]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.13.9-201404062127.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.13.9-201404062127.patch
CommitLineData
4cd7332d
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 b9e9bd8..bf49b92 100644
239--- a/Documentation/kernel-parameters.txt
240+++ b/Documentation/kernel-parameters.txt
241@@ -1033,6 +1033,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@@ -2018,6 +2022,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@@ -2285,6 +2293,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 652f972..20ef4fb 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 -fno-delete-null-pointer-checks
302
303 # Decide whether to build built-in, modular, or both.
304 # Normally, just do built-in.
305@@ -311,9 +312,15 @@ endif
306 # If the user is running make -s (silent mode), suppress echoing of
307 # commands
308
309+ifneq ($(filter 4.%,$(MAKE_VERSION)),) # make-4
310+ifneq ($(filter %s ,$(firstword x$(MAKEFLAGS))),)
311+ quiet=silent_
312+endif
313+else # make-3.8x
314 ifneq ($(filter s% -s%,$(MAKEFLAGS)),)
315 quiet=silent_
316 endif
317+endif
318
319 export quiet Q KBUILD_VERBOSE
320
321@@ -417,8 +424,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
322 # Rules shared between *config targets and build targets
323
324 # Basic helpers built in scripts/
325-PHONY += scripts_basic
326-scripts_basic:
327+PHONY += scripts_basic gcc-plugins
328+scripts_basic: gcc-plugins
329 $(Q)$(MAKE) $(build)=scripts/basic
330 $(Q)rm -f .tmp_quiet_recordmcount
331
332@@ -579,6 +586,72 @@ else
333 KBUILD_CFLAGS += -O2
334 endif
335
336+ifndef DISABLE_PAX_PLUGINS
337+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
338+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
339+else
340+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
341+endif
342+ifneq ($(PLUGINCC),)
343+ifdef CONFIG_PAX_CONSTIFY_PLUGIN
344+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
345+endif
346+ifdef CONFIG_PAX_MEMORY_STACKLEAK
347+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
348+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
349+endif
350+ifdef CONFIG_KALLOCSTAT_PLUGIN
351+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
352+endif
353+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
354+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
355+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
356+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
357+endif
358+ifdef CONFIG_GRKERNSEC_RANDSTRUCT
359+RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
360+ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
361+RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
362+endif
363+endif
364+ifdef CONFIG_CHECKER_PLUGIN
365+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
366+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
367+endif
368+endif
369+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
370+ifdef CONFIG_PAX_SIZE_OVERFLOW
371+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
372+endif
373+ifdef CONFIG_PAX_LATENT_ENTROPY
374+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
375+endif
376+ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
377+STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
378+endif
379+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
380+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
381+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
382+GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
383+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
384+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
385+ifeq ($(KBUILD_EXTMOD),)
386+gcc-plugins:
387+ $(Q)$(MAKE) $(build)=tools/gcc
388+else
389+gcc-plugins: ;
390+endif
391+else
392+gcc-plugins:
393+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
394+ $(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.))
395+else
396+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
397+endif
398+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
399+endif
400+endif
401+
402 include $(srctree)/arch/$(SRCARCH)/Makefile
403
404 ifdef CONFIG_READABLE_ASM
405@@ -619,7 +692,7 @@ endif
406
407 ifdef CONFIG_DEBUG_INFO
408 KBUILD_CFLAGS += -g
409-KBUILD_AFLAGS += -gdwarf-2
410+KBUILD_AFLAGS += -Wa,--gdwarf-2
411 endif
412
413 ifdef CONFIG_DEBUG_INFO_REDUCED
414@@ -754,7 +827,7 @@ export mod_sign_cmd
415
416
417 ifeq ($(KBUILD_EXTMOD),)
418-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
419+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
420
421 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
422 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
423@@ -803,6 +876,8 @@ endif
424
425 # The actual objects are generated when descending,
426 # make sure no implicit rule kicks in
427+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
428+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
429 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
430
431 # Handle descending into subdirectories listed in $(vmlinux-dirs)
432@@ -812,7 +887,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
433 # Error messages still appears in the original language
434
435 PHONY += $(vmlinux-dirs)
436-$(vmlinux-dirs): prepare scripts
437+$(vmlinux-dirs): gcc-plugins prepare scripts
438 $(Q)$(MAKE) $(build)=$@
439
440 define filechk_kernel.release
441@@ -855,10 +930,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
442
443 archprepare: archheaders archscripts prepare1 scripts_basic
444
445+prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
446+prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
447 prepare0: archprepare FORCE
448 $(Q)$(MAKE) $(build)=.
449
450 # All the preparing..
451+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
452 prepare: prepare0
453
454 # Generate some files
455@@ -966,6 +1044,8 @@ all: modules
456 # using awk while concatenating to the final file.
457
458 PHONY += modules
459+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
460+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
461 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
462 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
463 @$(kecho) ' Building modules, stage 2.';
464@@ -981,7 +1061,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
465
466 # Target to prepare building external modules
467 PHONY += modules_prepare
468-modules_prepare: prepare scripts
469+modules_prepare: gcc-plugins prepare scripts
470
471 # Target to install modules
472 PHONY += modules_install
473@@ -1047,7 +1127,8 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
474 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
475 signing_key.priv signing_key.x509 x509.genkey \
476 extra_certificates signing_key.x509.keyid \
477- signing_key.x509.signer
478+ signing_key.x509.signer tools/gcc/size_overflow_hash.h \
479+ tools/gcc/randomize_layout_seed.h
480
481 # clean - Delete most, but leave enough to build external modules
482 #
483@@ -1087,6 +1168,7 @@ distclean: mrproper
484 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
485 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
486 -o -name '.*.rej' \
487+ -o -name '.*.rej' -o -name '*.so' \
488 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
489 -type f -print | xargs rm -f
490
491@@ -1248,6 +1330,8 @@ PHONY += $(module-dirs) modules
492 $(module-dirs): crmodverdir $(objtree)/Module.symvers
493 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
494
495+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
496+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
497 modules: $(module-dirs)
498 @$(kecho) ' Building modules, stage 2.';
499 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
500@@ -1387,17 +1471,21 @@ else
501 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
502 endif
503
504-%.s: %.c prepare scripts FORCE
505+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
506+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
507+%.s: %.c gcc-plugins prepare scripts FORCE
508 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
509 %.i: %.c prepare scripts FORCE
510 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
511-%.o: %.c prepare scripts FORCE
512+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
513+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
514+%.o: %.c gcc-plugins prepare scripts FORCE
515 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
516 %.lst: %.c prepare scripts FORCE
517 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
518-%.s: %.S prepare scripts FORCE
519+%.s: %.S gcc-plugins prepare scripts FORCE
520 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
521-%.o: %.S prepare scripts FORCE
522+%.o: %.S gcc-plugins prepare scripts FORCE
523 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
524 %.symtypes: %.c prepare scripts FORCE
525 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
526@@ -1407,11 +1495,15 @@ endif
527 $(cmd_crmodverdir)
528 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
529 $(build)=$(build-dir)
530-%/: prepare scripts FORCE
531+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
532+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
533+%/: gcc-plugins prepare scripts FORCE
534 $(cmd_crmodverdir)
535 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
536 $(build)=$(build-dir)
537-%.ko: prepare scripts FORCE
538+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
539+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
540+%.ko: gcc-plugins prepare scripts FORCE
541 $(cmd_crmodverdir)
542 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
543 $(build)=$(build-dir) $(@:.ko=.o)
544diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
545index 78b03ef..da28a51 100644
546--- a/arch/alpha/include/asm/atomic.h
547+++ b/arch/alpha/include/asm/atomic.h
548@@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
549 #define atomic_dec(v) atomic_sub(1,(v))
550 #define atomic64_dec(v) atomic64_sub(1,(v))
551
552+#define atomic64_read_unchecked(v) atomic64_read(v)
553+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
554+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
555+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
556+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
557+#define atomic64_inc_unchecked(v) atomic64_inc(v)
558+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
559+#define atomic64_dec_unchecked(v) atomic64_dec(v)
560+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
561+
562 #define smp_mb__before_atomic_dec() smp_mb()
563 #define smp_mb__after_atomic_dec() smp_mb()
564 #define smp_mb__before_atomic_inc() smp_mb()
565diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
566index ad368a9..fbe0f25 100644
567--- a/arch/alpha/include/asm/cache.h
568+++ b/arch/alpha/include/asm/cache.h
569@@ -4,19 +4,19 @@
570 #ifndef __ARCH_ALPHA_CACHE_H
571 #define __ARCH_ALPHA_CACHE_H
572
573+#include <linux/const.h>
574
575 /* Bytes per L1 (data) cache line. */
576 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
577-# define L1_CACHE_BYTES 64
578 # define L1_CACHE_SHIFT 6
579 #else
580 /* Both EV4 and EV5 are write-through, read-allocate,
581 direct-mapped, physical.
582 */
583-# define L1_CACHE_BYTES 32
584 # define L1_CACHE_SHIFT 5
585 #endif
586
587+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
588 #define SMP_CACHE_BYTES L1_CACHE_BYTES
589
590 #endif
591diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
592index 968d999..d36b2df 100644
593--- a/arch/alpha/include/asm/elf.h
594+++ b/arch/alpha/include/asm/elf.h
595@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
596
597 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
598
599+#ifdef CONFIG_PAX_ASLR
600+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
601+
602+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
603+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
604+#endif
605+
606 /* $0 is set by ld.so to a pointer to a function which might be
607 registered using atexit. This provides a mean for the dynamic
608 linker to call DT_FINI functions for shared libraries that have
609diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
610index aab14a0..b4fa3e7 100644
611--- a/arch/alpha/include/asm/pgalloc.h
612+++ b/arch/alpha/include/asm/pgalloc.h
613@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
614 pgd_set(pgd, pmd);
615 }
616
617+static inline void
618+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
619+{
620+ pgd_populate(mm, pgd, pmd);
621+}
622+
623 extern pgd_t *pgd_alloc(struct mm_struct *mm);
624
625 static inline void
626diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
627index d8f9b7e..f6222fa 100644
628--- a/arch/alpha/include/asm/pgtable.h
629+++ b/arch/alpha/include/asm/pgtable.h
630@@ -102,6 +102,17 @@ struct vm_area_struct;
631 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
632 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
633 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
634+
635+#ifdef CONFIG_PAX_PAGEEXEC
636+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
637+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
638+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
639+#else
640+# define PAGE_SHARED_NOEXEC PAGE_SHARED
641+# define PAGE_COPY_NOEXEC PAGE_COPY
642+# define PAGE_READONLY_NOEXEC PAGE_READONLY
643+#endif
644+
645 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
646
647 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
648diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
649index 2fd00b7..cfd5069 100644
650--- a/arch/alpha/kernel/module.c
651+++ b/arch/alpha/kernel/module.c
652@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
653
654 /* The small sections were sorted to the end of the segment.
655 The following should definitely cover them. */
656- gp = (u64)me->module_core + me->core_size - 0x8000;
657+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
658 got = sechdrs[me->arch.gotsecindex].sh_addr;
659
660 for (i = 0; i < n; i++) {
661diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
662index 1402fcc..0b1abd2 100644
663--- a/arch/alpha/kernel/osf_sys.c
664+++ b/arch/alpha/kernel/osf_sys.c
665@@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
666 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
667
668 static unsigned long
669-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
670- unsigned long limit)
671+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
672+ unsigned long limit, unsigned long flags)
673 {
674 struct vm_unmapped_area_info info;
675+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
676
677 info.flags = 0;
678 info.length = len;
679@@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
680 info.high_limit = limit;
681 info.align_mask = 0;
682 info.align_offset = 0;
683+ info.threadstack_offset = offset;
684 return vm_unmapped_area(&info);
685 }
686
687@@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
688 merely specific addresses, but regions of memory -- perhaps
689 this feature should be incorporated into all ports? */
690
691+#ifdef CONFIG_PAX_RANDMMAP
692+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
693+#endif
694+
695 if (addr) {
696- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
697+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
698 if (addr != (unsigned long) -ENOMEM)
699 return addr;
700 }
701
702 /* Next, try allocating at TASK_UNMAPPED_BASE. */
703- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
704- len, limit);
705+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
706+
707 if (addr != (unsigned long) -ENOMEM)
708 return addr;
709
710 /* Finally, try allocating in low memory. */
711- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
712+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
713
714 return addr;
715 }
716diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
717index 98838a0..b304fb4 100644
718--- a/arch/alpha/mm/fault.c
719+++ b/arch/alpha/mm/fault.c
720@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
721 __reload_thread(pcb);
722 }
723
724+#ifdef CONFIG_PAX_PAGEEXEC
725+/*
726+ * PaX: decide what to do with offenders (regs->pc = fault address)
727+ *
728+ * returns 1 when task should be killed
729+ * 2 when patched PLT trampoline was detected
730+ * 3 when unpatched PLT trampoline was detected
731+ */
732+static int pax_handle_fetch_fault(struct pt_regs *regs)
733+{
734+
735+#ifdef CONFIG_PAX_EMUPLT
736+ int err;
737+
738+ do { /* PaX: patched PLT emulation #1 */
739+ unsigned int ldah, ldq, jmp;
740+
741+ err = get_user(ldah, (unsigned int *)regs->pc);
742+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
743+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
744+
745+ if (err)
746+ break;
747+
748+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
749+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
750+ jmp == 0x6BFB0000U)
751+ {
752+ unsigned long r27, addr;
753+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
754+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
755+
756+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
757+ err = get_user(r27, (unsigned long *)addr);
758+ if (err)
759+ break;
760+
761+ regs->r27 = r27;
762+ regs->pc = r27;
763+ return 2;
764+ }
765+ } while (0);
766+
767+ do { /* PaX: patched PLT emulation #2 */
768+ unsigned int ldah, lda, br;
769+
770+ err = get_user(ldah, (unsigned int *)regs->pc);
771+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
772+ err |= get_user(br, (unsigned int *)(regs->pc+8));
773+
774+ if (err)
775+ break;
776+
777+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
778+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
779+ (br & 0xFFE00000U) == 0xC3E00000U)
780+ {
781+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
782+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
783+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
784+
785+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
786+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
787+ return 2;
788+ }
789+ } while (0);
790+
791+ do { /* PaX: unpatched PLT emulation */
792+ unsigned int br;
793+
794+ err = get_user(br, (unsigned int *)regs->pc);
795+
796+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
797+ unsigned int br2, ldq, nop, jmp;
798+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
799+
800+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
801+ err = get_user(br2, (unsigned int *)addr);
802+ err |= get_user(ldq, (unsigned int *)(addr+4));
803+ err |= get_user(nop, (unsigned int *)(addr+8));
804+ err |= get_user(jmp, (unsigned int *)(addr+12));
805+ err |= get_user(resolver, (unsigned long *)(addr+16));
806+
807+ if (err)
808+ break;
809+
810+ if (br2 == 0xC3600000U &&
811+ ldq == 0xA77B000CU &&
812+ nop == 0x47FF041FU &&
813+ jmp == 0x6B7B0000U)
814+ {
815+ regs->r28 = regs->pc+4;
816+ regs->r27 = addr+16;
817+ regs->pc = resolver;
818+ return 3;
819+ }
820+ }
821+ } while (0);
822+#endif
823+
824+ return 1;
825+}
826+
827+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
828+{
829+ unsigned long i;
830+
831+ printk(KERN_ERR "PAX: bytes at PC: ");
832+ for (i = 0; i < 5; i++) {
833+ unsigned int c;
834+ if (get_user(c, (unsigned int *)pc+i))
835+ printk(KERN_CONT "???????? ");
836+ else
837+ printk(KERN_CONT "%08x ", c);
838+ }
839+ printk("\n");
840+}
841+#endif
842
843 /*
844 * This routine handles page faults. It determines the address,
845@@ -133,8 +251,29 @@ retry:
846 good_area:
847 si_code = SEGV_ACCERR;
848 if (cause < 0) {
849- if (!(vma->vm_flags & VM_EXEC))
850+ if (!(vma->vm_flags & VM_EXEC)) {
851+
852+#ifdef CONFIG_PAX_PAGEEXEC
853+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
854+ goto bad_area;
855+
856+ up_read(&mm->mmap_sem);
857+ switch (pax_handle_fetch_fault(regs)) {
858+
859+#ifdef CONFIG_PAX_EMUPLT
860+ case 2:
861+ case 3:
862+ return;
863+#endif
864+
865+ }
866+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
867+ do_group_exit(SIGKILL);
868+#else
869 goto bad_area;
870+#endif
871+
872+ }
873 } else if (!cause) {
874 /* Allow reads even for write-only mappings */
875 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
876diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
877index 47085a0..f975a53 100644
878--- a/arch/arm/Kconfig
879+++ b/arch/arm/Kconfig
880@@ -1830,7 +1830,7 @@ config ALIGNMENT_TRAP
881
882 config UACCESS_WITH_MEMCPY
883 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
884- depends on MMU
885+ depends on MMU && !PAX_MEMORY_UDEREF
886 default y if CPU_FEROCEON
887 help
888 Implement faster copy_to_user and clear_user methods for CPU
889@@ -2102,6 +2102,7 @@ config XIP_PHYS_ADDR
890 config KEXEC
891 bool "Kexec system call (EXPERIMENTAL)"
892 depends on (!SMP || PM_SLEEP_SMP)
893+ depends on !GRKERNSEC_KMEM
894 help
895 kexec is a system call that implements the ability to shutdown your
896 current kernel, and to start another kernel. It is like a reboot
897diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
898index 62d2cb5..09d45e3 100644
899--- a/arch/arm/include/asm/atomic.h
900+++ b/arch/arm/include/asm/atomic.h
901@@ -18,17 +18,35 @@
902 #include <asm/barrier.h>
903 #include <asm/cmpxchg.h>
904
905+#ifdef CONFIG_GENERIC_ATOMIC64
906+#include <asm-generic/atomic64.h>
907+#endif
908+
909 #define ATOMIC_INIT(i) { (i) }
910
911 #ifdef __KERNEL__
912
913+#define _ASM_EXTABLE(from, to) \
914+" .pushsection __ex_table,\"a\"\n"\
915+" .align 3\n" \
916+" .long " #from ", " #to"\n" \
917+" .popsection"
918+
919 /*
920 * On ARM, ordinary assignment (str instruction) doesn't clear the local
921 * strex/ldrex monitor on some implementations. The reason we can use it for
922 * atomic_set() is the clrex or dummy strex done on every exception return.
923 */
924 #define atomic_read(v) (*(volatile int *)&(v)->counter)
925+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
926+{
927+ return v->counter;
928+}
929 #define atomic_set(v,i) (((v)->counter) = (i))
930+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
931+{
932+ v->counter = i;
933+}
934
935 #if __LINUX_ARM_ARCH__ >= 6
936
937@@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
938
939 prefetchw(&v->counter);
940 __asm__ __volatile__("@ atomic_add\n"
941+"1: ldrex %1, [%3]\n"
942+" adds %0, %1, %4\n"
943+
944+#ifdef CONFIG_PAX_REFCOUNT
945+" bvc 3f\n"
946+"2: bkpt 0xf103\n"
947+"3:\n"
948+#endif
949+
950+" strex %1, %0, [%3]\n"
951+" teq %1, #0\n"
952+" bne 1b"
953+
954+#ifdef CONFIG_PAX_REFCOUNT
955+"\n4:\n"
956+ _ASM_EXTABLE(2b, 4b)
957+#endif
958+
959+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
960+ : "r" (&v->counter), "Ir" (i)
961+ : "cc");
962+}
963+
964+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
965+{
966+ unsigned long tmp;
967+ int result;
968+
969+ prefetchw(&v->counter);
970+ __asm__ __volatile__("@ atomic_add_unchecked\n"
971 "1: ldrex %0, [%3]\n"
972 " add %0, %0, %4\n"
973 " strex %1, %0, [%3]\n"
974@@ -62,6 +110,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
975 smp_mb();
976
977 __asm__ __volatile__("@ atomic_add_return\n"
978+"1: ldrex %1, [%3]\n"
979+" adds %0, %1, %4\n"
980+
981+#ifdef CONFIG_PAX_REFCOUNT
982+" bvc 3f\n"
983+" mov %0, %1\n"
984+"2: bkpt 0xf103\n"
985+"3:\n"
986+#endif
987+
988+" strex %1, %0, [%3]\n"
989+" teq %1, #0\n"
990+" bne 1b"
991+
992+#ifdef CONFIG_PAX_REFCOUNT
993+"\n4:\n"
994+ _ASM_EXTABLE(2b, 4b)
995+#endif
996+
997+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
998+ : "r" (&v->counter), "Ir" (i)
999+ : "cc");
1000+
1001+ smp_mb();
1002+
1003+ return result;
1004+}
1005+
1006+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1007+{
1008+ unsigned long tmp;
1009+ int result;
1010+
1011+ smp_mb();
1012+
1013+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
1014 "1: ldrex %0, [%3]\n"
1015 " add %0, %0, %4\n"
1016 " strex %1, %0, [%3]\n"
1017@@ -83,6 +167,36 @@ static inline void atomic_sub(int i, atomic_t *v)
1018
1019 prefetchw(&v->counter);
1020 __asm__ __volatile__("@ atomic_sub\n"
1021+"1: ldrex %1, [%3]\n"
1022+" subs %0, %1, %4\n"
1023+
1024+#ifdef CONFIG_PAX_REFCOUNT
1025+" bvc 3f\n"
1026+"2: bkpt 0xf103\n"
1027+"3:\n"
1028+#endif
1029+
1030+" strex %1, %0, [%3]\n"
1031+" teq %1, #0\n"
1032+" bne 1b"
1033+
1034+#ifdef CONFIG_PAX_REFCOUNT
1035+"\n4:\n"
1036+ _ASM_EXTABLE(2b, 4b)
1037+#endif
1038+
1039+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1040+ : "r" (&v->counter), "Ir" (i)
1041+ : "cc");
1042+}
1043+
1044+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1045+{
1046+ unsigned long tmp;
1047+ int result;
1048+
1049+ prefetchw(&v->counter);
1050+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
1051 "1: ldrex %0, [%3]\n"
1052 " sub %0, %0, %4\n"
1053 " strex %1, %0, [%3]\n"
1054@@ -101,11 +215,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1055 smp_mb();
1056
1057 __asm__ __volatile__("@ atomic_sub_return\n"
1058-"1: ldrex %0, [%3]\n"
1059-" sub %0, %0, %4\n"
1060+"1: ldrex %1, [%3]\n"
1061+" subs %0, %1, %4\n"
1062+
1063+#ifdef CONFIG_PAX_REFCOUNT
1064+" bvc 3f\n"
1065+" mov %0, %1\n"
1066+"2: bkpt 0xf103\n"
1067+"3:\n"
1068+#endif
1069+
1070 " strex %1, %0, [%3]\n"
1071 " teq %1, #0\n"
1072 " bne 1b"
1073+
1074+#ifdef CONFIG_PAX_REFCOUNT
1075+"\n4:\n"
1076+ _ASM_EXTABLE(2b, 4b)
1077+#endif
1078+
1079 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1080 : "r" (&v->counter), "Ir" (i)
1081 : "cc");
1082@@ -138,6 +266,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1083 return oldval;
1084 }
1085
1086+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1087+{
1088+ unsigned long oldval, res;
1089+
1090+ smp_mb();
1091+
1092+ do {
1093+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1094+ "ldrex %1, [%3]\n"
1095+ "mov %0, #0\n"
1096+ "teq %1, %4\n"
1097+ "strexeq %0, %5, [%3]\n"
1098+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1099+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1100+ : "cc");
1101+ } while (res);
1102+
1103+ smp_mb();
1104+
1105+ return oldval;
1106+}
1107+
1108 #else /* ARM_ARCH_6 */
1109
1110 #ifdef CONFIG_SMP
1111@@ -156,7 +306,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1112
1113 return val;
1114 }
1115+
1116+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1117+{
1118+ return atomic_add_return(i, v);
1119+}
1120+
1121 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1122+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1123+{
1124+ (void) atomic_add_return(i, v);
1125+}
1126
1127 static inline int atomic_sub_return(int i, atomic_t *v)
1128 {
1129@@ -171,6 +331,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1130 return val;
1131 }
1132 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1133+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1134+{
1135+ (void) atomic_sub_return(i, v);
1136+}
1137
1138 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1139 {
1140@@ -186,9 +350,18 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1141 return ret;
1142 }
1143
1144+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1145+{
1146+ return atomic_cmpxchg(v, old, new);
1147+}
1148+
1149 #endif /* __LINUX_ARM_ARCH__ */
1150
1151 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1152+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1153+{
1154+ return xchg(&v->counter, new);
1155+}
1156
1157 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1158 {
1159@@ -201,11 +374,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1160 }
1161
1162 #define atomic_inc(v) atomic_add(1, v)
1163+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1164+{
1165+ atomic_add_unchecked(1, v);
1166+}
1167 #define atomic_dec(v) atomic_sub(1, v)
1168+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1169+{
1170+ atomic_sub_unchecked(1, v);
1171+}
1172
1173 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1174+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1175+{
1176+ return atomic_add_return_unchecked(1, v) == 0;
1177+}
1178 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1179 #define atomic_inc_return(v) (atomic_add_return(1, v))
1180+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1181+{
1182+ return atomic_add_return_unchecked(1, v);
1183+}
1184 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1185 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1186
1187@@ -221,6 +410,14 @@ typedef struct {
1188 long long counter;
1189 } atomic64_t;
1190
1191+#ifdef CONFIG_PAX_REFCOUNT
1192+typedef struct {
1193+ long long counter;
1194+} atomic64_unchecked_t;
1195+#else
1196+typedef atomic64_t atomic64_unchecked_t;
1197+#endif
1198+
1199 #define ATOMIC64_INIT(i) { (i) }
1200
1201 #ifdef CONFIG_ARM_LPAE
1202@@ -237,6 +434,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1203 return result;
1204 }
1205
1206+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1207+{
1208+ long long result;
1209+
1210+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1211+" ldrd %0, %H0, [%1]"
1212+ : "=&r" (result)
1213+ : "r" (&v->counter), "Qo" (v->counter)
1214+ );
1215+
1216+ return result;
1217+}
1218+
1219 static inline void atomic64_set(atomic64_t *v, long long i)
1220 {
1221 __asm__ __volatile__("@ atomic64_set\n"
1222@@ -245,6 +455,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1223 : "r" (&v->counter), "r" (i)
1224 );
1225 }
1226+
1227+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1228+{
1229+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1230+" strd %2, %H2, [%1]"
1231+ : "=Qo" (v->counter)
1232+ : "r" (&v->counter), "r" (i)
1233+ );
1234+}
1235 #else
1236 static inline long long atomic64_read(const atomic64_t *v)
1237 {
1238@@ -259,6 +478,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1239 return result;
1240 }
1241
1242+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1243+{
1244+ long long result;
1245+
1246+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1247+" ldrexd %0, %H0, [%1]"
1248+ : "=&r" (result)
1249+ : "r" (&v->counter), "Qo" (v->counter)
1250+ );
1251+
1252+ return result;
1253+}
1254+
1255 static inline void atomic64_set(atomic64_t *v, long long i)
1256 {
1257 long long tmp;
1258@@ -273,6 +505,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1259 : "r" (&v->counter), "r" (i)
1260 : "cc");
1261 }
1262+
1263+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1264+{
1265+ long long tmp;
1266+
1267+ prefetchw(&v->counter);
1268+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1269+"1: ldrexd %0, %H0, [%2]\n"
1270+" strexd %0, %3, %H3, [%2]\n"
1271+" teq %0, #0\n"
1272+" bne 1b"
1273+ : "=&r" (tmp), "=Qo" (v->counter)
1274+ : "r" (&v->counter), "r" (i)
1275+ : "cc");
1276+}
1277 #endif
1278
1279 static inline void atomic64_add(long long i, atomic64_t *v)
1280@@ -284,6 +531,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1281 __asm__ __volatile__("@ atomic64_add\n"
1282 "1: ldrexd %0, %H0, [%3]\n"
1283 " adds %Q0, %Q0, %Q4\n"
1284+" adcs %R0, %R0, %R4\n"
1285+
1286+#ifdef CONFIG_PAX_REFCOUNT
1287+" bvc 3f\n"
1288+"2: bkpt 0xf103\n"
1289+"3:\n"
1290+#endif
1291+
1292+" strexd %1, %0, %H0, [%3]\n"
1293+" teq %1, #0\n"
1294+" bne 1b"
1295+
1296+#ifdef CONFIG_PAX_REFCOUNT
1297+"\n4:\n"
1298+ _ASM_EXTABLE(2b, 4b)
1299+#endif
1300+
1301+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1302+ : "r" (&v->counter), "r" (i)
1303+ : "cc");
1304+}
1305+
1306+static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1307+{
1308+ long long result;
1309+ unsigned long tmp;
1310+
1311+ prefetchw(&v->counter);
1312+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1313+"1: ldrexd %0, %H0, [%3]\n"
1314+" adds %Q0, %Q0, %Q4\n"
1315 " adc %R0, %R0, %R4\n"
1316 " strexd %1, %0, %H0, [%3]\n"
1317 " teq %1, #0\n"
1318@@ -303,6 +581,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1319 __asm__ __volatile__("@ atomic64_add_return\n"
1320 "1: ldrexd %0, %H0, [%3]\n"
1321 " adds %Q0, %Q0, %Q4\n"
1322+" adcs %R0, %R0, %R4\n"
1323+
1324+#ifdef CONFIG_PAX_REFCOUNT
1325+" bvc 3f\n"
1326+" mov %0, %1\n"
1327+" mov %H0, %H1\n"
1328+"2: bkpt 0xf103\n"
1329+"3:\n"
1330+#endif
1331+
1332+" strexd %1, %0, %H0, [%3]\n"
1333+" teq %1, #0\n"
1334+" bne 1b"
1335+
1336+#ifdef CONFIG_PAX_REFCOUNT
1337+"\n4:\n"
1338+ _ASM_EXTABLE(2b, 4b)
1339+#endif
1340+
1341+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1342+ : "r" (&v->counter), "r" (i)
1343+ : "cc");
1344+
1345+ smp_mb();
1346+
1347+ return result;
1348+}
1349+
1350+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1351+{
1352+ long long result;
1353+ unsigned long tmp;
1354+
1355+ smp_mb();
1356+
1357+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1358+"1: ldrexd %0, %H0, [%3]\n"
1359+" adds %Q0, %Q0, %Q4\n"
1360 " adc %R0, %R0, %R4\n"
1361 " strexd %1, %0, %H0, [%3]\n"
1362 " teq %1, #0\n"
1363@@ -325,6 +641,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1364 __asm__ __volatile__("@ atomic64_sub\n"
1365 "1: ldrexd %0, %H0, [%3]\n"
1366 " subs %Q0, %Q0, %Q4\n"
1367+" sbcs %R0, %R0, %R4\n"
1368+
1369+#ifdef CONFIG_PAX_REFCOUNT
1370+" bvc 3f\n"
1371+"2: bkpt 0xf103\n"
1372+"3:\n"
1373+#endif
1374+
1375+" strexd %1, %0, %H0, [%3]\n"
1376+" teq %1, #0\n"
1377+" bne 1b"
1378+
1379+#ifdef CONFIG_PAX_REFCOUNT
1380+"\n4:\n"
1381+ _ASM_EXTABLE(2b, 4b)
1382+#endif
1383+
1384+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1385+ : "r" (&v->counter), "r" (i)
1386+ : "cc");
1387+}
1388+
1389+static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1390+{
1391+ long long result;
1392+ unsigned long tmp;
1393+
1394+ prefetchw(&v->counter);
1395+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1396+"1: ldrexd %0, %H0, [%3]\n"
1397+" subs %Q0, %Q0, %Q4\n"
1398 " sbc %R0, %R0, %R4\n"
1399 " strexd %1, %0, %H0, [%3]\n"
1400 " teq %1, #0\n"
1401@@ -344,16 +691,29 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1402 __asm__ __volatile__("@ atomic64_sub_return\n"
1403 "1: ldrexd %0, %H0, [%3]\n"
1404 " subs %Q0, %Q0, %Q4\n"
1405-" sbc %R0, %R0, %R4\n"
1406+" sbcs %R0, %R0, %R4\n"
1407+
1408+#ifdef CONFIG_PAX_REFCOUNT
1409+" bvc 3f\n"
1410+" mov %0, %1\n"
1411+" mov %H0, %H1\n"
1412+"2: bkpt 0xf103\n"
1413+"3:\n"
1414+#endif
1415+
1416 " strexd %1, %0, %H0, [%3]\n"
1417 " teq %1, #0\n"
1418 " bne 1b"
1419+
1420+#ifdef CONFIG_PAX_REFCOUNT
1421+"\n4:\n"
1422+ _ASM_EXTABLE(2b, 4b)
1423+#endif
1424+
1425 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1426 : "r" (&v->counter), "r" (i)
1427 : "cc");
1428
1429- smp_mb();
1430-
1431 return result;
1432 }
1433
1434@@ -382,6 +742,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1435 return oldval;
1436 }
1437
1438+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1439+ long long new)
1440+{
1441+ long long oldval;
1442+ unsigned long res;
1443+
1444+ smp_mb();
1445+
1446+ do {
1447+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1448+ "ldrexd %1, %H1, [%3]\n"
1449+ "mov %0, #0\n"
1450+ "teq %1, %4\n"
1451+ "teqeq %H1, %H4\n"
1452+ "strexdeq %0, %5, %H5, [%3]"
1453+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1454+ : "r" (&ptr->counter), "r" (old), "r" (new)
1455+ : "cc");
1456+ } while (res);
1457+
1458+ smp_mb();
1459+
1460+ return oldval;
1461+}
1462+
1463 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1464 {
1465 long long result;
1466@@ -406,20 +791,34 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1467 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1468 {
1469 long long result;
1470- unsigned long tmp;
1471+ u64 tmp;
1472
1473 smp_mb();
1474
1475 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1476-"1: ldrexd %0, %H0, [%3]\n"
1477-" subs %Q0, %Q0, #1\n"
1478-" sbc %R0, %R0, #0\n"
1479+"1: ldrexd %1, %H1, [%3]\n"
1480+" subs %Q0, %Q1, #1\n"
1481+" sbcs %R0, %R1, #0\n"
1482+
1483+#ifdef CONFIG_PAX_REFCOUNT
1484+" bvc 3f\n"
1485+" mov %Q0, %Q1\n"
1486+" mov %R0, %R1\n"
1487+"2: bkpt 0xf103\n"
1488+"3:\n"
1489+#endif
1490+
1491 " teq %R0, #0\n"
1492-" bmi 2f\n"
1493+" bmi 4f\n"
1494 " strexd %1, %0, %H0, [%3]\n"
1495 " teq %1, #0\n"
1496 " bne 1b\n"
1497-"2:"
1498+"4:\n"
1499+
1500+#ifdef CONFIG_PAX_REFCOUNT
1501+ _ASM_EXTABLE(2b, 4b)
1502+#endif
1503+
1504 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1505 : "r" (&v->counter)
1506 : "cc");
1507@@ -442,13 +841,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1508 " teq %0, %5\n"
1509 " teqeq %H0, %H5\n"
1510 " moveq %1, #0\n"
1511-" beq 2f\n"
1512+" beq 4f\n"
1513 " adds %Q0, %Q0, %Q6\n"
1514-" adc %R0, %R0, %R6\n"
1515+" adcs %R0, %R0, %R6\n"
1516+
1517+#ifdef CONFIG_PAX_REFCOUNT
1518+" bvc 3f\n"
1519+"2: bkpt 0xf103\n"
1520+"3:\n"
1521+#endif
1522+
1523 " strexd %2, %0, %H0, [%4]\n"
1524 " teq %2, #0\n"
1525 " bne 1b\n"
1526-"2:"
1527+"4:\n"
1528+
1529+#ifdef CONFIG_PAX_REFCOUNT
1530+ _ASM_EXTABLE(2b, 4b)
1531+#endif
1532+
1533 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1534 : "r" (&v->counter), "r" (u), "r" (a)
1535 : "cc");
1536@@ -461,10 +872,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1537
1538 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1539 #define atomic64_inc(v) atomic64_add(1LL, (v))
1540+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1541 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1542+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1543 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1544 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1545 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1546+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1547 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1548 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1549 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1550diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1551index 75fe66b..ba3dee4 100644
1552--- a/arch/arm/include/asm/cache.h
1553+++ b/arch/arm/include/asm/cache.h
1554@@ -4,8 +4,10 @@
1555 #ifndef __ASMARM_CACHE_H
1556 #define __ASMARM_CACHE_H
1557
1558+#include <linux/const.h>
1559+
1560 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1561-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1562+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1563
1564 /*
1565 * Memory returned by kmalloc() may be used for DMA, so we must make
1566@@ -24,5 +26,6 @@
1567 #endif
1568
1569 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1570+#define __read_only __attribute__ ((__section__(".data..read_only")))
1571
1572 #endif
1573diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1574index ab91ebb..2c2afeb 100644
1575--- a/arch/arm/include/asm/cacheflush.h
1576+++ b/arch/arm/include/asm/cacheflush.h
1577@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1578 void (*dma_unmap_area)(const void *, size_t, int);
1579
1580 void (*dma_flush_range)(const void *, const void *);
1581-};
1582+} __no_const;
1583
1584 /*
1585 * Select the calling method
1586diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1587index 6dcc164..b14d917 100644
1588--- a/arch/arm/include/asm/checksum.h
1589+++ b/arch/arm/include/asm/checksum.h
1590@@ -37,7 +37,19 @@ __wsum
1591 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1592
1593 __wsum
1594-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1595+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1596+
1597+static inline __wsum
1598+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1599+{
1600+ __wsum ret;
1601+ pax_open_userland();
1602+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1603+ pax_close_userland();
1604+ return ret;
1605+}
1606+
1607+
1608
1609 /*
1610 * Fold a partial checksum without adding pseudo headers
1611diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1612index df2fbba..63fe3e1 100644
1613--- a/arch/arm/include/asm/cmpxchg.h
1614+++ b/arch/arm/include/asm/cmpxchg.h
1615@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1616
1617 #define xchg(ptr,x) \
1618 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1619+#define xchg_unchecked(ptr,x) \
1620+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1621
1622 #include <asm-generic/cmpxchg-local.h>
1623
1624diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1625index 6ddbe44..b5e38b1 100644
1626--- a/arch/arm/include/asm/domain.h
1627+++ b/arch/arm/include/asm/domain.h
1628@@ -48,18 +48,37 @@
1629 * Domain types
1630 */
1631 #define DOMAIN_NOACCESS 0
1632-#define DOMAIN_CLIENT 1
1633 #ifdef CONFIG_CPU_USE_DOMAINS
1634+#define DOMAIN_USERCLIENT 1
1635+#define DOMAIN_KERNELCLIENT 1
1636 #define DOMAIN_MANAGER 3
1637+#define DOMAIN_VECTORS DOMAIN_USER
1638 #else
1639+
1640+#ifdef CONFIG_PAX_KERNEXEC
1641 #define DOMAIN_MANAGER 1
1642+#define DOMAIN_KERNEXEC 3
1643+#else
1644+#define DOMAIN_MANAGER 1
1645+#endif
1646+
1647+#ifdef CONFIG_PAX_MEMORY_UDEREF
1648+#define DOMAIN_USERCLIENT 0
1649+#define DOMAIN_UDEREF 1
1650+#define DOMAIN_VECTORS DOMAIN_KERNEL
1651+#else
1652+#define DOMAIN_USERCLIENT 1
1653+#define DOMAIN_VECTORS DOMAIN_USER
1654+#endif
1655+#define DOMAIN_KERNELCLIENT 1
1656+
1657 #endif
1658
1659 #define domain_val(dom,type) ((type) << (2*(dom)))
1660
1661 #ifndef __ASSEMBLY__
1662
1663-#ifdef CONFIG_CPU_USE_DOMAINS
1664+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1665 static inline void set_domain(unsigned val)
1666 {
1667 asm volatile(
1668@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1669 isb();
1670 }
1671
1672-#define modify_domain(dom,type) \
1673- do { \
1674- struct thread_info *thread = current_thread_info(); \
1675- unsigned int domain = thread->cpu_domain; \
1676- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1677- thread->cpu_domain = domain | domain_val(dom, type); \
1678- set_domain(thread->cpu_domain); \
1679- } while (0)
1680-
1681+extern void modify_domain(unsigned int dom, unsigned int type);
1682 #else
1683 static inline void set_domain(unsigned val) { }
1684 static inline void modify_domain(unsigned dom, unsigned type) { }
1685diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1686index f4b46d3..abc9b2b 100644
1687--- a/arch/arm/include/asm/elf.h
1688+++ b/arch/arm/include/asm/elf.h
1689@@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1690 the loader. We need to make sure that it is out of the way of the program
1691 that it will "exec", and that there is sufficient room for the brk. */
1692
1693-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1694+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1695+
1696+#ifdef CONFIG_PAX_ASLR
1697+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1698+
1699+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1700+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1701+#endif
1702
1703 /* When the program starts, a1 contains a pointer to a function to be
1704 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1705@@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1706 extern void elf_set_personality(const struct elf32_hdr *);
1707 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1708
1709-struct mm_struct;
1710-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1711-#define arch_randomize_brk arch_randomize_brk
1712-
1713 #ifdef CONFIG_MMU
1714 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1715 struct linux_binprm;
1716diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1717index de53547..52b9a28 100644
1718--- a/arch/arm/include/asm/fncpy.h
1719+++ b/arch/arm/include/asm/fncpy.h
1720@@ -81,7 +81,9 @@
1721 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1722 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1723 \
1724+ pax_open_kernel(); \
1725 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1726+ pax_close_kernel(); \
1727 flush_icache_range((unsigned long)(dest_buf), \
1728 (unsigned long)(dest_buf) + (size)); \
1729 \
1730diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1731index e42cf59..7b94b8f 100644
1732--- a/arch/arm/include/asm/futex.h
1733+++ b/arch/arm/include/asm/futex.h
1734@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1735 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1736 return -EFAULT;
1737
1738+ pax_open_userland();
1739+
1740 smp_mb();
1741 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1742 "1: ldrex %1, [%4]\n"
1743@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1744 : "cc", "memory");
1745 smp_mb();
1746
1747+ pax_close_userland();
1748+
1749 *uval = val;
1750 return ret;
1751 }
1752@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1753 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1754 return -EFAULT;
1755
1756+ pax_open_userland();
1757+
1758 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1759 "1: " TUSER(ldr) " %1, [%4]\n"
1760 " teq %1, %2\n"
1761@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1762 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1763 : "cc", "memory");
1764
1765+ pax_close_userland();
1766+
1767 *uval = val;
1768 return ret;
1769 }
1770@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1771 return -EFAULT;
1772
1773 pagefault_disable(); /* implies preempt_disable() */
1774+ pax_open_userland();
1775
1776 switch (op) {
1777 case FUTEX_OP_SET:
1778@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1779 ret = -ENOSYS;
1780 }
1781
1782+ pax_close_userland();
1783 pagefault_enable(); /* subsumes preempt_enable() */
1784
1785 if (!ret) {
1786diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1787index 83eb2f7..ed77159 100644
1788--- a/arch/arm/include/asm/kmap_types.h
1789+++ b/arch/arm/include/asm/kmap_types.h
1790@@ -4,6 +4,6 @@
1791 /*
1792 * This is the "bare minimum". AIO seems to require this.
1793 */
1794-#define KM_TYPE_NR 16
1795+#define KM_TYPE_NR 17
1796
1797 #endif
1798diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1799index 9e614a1..3302cca 100644
1800--- a/arch/arm/include/asm/mach/dma.h
1801+++ b/arch/arm/include/asm/mach/dma.h
1802@@ -22,7 +22,7 @@ struct dma_ops {
1803 int (*residue)(unsigned int, dma_t *); /* optional */
1804 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1805 const char *type;
1806-};
1807+} __do_const;
1808
1809 struct dma_struct {
1810 void *addr; /* single DMA address */
1811diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1812index 2fe141f..192dc01 100644
1813--- a/arch/arm/include/asm/mach/map.h
1814+++ b/arch/arm/include/asm/mach/map.h
1815@@ -27,13 +27,16 @@ struct map_desc {
1816 #define MT_MINICLEAN 6
1817 #define MT_LOW_VECTORS 7
1818 #define MT_HIGH_VECTORS 8
1819-#define MT_MEMORY 9
1820+#define MT_MEMORY_RWX 9
1821 #define MT_ROM 10
1822-#define MT_MEMORY_NONCACHED 11
1823+#define MT_MEMORY_NONCACHED_RX 11
1824 #define MT_MEMORY_DTCM 12
1825 #define MT_MEMORY_ITCM 13
1826 #define MT_MEMORY_SO 14
1827 #define MT_MEMORY_DMA_READY 15
1828+#define MT_MEMORY_RW 16
1829+#define MT_MEMORY_RX 17
1830+#define MT_MEMORY_NONCACHED_RW 18
1831
1832 #ifdef CONFIG_MMU
1833 extern void iotable_init(struct map_desc *, int);
1834diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1835index f94784f..9a09a4a 100644
1836--- a/arch/arm/include/asm/outercache.h
1837+++ b/arch/arm/include/asm/outercache.h
1838@@ -35,7 +35,7 @@ struct outer_cache_fns {
1839 #endif
1840 void (*set_debug)(unsigned long);
1841 void (*resume)(void);
1842-};
1843+} __no_const;
1844
1845 extern struct outer_cache_fns outer_cache;
1846
1847diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1848index 4355f0e..cd9168e 100644
1849--- a/arch/arm/include/asm/page.h
1850+++ b/arch/arm/include/asm/page.h
1851@@ -23,6 +23,7 @@
1852
1853 #else
1854
1855+#include <linux/compiler.h>
1856 #include <asm/glue.h>
1857
1858 /*
1859@@ -114,7 +115,7 @@ struct cpu_user_fns {
1860 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1861 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1862 unsigned long vaddr, struct vm_area_struct *vma);
1863-};
1864+} __no_const;
1865
1866 #ifdef MULTI_USER
1867 extern struct cpu_user_fns cpu_user;
1868diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1869index 78a7793..e3dc06c 100644
1870--- a/arch/arm/include/asm/pgalloc.h
1871+++ b/arch/arm/include/asm/pgalloc.h
1872@@ -17,6 +17,7 @@
1873 #include <asm/processor.h>
1874 #include <asm/cacheflush.h>
1875 #include <asm/tlbflush.h>
1876+#include <asm/system_info.h>
1877
1878 #define check_pgt_cache() do { } while (0)
1879
1880@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1881 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1882 }
1883
1884+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1885+{
1886+ pud_populate(mm, pud, pmd);
1887+}
1888+
1889 #else /* !CONFIG_ARM_LPAE */
1890
1891 /*
1892@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1893 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1894 #define pmd_free(mm, pmd) do { } while (0)
1895 #define pud_populate(mm,pmd,pte) BUG()
1896+#define pud_populate_kernel(mm,pmd,pte) BUG()
1897
1898 #endif /* CONFIG_ARM_LPAE */
1899
1900@@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1901 __free_page(pte);
1902 }
1903
1904+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1905+{
1906+#ifdef CONFIG_ARM_LPAE
1907+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1908+#else
1909+ if (addr & SECTION_SIZE)
1910+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1911+ else
1912+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1913+#endif
1914+ flush_pmd_entry(pmdp);
1915+}
1916+
1917 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1918 pmdval_t prot)
1919 {
1920@@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1921 static inline void
1922 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1923 {
1924- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1925+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1926 }
1927 #define pmd_pgtable(pmd) pmd_page(pmd)
1928
1929diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1930index 5cfba15..f415e1a 100644
1931--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1932+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1933@@ -20,12 +20,15 @@
1934 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1935 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1936 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1937+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1938 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1939 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1940 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1941+
1942 /*
1943 * - section
1944 */
1945+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1946 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1947 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1948 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1949@@ -37,6 +40,7 @@
1950 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1951 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1952 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1953+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1954
1955 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1956 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1957@@ -66,6 +70,7 @@
1958 * - extended small page/tiny page
1959 */
1960 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1961+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1962 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1963 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1964 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1965diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1966index 86a659a..70e0120 100644
1967--- a/arch/arm/include/asm/pgtable-2level.h
1968+++ b/arch/arm/include/asm/pgtable-2level.h
1969@@ -126,6 +126,9 @@
1970 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1971 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1972
1973+/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1974+#define L_PTE_PXN (_AT(pteval_t, 0))
1975+
1976 /*
1977 * These are the memory types, defined to be compatible with
1978 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1979diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1980index 626989f..9d67a33 100644
1981--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1982+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1983@@ -75,6 +75,7 @@
1984 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1985 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1986 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1987+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1988 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1989
1990 /*
1991diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1992index 1d15673..04d626a 100644
1993--- a/arch/arm/include/asm/pgtable-3level.h
1994+++ b/arch/arm/include/asm/pgtable-3level.h
1995@@ -82,6 +82,7 @@
1996 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1997 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1998 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1999+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2000 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
2001 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
2002 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
2003@@ -95,6 +96,7 @@
2004 /*
2005 * To be used in assembly code with the upper page attributes.
2006 */
2007+#define L_PTE_PXN_HIGH (1 << (53 - 32))
2008 #define L_PTE_XN_HIGH (1 << (54 - 32))
2009 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2010
2011diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2012index 1571d12..b8a9b43 100644
2013--- a/arch/arm/include/asm/pgtable.h
2014+++ b/arch/arm/include/asm/pgtable.h
2015@@ -33,6 +33,9 @@
2016 #include <asm/pgtable-2level.h>
2017 #endif
2018
2019+#define ktla_ktva(addr) (addr)
2020+#define ktva_ktla(addr) (addr)
2021+
2022 /*
2023 * Just any arbitrary offset to the start of the vmalloc VM area: the
2024 * current 8MB value just means that there will be a 8MB "hole" after the
2025@@ -48,6 +51,9 @@
2026 #define LIBRARY_TEXT_START 0x0c000000
2027
2028 #ifndef __ASSEMBLY__
2029+extern pteval_t __supported_pte_mask;
2030+extern pmdval_t __supported_pmd_mask;
2031+
2032 extern void __pte_error(const char *file, int line, pte_t);
2033 extern void __pmd_error(const char *file, int line, pmd_t);
2034 extern void __pgd_error(const char *file, int line, pgd_t);
2035@@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2036 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2037 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2038
2039+#define __HAVE_ARCH_PAX_OPEN_KERNEL
2040+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2041+
2042+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2043+#include <asm/domain.h>
2044+#include <linux/thread_info.h>
2045+#include <linux/preempt.h>
2046+
2047+static inline int test_domain(int domain, int domaintype)
2048+{
2049+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2050+}
2051+#endif
2052+
2053+#ifdef CONFIG_PAX_KERNEXEC
2054+static inline unsigned long pax_open_kernel(void) {
2055+#ifdef CONFIG_ARM_LPAE
2056+ /* TODO */
2057+#else
2058+ preempt_disable();
2059+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2060+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2061+#endif
2062+ return 0;
2063+}
2064+
2065+static inline unsigned long pax_close_kernel(void) {
2066+#ifdef CONFIG_ARM_LPAE
2067+ /* TODO */
2068+#else
2069+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2070+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2071+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2072+ preempt_enable_no_resched();
2073+#endif
2074+ return 0;
2075+}
2076+#else
2077+static inline unsigned long pax_open_kernel(void) { return 0; }
2078+static inline unsigned long pax_close_kernel(void) { return 0; }
2079+#endif
2080+
2081 /*
2082 * This is the lowest virtual address we can permit any user space
2083 * mapping to be mapped at. This is particularly important for
2084@@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2085 /*
2086 * The pgprot_* and protection_map entries will be fixed up in runtime
2087 * to include the cachable and bufferable bits based on memory policy,
2088- * as well as any architecture dependent bits like global/ASID and SMP
2089- * shared mapping bits.
2090+ * as well as any architecture dependent bits like global/ASID, PXN,
2091+ * and SMP shared mapping bits.
2092 */
2093 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2094
2095@@ -260,7 +308,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2096 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2097 {
2098 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2099- L_PTE_NONE | L_PTE_VALID;
2100+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2101 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2102 return pte;
2103 }
2104diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2105index c4ae171..ea0c0c2 100644
2106--- a/arch/arm/include/asm/psci.h
2107+++ b/arch/arm/include/asm/psci.h
2108@@ -29,7 +29,7 @@ struct psci_operations {
2109 int (*cpu_off)(struct psci_power_state state);
2110 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2111 int (*migrate)(unsigned long cpuid);
2112-};
2113+} __no_const;
2114
2115 extern struct psci_operations psci_ops;
2116 extern struct smp_operations psci_smp_ops;
2117diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2118index 22a3b9b..7f214ee 100644
2119--- a/arch/arm/include/asm/smp.h
2120+++ b/arch/arm/include/asm/smp.h
2121@@ -112,7 +112,7 @@ struct smp_operations {
2122 int (*cpu_disable)(unsigned int cpu);
2123 #endif
2124 #endif
2125-};
2126+} __no_const;
2127
2128 /*
2129 * set platform specific SMP operations
2130diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2131index 71a06b2..8bb9ae1 100644
2132--- a/arch/arm/include/asm/thread_info.h
2133+++ b/arch/arm/include/asm/thread_info.h
2134@@ -88,9 +88,9 @@ struct thread_info {
2135 .flags = 0, \
2136 .preempt_count = INIT_PREEMPT_COUNT, \
2137 .addr_limit = KERNEL_DS, \
2138- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2139- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2140- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2141+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2142+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2143+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2144 .restart_block = { \
2145 .fn = do_no_restart_syscall, \
2146 }, \
2147@@ -157,7 +157,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2148 #define TIF_SYSCALL_AUDIT 9
2149 #define TIF_SYSCALL_TRACEPOINT 10
2150 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2151-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2152+/* within 8 bits of TIF_SYSCALL_TRACE
2153+ * to meet flexible second operand requirements
2154+ */
2155+#define TIF_GRSEC_SETXID 12
2156+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2157 #define TIF_USING_IWMMXT 17
2158 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2159 #define TIF_RESTORE_SIGMASK 20
2160@@ -170,10 +174,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2161 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2162 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2163 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2164+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2165
2166 /* Checks for any syscall work in entry-common.S */
2167 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2168- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2169+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2170
2171 /*
2172 * Change these and you break ASM code in entry-common.S
2173diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2174index 72abdc5..35acac1 100644
2175--- a/arch/arm/include/asm/uaccess.h
2176+++ b/arch/arm/include/asm/uaccess.h
2177@@ -18,6 +18,7 @@
2178 #include <asm/domain.h>
2179 #include <asm/unified.h>
2180 #include <asm/compiler.h>
2181+#include <asm/pgtable.h>
2182
2183 #if __LINUX_ARM_ARCH__ < 6
2184 #include <asm-generic/uaccess-unaligned.h>
2185@@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2186 static inline void set_fs(mm_segment_t fs)
2187 {
2188 current_thread_info()->addr_limit = fs;
2189- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2190+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2191 }
2192
2193 #define segment_eq(a,b) ((a) == (b))
2194
2195+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2196+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2197+
2198+static inline void pax_open_userland(void)
2199+{
2200+
2201+#ifdef CONFIG_PAX_MEMORY_UDEREF
2202+ if (segment_eq(get_fs(), USER_DS)) {
2203+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2204+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2205+ }
2206+#endif
2207+
2208+}
2209+
2210+static inline void pax_close_userland(void)
2211+{
2212+
2213+#ifdef CONFIG_PAX_MEMORY_UDEREF
2214+ if (segment_eq(get_fs(), USER_DS)) {
2215+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2216+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2217+ }
2218+#endif
2219+
2220+}
2221+
2222 #define __addr_ok(addr) ({ \
2223 unsigned long flag; \
2224 __asm__("cmp %2, %0; movlo %0, #0" \
2225@@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2226
2227 #define get_user(x,p) \
2228 ({ \
2229+ int __e; \
2230 might_fault(); \
2231- __get_user_check(x,p); \
2232+ pax_open_userland(); \
2233+ __e = __get_user_check(x,p); \
2234+ pax_close_userland(); \
2235+ __e; \
2236 })
2237
2238 extern int __put_user_1(void *, unsigned int);
2239@@ -195,8 +227,12 @@ extern int __put_user_8(void *, unsigned long long);
2240
2241 #define put_user(x,p) \
2242 ({ \
2243+ int __e; \
2244 might_fault(); \
2245- __put_user_check(x,p); \
2246+ pax_open_userland(); \
2247+ __e = __put_user_check(x,p); \
2248+ pax_close_userland(); \
2249+ __e; \
2250 })
2251
2252 #else /* CONFIG_MMU */
2253@@ -220,6 +256,7 @@ static inline void set_fs(mm_segment_t fs)
2254
2255 #endif /* CONFIG_MMU */
2256
2257+#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2258 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2259
2260 #define user_addr_max() \
2261@@ -237,13 +274,17 @@ static inline void set_fs(mm_segment_t fs)
2262 #define __get_user(x,ptr) \
2263 ({ \
2264 long __gu_err = 0; \
2265+ pax_open_userland(); \
2266 __get_user_err((x),(ptr),__gu_err); \
2267+ pax_close_userland(); \
2268 __gu_err; \
2269 })
2270
2271 #define __get_user_error(x,ptr,err) \
2272 ({ \
2273+ pax_open_userland(); \
2274 __get_user_err((x),(ptr),err); \
2275+ pax_close_userland(); \
2276 (void) 0; \
2277 })
2278
2279@@ -319,13 +360,17 @@ do { \
2280 #define __put_user(x,ptr) \
2281 ({ \
2282 long __pu_err = 0; \
2283+ pax_open_userland(); \
2284 __put_user_err((x),(ptr),__pu_err); \
2285+ pax_close_userland(); \
2286 __pu_err; \
2287 })
2288
2289 #define __put_user_error(x,ptr,err) \
2290 ({ \
2291+ pax_open_userland(); \
2292 __put_user_err((x),(ptr),err); \
2293+ pax_close_userland(); \
2294 (void) 0; \
2295 })
2296
2297@@ -425,11 +470,44 @@ do { \
2298
2299
2300 #ifdef CONFIG_MMU
2301-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2302-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2303+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2304+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2305+
2306+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2307+{
2308+ unsigned long ret;
2309+
2310+ check_object_size(to, n, false);
2311+ pax_open_userland();
2312+ ret = ___copy_from_user(to, from, n);
2313+ pax_close_userland();
2314+ return ret;
2315+}
2316+
2317+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2318+{
2319+ unsigned long ret;
2320+
2321+ check_object_size(from, n, true);
2322+ pax_open_userland();
2323+ ret = ___copy_to_user(to, from, n);
2324+ pax_close_userland();
2325+ return ret;
2326+}
2327+
2328 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2329-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2330+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2331 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2332+
2333+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2334+{
2335+ unsigned long ret;
2336+ pax_open_userland();
2337+ ret = ___clear_user(addr, n);
2338+ pax_close_userland();
2339+ return ret;
2340+}
2341+
2342 #else
2343 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2344 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2345@@ -438,6 +516,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2346
2347 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2348 {
2349+ if ((long)n < 0)
2350+ return n;
2351+
2352 if (access_ok(VERIFY_READ, from, n))
2353 n = __copy_from_user(to, from, n);
2354 else /* security hole - plug it */
2355@@ -447,6 +528,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2356
2357 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2358 {
2359+ if ((long)n < 0)
2360+ return n;
2361+
2362 if (access_ok(VERIFY_WRITE, to, n))
2363 n = __copy_to_user(to, from, n);
2364 return n;
2365diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2366index 5af0ed1..cea83883 100644
2367--- a/arch/arm/include/uapi/asm/ptrace.h
2368+++ b/arch/arm/include/uapi/asm/ptrace.h
2369@@ -92,7 +92,7 @@
2370 * ARMv7 groups of PSR bits
2371 */
2372 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2373-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2374+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2375 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2376 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2377
2378diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2379index 1f031dd..d9b5e4a 100644
2380--- a/arch/arm/kernel/armksyms.c
2381+++ b/arch/arm/kernel/armksyms.c
2382@@ -53,7 +53,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2383
2384 /* networking */
2385 EXPORT_SYMBOL(csum_partial);
2386-EXPORT_SYMBOL(csum_partial_copy_from_user);
2387+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2388 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2389 EXPORT_SYMBOL(__csum_ipv6_magic);
2390
2391@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2392 #ifdef CONFIG_MMU
2393 EXPORT_SYMBOL(copy_page);
2394
2395-EXPORT_SYMBOL(__copy_from_user);
2396-EXPORT_SYMBOL(__copy_to_user);
2397-EXPORT_SYMBOL(__clear_user);
2398+EXPORT_SYMBOL(___copy_from_user);
2399+EXPORT_SYMBOL(___copy_to_user);
2400+EXPORT_SYMBOL(___clear_user);
2401
2402 EXPORT_SYMBOL(__get_user_1);
2403 EXPORT_SYMBOL(__get_user_2);
2404diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2405index b3fb8c9..59cfab2 100644
2406--- a/arch/arm/kernel/entry-armv.S
2407+++ b/arch/arm/kernel/entry-armv.S
2408@@ -47,6 +47,87 @@
2409 9997:
2410 .endm
2411
2412+ .macro pax_enter_kernel
2413+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2414+ @ make aligned space for saved DACR
2415+ sub sp, sp, #8
2416+ @ save regs
2417+ stmdb sp!, {r1, r2}
2418+ @ read DACR from cpu_domain into r1
2419+ mov r2, sp
2420+ @ assume 8K pages, since we have to split the immediate in two
2421+ bic r2, r2, #(0x1fc0)
2422+ bic r2, r2, #(0x3f)
2423+ ldr r1, [r2, #TI_CPU_DOMAIN]
2424+ @ store old DACR on stack
2425+ str r1, [sp, #8]
2426+#ifdef CONFIG_PAX_KERNEXEC
2427+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2428+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2429+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2430+#endif
2431+#ifdef CONFIG_PAX_MEMORY_UDEREF
2432+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2433+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2434+#endif
2435+ @ write r1 to current_thread_info()->cpu_domain
2436+ str r1, [r2, #TI_CPU_DOMAIN]
2437+ @ write r1 to DACR
2438+ mcr p15, 0, r1, c3, c0, 0
2439+ @ instruction sync
2440+ instr_sync
2441+ @ restore regs
2442+ ldmia sp!, {r1, r2}
2443+#endif
2444+ .endm
2445+
2446+ .macro pax_open_userland
2447+#ifdef CONFIG_PAX_MEMORY_UDEREF
2448+ @ save regs
2449+ stmdb sp!, {r0, r1}
2450+ @ read DACR from cpu_domain into r1
2451+ mov r0, sp
2452+ @ assume 8K pages, since we have to split the immediate in two
2453+ bic r0, r0, #(0x1fc0)
2454+ bic r0, r0, #(0x3f)
2455+ ldr r1, [r0, #TI_CPU_DOMAIN]
2456+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2457+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2458+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2459+ @ write r1 to current_thread_info()->cpu_domain
2460+ str r1, [r0, #TI_CPU_DOMAIN]
2461+ @ write r1 to DACR
2462+ mcr p15, 0, r1, c3, c0, 0
2463+ @ instruction sync
2464+ instr_sync
2465+ @ restore regs
2466+ ldmia sp!, {r0, r1}
2467+#endif
2468+ .endm
2469+
2470+ .macro pax_close_userland
2471+#ifdef CONFIG_PAX_MEMORY_UDEREF
2472+ @ save regs
2473+ stmdb sp!, {r0, r1}
2474+ @ read DACR from cpu_domain into r1
2475+ mov r0, sp
2476+ @ assume 8K pages, since we have to split the immediate in two
2477+ bic r0, r0, #(0x1fc0)
2478+ bic r0, r0, #(0x3f)
2479+ ldr r1, [r0, #TI_CPU_DOMAIN]
2480+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2481+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2482+ @ write r1 to current_thread_info()->cpu_domain
2483+ str r1, [r0, #TI_CPU_DOMAIN]
2484+ @ write r1 to DACR
2485+ mcr p15, 0, r1, c3, c0, 0
2486+ @ instruction sync
2487+ instr_sync
2488+ @ restore regs
2489+ ldmia sp!, {r0, r1}
2490+#endif
2491+ .endm
2492+
2493 .macro pabt_helper
2494 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2495 #ifdef MULTI_PABORT
2496@@ -89,11 +170,15 @@
2497 * Invalid mode handlers
2498 */
2499 .macro inv_entry, reason
2500+
2501+ pax_enter_kernel
2502+
2503 sub sp, sp, #S_FRAME_SIZE
2504 ARM( stmib sp, {r1 - lr} )
2505 THUMB( stmia sp, {r0 - r12} )
2506 THUMB( str sp, [sp, #S_SP] )
2507 THUMB( str lr, [sp, #S_LR] )
2508+
2509 mov r1, #\reason
2510 .endm
2511
2512@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2513 .macro svc_entry, stack_hole=0
2514 UNWIND(.fnstart )
2515 UNWIND(.save {r0 - pc} )
2516+
2517+ pax_enter_kernel
2518+
2519 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2520+
2521 #ifdef CONFIG_THUMB2_KERNEL
2522 SPFIX( str r0, [sp] ) @ temporarily saved
2523 SPFIX( mov r0, sp )
2524@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2525 ldmia r0, {r3 - r5}
2526 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2527 mov r6, #-1 @ "" "" "" ""
2528+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2529+ @ offset sp by 8 as done in pax_enter_kernel
2530+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2531+#else
2532 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2533+#endif
2534 SPFIX( addeq r2, r2, #4 )
2535 str r3, [sp, #-4]! @ save the "real" r0 copied
2536 @ from the exception stack
2537@@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2538 .macro usr_entry
2539 UNWIND(.fnstart )
2540 UNWIND(.cantunwind ) @ don't unwind the user space
2541+
2542+ pax_enter_kernel_user
2543+
2544 sub sp, sp, #S_FRAME_SIZE
2545 ARM( stmib sp, {r1 - r12} )
2546 THUMB( stmia sp, {r0 - r12} )
2547@@ -416,7 +513,9 @@ __und_usr:
2548 tst r3, #PSR_T_BIT @ Thumb mode?
2549 bne __und_usr_thumb
2550 sub r4, r2, #4 @ ARM instr at LR - 4
2551+ pax_open_userland
2552 1: ldrt r0, [r4]
2553+ pax_close_userland
2554 ARM_BE8(rev r0, r0) @ little endian instruction
2555
2556 @ r0 = 32-bit ARM instruction which caused the exception
2557@@ -450,10 +549,14 @@ __und_usr_thumb:
2558 */
2559 .arch armv6t2
2560 #endif
2561+ pax_open_userland
2562 2: ldrht r5, [r4]
2563+ pax_close_userland
2564 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2565 blo __und_usr_fault_16 @ 16bit undefined instruction
2566+ pax_open_userland
2567 3: ldrht r0, [r2]
2568+ pax_close_userland
2569 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2570 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2571 orr r0, r0, r5, lsl #16
2572@@ -482,7 +585,8 @@ ENDPROC(__und_usr)
2573 */
2574 .pushsection .fixup, "ax"
2575 .align 2
2576-4: mov pc, r9
2577+4: pax_close_userland
2578+ mov pc, r9
2579 .popsection
2580 .pushsection __ex_table,"a"
2581 .long 1b, 4b
2582@@ -692,7 +796,7 @@ ENTRY(__switch_to)
2583 THUMB( str lr, [ip], #4 )
2584 ldr r4, [r2, #TI_TP_VALUE]
2585 ldr r5, [r2, #TI_TP_VALUE + 4]
2586-#ifdef CONFIG_CPU_USE_DOMAINS
2587+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2588 ldr r6, [r2, #TI_CPU_DOMAIN]
2589 #endif
2590 switch_tls r1, r4, r5, r3, r7
2591@@ -701,7 +805,7 @@ ENTRY(__switch_to)
2592 ldr r8, =__stack_chk_guard
2593 ldr r7, [r7, #TSK_STACK_CANARY]
2594 #endif
2595-#ifdef CONFIG_CPU_USE_DOMAINS
2596+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2597 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2598 #endif
2599 mov r5, r0
2600diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2601index a2dcafd..1048b5a 100644
2602--- a/arch/arm/kernel/entry-common.S
2603+++ b/arch/arm/kernel/entry-common.S
2604@@ -10,18 +10,46 @@
2605
2606 #include <asm/unistd.h>
2607 #include <asm/ftrace.h>
2608+#include <asm/domain.h>
2609 #include <asm/unwind.h>
2610
2611+#include "entry-header.S"
2612+
2613 #ifdef CONFIG_NEED_RET_TO_USER
2614 #include <mach/entry-macro.S>
2615 #else
2616 .macro arch_ret_to_user, tmp1, tmp2
2617+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2618+ @ save regs
2619+ stmdb sp!, {r1, r2}
2620+ @ read DACR from cpu_domain into r1
2621+ mov r2, sp
2622+ @ assume 8K pages, since we have to split the immediate in two
2623+ bic r2, r2, #(0x1fc0)
2624+ bic r2, r2, #(0x3f)
2625+ ldr r1, [r2, #TI_CPU_DOMAIN]
2626+#ifdef CONFIG_PAX_KERNEXEC
2627+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2628+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2629+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2630+#endif
2631+#ifdef CONFIG_PAX_MEMORY_UDEREF
2632+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2633+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2634+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2635+#endif
2636+ @ write r1 to current_thread_info()->cpu_domain
2637+ str r1, [r2, #TI_CPU_DOMAIN]
2638+ @ write r1 to DACR
2639+ mcr p15, 0, r1, c3, c0, 0
2640+ @ instruction sync
2641+ instr_sync
2642+ @ restore regs
2643+ ldmia sp!, {r1, r2}
2644+#endif
2645 .endm
2646 #endif
2647
2648-#include "entry-header.S"
2649-
2650-
2651 .align 5
2652 /*
2653 * This is the fast syscall return path. We do as little as
2654@@ -411,6 +439,12 @@ ENTRY(vector_swi)
2655 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2656 #endif
2657
2658+ /*
2659+ * do this here to avoid a performance hit of wrapping the code above
2660+ * that directly dereferences userland to parse the SWI instruction
2661+ */
2662+ pax_enter_kernel_user
2663+
2664 adr tbl, sys_call_table @ load syscall table pointer
2665
2666 #if defined(CONFIG_OABI_COMPAT)
2667diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2668index 39f89fb..d612bd9 100644
2669--- a/arch/arm/kernel/entry-header.S
2670+++ b/arch/arm/kernel/entry-header.S
2671@@ -184,6 +184,60 @@
2672 msr cpsr_c, \rtemp @ switch back to the SVC mode
2673 .endm
2674
2675+ .macro pax_enter_kernel_user
2676+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2677+ @ save regs
2678+ stmdb sp!, {r0, r1}
2679+ @ read DACR from cpu_domain into r1
2680+ mov r0, sp
2681+ @ assume 8K pages, since we have to split the immediate in two
2682+ bic r0, r0, #(0x1fc0)
2683+ bic r0, r0, #(0x3f)
2684+ ldr r1, [r0, #TI_CPU_DOMAIN]
2685+#ifdef CONFIG_PAX_MEMORY_UDEREF
2686+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2687+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2688+#endif
2689+#ifdef CONFIG_PAX_KERNEXEC
2690+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2691+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2692+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2693+#endif
2694+ @ write r1 to current_thread_info()->cpu_domain
2695+ str r1, [r0, #TI_CPU_DOMAIN]
2696+ @ write r1 to DACR
2697+ mcr p15, 0, r1, c3, c0, 0
2698+ @ instruction sync
2699+ instr_sync
2700+ @ restore regs
2701+ ldmia sp!, {r0, r1}
2702+#endif
2703+ .endm
2704+
2705+ .macro pax_exit_kernel
2706+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2707+ @ save regs
2708+ stmdb sp!, {r0, r1}
2709+ @ read old DACR from stack into r1
2710+ ldr r1, [sp, #(8 + S_SP)]
2711+ sub r1, r1, #8
2712+ ldr r1, [r1]
2713+
2714+ @ write r1 to current_thread_info()->cpu_domain
2715+ mov r0, sp
2716+ @ assume 8K pages, since we have to split the immediate in two
2717+ bic r0, r0, #(0x1fc0)
2718+ bic r0, r0, #(0x3f)
2719+ str r1, [r0, #TI_CPU_DOMAIN]
2720+ @ write r1 to DACR
2721+ mcr p15, 0, r1, c3, c0, 0
2722+ @ instruction sync
2723+ instr_sync
2724+ @ restore regs
2725+ ldmia sp!, {r0, r1}
2726+#endif
2727+ .endm
2728+
2729 #ifndef CONFIG_THUMB2_KERNEL
2730 .macro svc_exit, rpsr, irq = 0
2731 .if \irq != 0
2732@@ -203,6 +257,9 @@
2733 blne trace_hardirqs_off
2734 #endif
2735 .endif
2736+
2737+ pax_exit_kernel
2738+
2739 msr spsr_cxsf, \rpsr
2740 #if defined(CONFIG_CPU_V6)
2741 ldr r0, [sp]
2742@@ -266,6 +323,9 @@
2743 blne trace_hardirqs_off
2744 #endif
2745 .endif
2746+
2747+ pax_exit_kernel
2748+
2749 ldr lr, [sp, #S_SP] @ top of the stack
2750 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2751 clrex @ clear the exclusive monitor
2752diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2753index 918875d..cd5fa27 100644
2754--- a/arch/arm/kernel/fiq.c
2755+++ b/arch/arm/kernel/fiq.c
2756@@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2757 void *base = vectors_page;
2758 unsigned offset = FIQ_OFFSET;
2759
2760+ pax_open_kernel();
2761 memcpy(base + offset, start, length);
2762+ pax_close_kernel();
2763+
2764 if (!cache_is_vipt_nonaliasing())
2765 flush_icache_range((unsigned long)base + offset, offset +
2766 length);
2767diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2768index 32f317e..710ae07 100644
2769--- a/arch/arm/kernel/head.S
2770+++ b/arch/arm/kernel/head.S
2771@@ -52,7 +52,9 @@
2772 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2773
2774 .macro pgtbl, rd, phys
2775- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2776+ mov \rd, #TEXT_OFFSET
2777+ sub \rd, #PG_DIR_SIZE
2778+ add \rd, \rd, \phys
2779 .endm
2780
2781 /*
2782@@ -436,7 +438,7 @@ __enable_mmu:
2783 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2784 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2785 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2786- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2787+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2788 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2789 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2790 #endif
2791diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2792index 45e4781..8eac93d 100644
2793--- a/arch/arm/kernel/module.c
2794+++ b/arch/arm/kernel/module.c
2795@@ -38,12 +38,39 @@
2796 #endif
2797
2798 #ifdef CONFIG_MMU
2799-void *module_alloc(unsigned long size)
2800+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2801 {
2802+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2803+ return NULL;
2804 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2805- GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2806+ GFP_KERNEL, prot, NUMA_NO_NODE,
2807 __builtin_return_address(0));
2808 }
2809+
2810+void *module_alloc(unsigned long size)
2811+{
2812+
2813+#ifdef CONFIG_PAX_KERNEXEC
2814+ return __module_alloc(size, PAGE_KERNEL);
2815+#else
2816+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2817+#endif
2818+
2819+}
2820+
2821+#ifdef CONFIG_PAX_KERNEXEC
2822+void module_free_exec(struct module *mod, void *module_region)
2823+{
2824+ module_free(mod, module_region);
2825+}
2826+EXPORT_SYMBOL(module_free_exec);
2827+
2828+void *module_alloc_exec(unsigned long size)
2829+{
2830+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2831+}
2832+EXPORT_SYMBOL(module_alloc_exec);
2833+#endif
2834 #endif
2835
2836 int
2837diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2838index 07314af..c46655c 100644
2839--- a/arch/arm/kernel/patch.c
2840+++ b/arch/arm/kernel/patch.c
2841@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2842 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2843 int size;
2844
2845+ pax_open_kernel();
2846 if (thumb2 && __opcode_is_thumb16(insn)) {
2847 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2848 size = sizeof(u16);
2849@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2850 *(u32 *)addr = insn;
2851 size = sizeof(u32);
2852 }
2853+ pax_close_kernel();
2854
2855 flush_icache_range((uintptr_t)(addr),
2856 (uintptr_t)(addr) + size);
2857diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2858index 92f7b15..7048500 100644
2859--- a/arch/arm/kernel/process.c
2860+++ b/arch/arm/kernel/process.c
2861@@ -217,6 +217,7 @@ void machine_power_off(void)
2862
2863 if (pm_power_off)
2864 pm_power_off();
2865+ BUG();
2866 }
2867
2868 /*
2869@@ -230,7 +231,7 @@ void machine_power_off(void)
2870 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2871 * to use. Implementing such co-ordination would be essentially impossible.
2872 */
2873-void machine_restart(char *cmd)
2874+__noreturn void machine_restart(char *cmd)
2875 {
2876 local_irq_disable();
2877 smp_send_stop();
2878@@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2879
2880 show_regs_print_info(KERN_DEFAULT);
2881
2882- print_symbol("PC is at %s\n", instruction_pointer(regs));
2883- print_symbol("LR is at %s\n", regs->ARM_lr);
2884+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2885+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2886 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2887 "sp : %08lx ip : %08lx fp : %08lx\n",
2888 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2889@@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2890 return 0;
2891 }
2892
2893-unsigned long arch_randomize_brk(struct mm_struct *mm)
2894-{
2895- unsigned long range_end = mm->brk + 0x02000000;
2896- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2897-}
2898-
2899 #ifdef CONFIG_MMU
2900 #ifdef CONFIG_KUSER_HELPERS
2901 /*
2902@@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
2903
2904 static int __init gate_vma_init(void)
2905 {
2906- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2907+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2908 return 0;
2909 }
2910 arch_initcall(gate_vma_init);
2911@@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
2912
2913 const char *arch_vma_name(struct vm_area_struct *vma)
2914 {
2915- return is_gate_vma(vma) ? "[vectors]" :
2916- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2917- "[sigpage]" : NULL;
2918+ return is_gate_vma(vma) ? "[vectors]" : NULL;
2919 }
2920
2921-static struct page *signal_page;
2922-extern struct page *get_signal_page(void);
2923-
2924 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2925 {
2926 struct mm_struct *mm = current->mm;
2927- unsigned long addr;
2928- int ret;
2929-
2930- if (!signal_page)
2931- signal_page = get_signal_page();
2932- if (!signal_page)
2933- return -ENOMEM;
2934
2935 down_write(&mm->mmap_sem);
2936- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2937- if (IS_ERR_VALUE(addr)) {
2938- ret = addr;
2939- goto up_fail;
2940- }
2941-
2942- ret = install_special_mapping(mm, addr, PAGE_SIZE,
2943- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2944- &signal_page);
2945-
2946- if (ret == 0)
2947- mm->context.sigpage = addr;
2948-
2949- up_fail:
2950+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2951 up_write(&mm->mmap_sem);
2952- return ret;
2953+ return 0;
2954 }
2955 #endif
2956diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2957index 4693188..4596c5e 100644
2958--- a/arch/arm/kernel/psci.c
2959+++ b/arch/arm/kernel/psci.c
2960@@ -24,7 +24,7 @@
2961 #include <asm/opcodes-virt.h>
2962 #include <asm/psci.h>
2963
2964-struct psci_operations psci_ops;
2965+struct psci_operations psci_ops __read_only;
2966
2967 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2968
2969diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2970index 0dd3b79..e018f64 100644
2971--- a/arch/arm/kernel/ptrace.c
2972+++ b/arch/arm/kernel/ptrace.c
2973@@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2974 return current_thread_info()->syscall;
2975 }
2976
2977+#ifdef CONFIG_GRKERNSEC_SETXID
2978+extern void gr_delayed_cred_worker(void);
2979+#endif
2980+
2981 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2982 {
2983 current_thread_info()->syscall = scno;
2984
2985+#ifdef CONFIG_GRKERNSEC_SETXID
2986+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2987+ gr_delayed_cred_worker();
2988+#endif
2989+
2990 /* Do the secure computing check first; failures should be fast. */
2991 if (secure_computing(scno) == -1)
2992 return -1;
2993diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2994index 987a7f5..ab0c397 100644
2995--- a/arch/arm/kernel/setup.c
2996+++ b/arch/arm/kernel/setup.c
2997@@ -100,21 +100,23 @@ EXPORT_SYMBOL(system_serial_high);
2998 unsigned int elf_hwcap __read_mostly;
2999 EXPORT_SYMBOL(elf_hwcap);
3000
3001+pteval_t __supported_pte_mask __read_only;
3002+pmdval_t __supported_pmd_mask __read_only;
3003
3004 #ifdef MULTI_CPU
3005-struct processor processor __read_mostly;
3006+struct processor processor __read_only;
3007 #endif
3008 #ifdef MULTI_TLB
3009-struct cpu_tlb_fns cpu_tlb __read_mostly;
3010+struct cpu_tlb_fns cpu_tlb __read_only;
3011 #endif
3012 #ifdef MULTI_USER
3013-struct cpu_user_fns cpu_user __read_mostly;
3014+struct cpu_user_fns cpu_user __read_only;
3015 #endif
3016 #ifdef MULTI_CACHE
3017-struct cpu_cache_fns cpu_cache __read_mostly;
3018+struct cpu_cache_fns cpu_cache __read_only;
3019 #endif
3020 #ifdef CONFIG_OUTER_CACHE
3021-struct outer_cache_fns outer_cache __read_mostly;
3022+struct outer_cache_fns outer_cache __read_only;
3023 EXPORT_SYMBOL(outer_cache);
3024 #endif
3025
3026@@ -247,9 +249,13 @@ static int __get_cpu_architecture(void)
3027 asm("mrc p15, 0, %0, c0, c1, 4"
3028 : "=r" (mmfr0));
3029 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3030- (mmfr0 & 0x000000f0) >= 0x00000030)
3031+ (mmfr0 & 0x000000f0) >= 0x00000030) {
3032 cpu_arch = CPU_ARCH_ARMv7;
3033- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3034+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3035+ __supported_pte_mask |= L_PTE_PXN;
3036+ __supported_pmd_mask |= PMD_PXNTABLE;
3037+ }
3038+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3039 (mmfr0 & 0x000000f0) == 0x00000020)
3040 cpu_arch = CPU_ARCH_ARMv6;
3041 else
3042diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3043index 04d6388..5115238 100644
3044--- a/arch/arm/kernel/signal.c
3045+++ b/arch/arm/kernel/signal.c
3046@@ -23,8 +23,6 @@
3047
3048 extern const unsigned long sigreturn_codes[7];
3049
3050-static unsigned long signal_return_offset;
3051-
3052 #ifdef CONFIG_CRUNCH
3053 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3054 {
3055@@ -395,8 +393,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3056 * except when the MPU has protected the vectors
3057 * page from PL0
3058 */
3059- retcode = mm->context.sigpage + signal_return_offset +
3060- (idx << 2) + thumb;
3061+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3062 } else
3063 #endif
3064 {
3065@@ -600,33 +597,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3066 } while (thread_flags & _TIF_WORK_MASK);
3067 return 0;
3068 }
3069-
3070-struct page *get_signal_page(void)
3071-{
3072- unsigned long ptr;
3073- unsigned offset;
3074- struct page *page;
3075- void *addr;
3076-
3077- page = alloc_pages(GFP_KERNEL, 0);
3078-
3079- if (!page)
3080- return NULL;
3081-
3082- addr = page_address(page);
3083-
3084- /* Give the signal return code some randomness */
3085- offset = 0x200 + (get_random_int() & 0x7fc);
3086- signal_return_offset = offset;
3087-
3088- /*
3089- * Copy signal return handlers into the vector page, and
3090- * set sigreturn to be a pointer to these.
3091- */
3092- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3093-
3094- ptr = (unsigned long)addr + offset;
3095- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3096-
3097- return page;
3098-}
3099diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3100index dc894ab..f929a0d 100644
3101--- a/arch/arm/kernel/smp.c
3102+++ b/arch/arm/kernel/smp.c
3103@@ -73,7 +73,7 @@ enum ipi_msg_type {
3104
3105 static DECLARE_COMPLETION(cpu_running);
3106
3107-static struct smp_operations smp_ops;
3108+static struct smp_operations smp_ops __read_only;
3109
3110 void __init smp_set_ops(struct smp_operations *ops)
3111 {
3112diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3113index 4636d56..ce4ec3d 100644
3114--- a/arch/arm/kernel/traps.c
3115+++ b/arch/arm/kernel/traps.c
3116@@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3117 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3118 {
3119 #ifdef CONFIG_KALLSYMS
3120- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3121+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3122 #else
3123 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3124 #endif
3125@@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3126 static int die_owner = -1;
3127 static unsigned int die_nest_count;
3128
3129+extern void gr_handle_kernel_exploit(void);
3130+
3131 static unsigned long oops_begin(void)
3132 {
3133 int cpu;
3134@@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3135 panic("Fatal exception in interrupt");
3136 if (panic_on_oops)
3137 panic("Fatal exception");
3138+
3139+ gr_handle_kernel_exploit();
3140+
3141 if (signr)
3142 do_exit(signr);
3143 }
3144@@ -642,7 +647,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3145 * The user helper at 0xffff0fe0 must be used instead.
3146 * (see entry-armv.S for details)
3147 */
3148+ pax_open_kernel();
3149 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3150+ pax_close_kernel();
3151 }
3152 return 0;
3153
3154@@ -899,7 +906,11 @@ void __init early_trap_init(void *vectors_base)
3155 kuser_init(vectors_base);
3156
3157 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3158- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3159+
3160+#ifndef CONFIG_PAX_MEMORY_UDEREF
3161+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3162+#endif
3163+
3164 #else /* ifndef CONFIG_CPU_V7M */
3165 /*
3166 * on V7-M there is no need to copy the vector table to a dedicated
3167diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3168index 7bcee5c..e2f3249 100644
3169--- a/arch/arm/kernel/vmlinux.lds.S
3170+++ b/arch/arm/kernel/vmlinux.lds.S
3171@@ -8,7 +8,11 @@
3172 #include <asm/thread_info.h>
3173 #include <asm/memory.h>
3174 #include <asm/page.h>
3175-
3176+
3177+#ifdef CONFIG_PAX_KERNEXEC
3178+#include <asm/pgtable.h>
3179+#endif
3180+
3181 #define PROC_INFO \
3182 . = ALIGN(4); \
3183 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3184@@ -34,7 +38,7 @@
3185 #endif
3186
3187 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3188- defined(CONFIG_GENERIC_BUG)
3189+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3190 #define ARM_EXIT_KEEP(x) x
3191 #define ARM_EXIT_DISCARD(x)
3192 #else
3193@@ -90,6 +94,11 @@ SECTIONS
3194 _text = .;
3195 HEAD_TEXT
3196 }
3197+
3198+#ifdef CONFIG_PAX_KERNEXEC
3199+ . = ALIGN(1<<SECTION_SHIFT);
3200+#endif
3201+
3202 .text : { /* Real text segment */
3203 _stext = .; /* Text and read-only data */
3204 __exception_text_start = .;
3205@@ -112,6 +121,8 @@ SECTIONS
3206 ARM_CPU_KEEP(PROC_INFO)
3207 }
3208
3209+ _etext = .; /* End of text section */
3210+
3211 RO_DATA(PAGE_SIZE)
3212
3213 . = ALIGN(4);
3214@@ -142,7 +153,9 @@ SECTIONS
3215
3216 NOTES
3217
3218- _etext = .; /* End of text and rodata section */
3219+#ifdef CONFIG_PAX_KERNEXEC
3220+ . = ALIGN(1<<SECTION_SHIFT);
3221+#endif
3222
3223 #ifndef CONFIG_XIP_KERNEL
3224 . = ALIGN(PAGE_SIZE);
3225@@ -220,6 +233,11 @@ SECTIONS
3226 . = PAGE_OFFSET + TEXT_OFFSET;
3227 #else
3228 __init_end = .;
3229+
3230+#ifdef CONFIG_PAX_KERNEXEC
3231+ . = ALIGN(1<<SECTION_SHIFT);
3232+#endif
3233+
3234 . = ALIGN(THREAD_SIZE);
3235 __data_loc = .;
3236 #endif
3237diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3238index 2a700e0..745b980 100644
3239--- a/arch/arm/kvm/arm.c
3240+++ b/arch/arm/kvm/arm.c
3241@@ -56,7 +56,7 @@ static unsigned long hyp_default_vectors;
3242 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3243
3244 /* The VMID used in the VTTBR */
3245-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3246+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3247 static u8 kvm_next_vmid;
3248 static DEFINE_SPINLOCK(kvm_vmid_lock);
3249
3250@@ -397,7 +397,7 @@ void force_vm_exit(const cpumask_t *mask)
3251 */
3252 static bool need_new_vmid_gen(struct kvm *kvm)
3253 {
3254- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3255+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3256 }
3257
3258 /**
3259@@ -430,7 +430,7 @@ static void update_vttbr(struct kvm *kvm)
3260
3261 /* First user of a new VMID generation? */
3262 if (unlikely(kvm_next_vmid == 0)) {
3263- atomic64_inc(&kvm_vmid_gen);
3264+ atomic64_inc_unchecked(&kvm_vmid_gen);
3265 kvm_next_vmid = 1;
3266
3267 /*
3268@@ -447,7 +447,7 @@ static void update_vttbr(struct kvm *kvm)
3269 kvm_call_hyp(__kvm_flush_vm_context);
3270 }
3271
3272- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3273+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3274 kvm->arch.vmid = kvm_next_vmid;
3275 kvm_next_vmid++;
3276
3277diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3278index 14a0d98..7771a7d 100644
3279--- a/arch/arm/lib/clear_user.S
3280+++ b/arch/arm/lib/clear_user.S
3281@@ -12,14 +12,14 @@
3282
3283 .text
3284
3285-/* Prototype: int __clear_user(void *addr, size_t sz)
3286+/* Prototype: int ___clear_user(void *addr, size_t sz)
3287 * Purpose : clear some user memory
3288 * Params : addr - user memory address to clear
3289 * : sz - number of bytes to clear
3290 * Returns : number of bytes NOT cleared
3291 */
3292 ENTRY(__clear_user_std)
3293-WEAK(__clear_user)
3294+WEAK(___clear_user)
3295 stmfd sp!, {r1, lr}
3296 mov r2, #0
3297 cmp r1, #4
3298@@ -44,7 +44,7 @@ WEAK(__clear_user)
3299 USER( strnebt r2, [r0])
3300 mov r0, #0
3301 ldmfd sp!, {r1, pc}
3302-ENDPROC(__clear_user)
3303+ENDPROC(___clear_user)
3304 ENDPROC(__clear_user_std)
3305
3306 .pushsection .fixup,"ax"
3307diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3308index 66a477a..bee61d3 100644
3309--- a/arch/arm/lib/copy_from_user.S
3310+++ b/arch/arm/lib/copy_from_user.S
3311@@ -16,7 +16,7 @@
3312 /*
3313 * Prototype:
3314 *
3315- * size_t __copy_from_user(void *to, const void *from, size_t n)
3316+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3317 *
3318 * Purpose:
3319 *
3320@@ -84,11 +84,11 @@
3321
3322 .text
3323
3324-ENTRY(__copy_from_user)
3325+ENTRY(___copy_from_user)
3326
3327 #include "copy_template.S"
3328
3329-ENDPROC(__copy_from_user)
3330+ENDPROC(___copy_from_user)
3331
3332 .pushsection .fixup,"ax"
3333 .align 0
3334diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3335index 6ee2f67..d1cce76 100644
3336--- a/arch/arm/lib/copy_page.S
3337+++ b/arch/arm/lib/copy_page.S
3338@@ -10,6 +10,7 @@
3339 * ASM optimised string functions
3340 */
3341 #include <linux/linkage.h>
3342+#include <linux/const.h>
3343 #include <asm/assembler.h>
3344 #include <asm/asm-offsets.h>
3345 #include <asm/cache.h>
3346diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3347index d066df6..df28194 100644
3348--- a/arch/arm/lib/copy_to_user.S
3349+++ b/arch/arm/lib/copy_to_user.S
3350@@ -16,7 +16,7 @@
3351 /*
3352 * Prototype:
3353 *
3354- * size_t __copy_to_user(void *to, const void *from, size_t n)
3355+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3356 *
3357 * Purpose:
3358 *
3359@@ -88,11 +88,11 @@
3360 .text
3361
3362 ENTRY(__copy_to_user_std)
3363-WEAK(__copy_to_user)
3364+WEAK(___copy_to_user)
3365
3366 #include "copy_template.S"
3367
3368-ENDPROC(__copy_to_user)
3369+ENDPROC(___copy_to_user)
3370 ENDPROC(__copy_to_user_std)
3371
3372 .pushsection .fixup,"ax"
3373diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3374index 7d08b43..f7ca7ea 100644
3375--- a/arch/arm/lib/csumpartialcopyuser.S
3376+++ b/arch/arm/lib/csumpartialcopyuser.S
3377@@ -57,8 +57,8 @@
3378 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3379 */
3380
3381-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3382-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3383+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3384+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3385
3386 #include "csumpartialcopygeneric.S"
3387
3388diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3389index 5306de3..aed6d03 100644
3390--- a/arch/arm/lib/delay.c
3391+++ b/arch/arm/lib/delay.c
3392@@ -28,7 +28,7 @@
3393 /*
3394 * Default to the loop-based delay implementation.
3395 */
3396-struct arm_delay_ops arm_delay_ops = {
3397+struct arm_delay_ops arm_delay_ops __read_only = {
3398 .delay = __loop_delay,
3399 .const_udelay = __loop_const_udelay,
3400 .udelay = __loop_udelay,
3401diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3402index 3e58d71..029817c 100644
3403--- a/arch/arm/lib/uaccess_with_memcpy.c
3404+++ b/arch/arm/lib/uaccess_with_memcpy.c
3405@@ -136,7 +136,7 @@ out:
3406 }
3407
3408 unsigned long
3409-__copy_to_user(void __user *to, const void *from, unsigned long n)
3410+___copy_to_user(void __user *to, const void *from, unsigned long n)
3411 {
3412 /*
3413 * This test is stubbed out of the main function above to keep
3414@@ -190,7 +190,7 @@ out:
3415 return n;
3416 }
3417
3418-unsigned long __clear_user(void __user *addr, unsigned long n)
3419+unsigned long ___clear_user(void __user *addr, unsigned long n)
3420 {
3421 /* See rational for this in __copy_to_user() above. */
3422 if (n < 64)
3423diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3424index f3407a5..bd4256f 100644
3425--- a/arch/arm/mach-kirkwood/common.c
3426+++ b/arch/arm/mach-kirkwood/common.c
3427@@ -156,7 +156,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3428 clk_gate_ops.disable(hw);
3429 }
3430
3431-static struct clk_ops clk_gate_fn_ops;
3432+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3433+{
3434+ return clk_gate_ops.is_enabled(hw);
3435+}
3436+
3437+static struct clk_ops clk_gate_fn_ops = {
3438+ .enable = clk_gate_fn_enable,
3439+ .disable = clk_gate_fn_disable,
3440+ .is_enabled = clk_gate_fn_is_enabled,
3441+};
3442
3443 static struct clk __init *clk_register_gate_fn(struct device *dev,
3444 const char *name,
3445@@ -190,14 +199,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3446 gate_fn->fn_en = fn_en;
3447 gate_fn->fn_dis = fn_dis;
3448
3449- /* ops is the gate ops, but with our enable/disable functions */
3450- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3451- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3452- clk_gate_fn_ops = clk_gate_ops;
3453- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3454- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3455- }
3456-
3457 clk = clk_register(dev, &gate_fn->gate.hw);
3458
3459 if (IS_ERR(clk))
3460diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3461index 827d1500..2885dc6 100644
3462--- a/arch/arm/mach-omap2/board-n8x0.c
3463+++ b/arch/arm/mach-omap2/board-n8x0.c
3464@@ -627,7 +627,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3465 }
3466 #endif
3467
3468-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3469+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3470 .late_init = n8x0_menelaus_late_init,
3471 };
3472
3473diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3474index ab43755..ccfa231 100644
3475--- a/arch/arm/mach-omap2/gpmc.c
3476+++ b/arch/arm/mach-omap2/gpmc.c
3477@@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3478 };
3479
3480 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3481-static struct irq_chip gpmc_irq_chip;
3482 static int gpmc_irq_start;
3483
3484 static struct resource gpmc_mem_root;
3485@@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3486
3487 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3488
3489+static struct irq_chip gpmc_irq_chip = {
3490+ .name = "gpmc",
3491+ .irq_startup = gpmc_irq_noop_ret,
3492+ .irq_enable = gpmc_irq_enable,
3493+ .irq_disable = gpmc_irq_disable,
3494+ .irq_shutdown = gpmc_irq_noop,
3495+ .irq_ack = gpmc_irq_noop,
3496+ .irq_mask = gpmc_irq_noop,
3497+ .irq_unmask = gpmc_irq_noop,
3498+
3499+};
3500+
3501 static int gpmc_setup_irq(void)
3502 {
3503 int i;
3504@@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3505 return gpmc_irq_start;
3506 }
3507
3508- gpmc_irq_chip.name = "gpmc";
3509- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3510- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3511- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3512- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3513- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3514- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3515- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3516-
3517 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3518 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3519
3520diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3521index f991016..145ebeb 100644
3522--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3523+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3524@@ -84,7 +84,7 @@ struct cpu_pm_ops {
3525 int (*finish_suspend)(unsigned long cpu_state);
3526 void (*resume)(void);
3527 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3528-};
3529+} __no_const;
3530
3531 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3532 static struct powerdomain *mpuss_pd;
3533@@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3534 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3535 {}
3536
3537-struct cpu_pm_ops omap_pm_ops = {
3538+static struct cpu_pm_ops omap_pm_ops __read_only = {
3539 .finish_suspend = default_finish_suspend,
3540 .resume = dummy_cpu_resume,
3541 .scu_prepare = dummy_scu_prepare,
3542diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3543index 3664562..72f85c6 100644
3544--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3545+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3546@@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3547 return NOTIFY_OK;
3548 }
3549
3550-static struct notifier_block __refdata irq_hotplug_notifier = {
3551+static struct notifier_block irq_hotplug_notifier = {
3552 .notifier_call = irq_cpu_hotplug_notify,
3553 };
3554
3555diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3556index e0a398c..a470fa5 100644
3557--- a/arch/arm/mach-omap2/omap_device.c
3558+++ b/arch/arm/mach-omap2/omap_device.c
3559@@ -508,7 +508,7 @@ void omap_device_delete(struct omap_device *od)
3560 struct platform_device __init *omap_device_build(const char *pdev_name,
3561 int pdev_id,
3562 struct omap_hwmod *oh,
3563- void *pdata, int pdata_len)
3564+ const void *pdata, int pdata_len)
3565 {
3566 struct omap_hwmod *ohs[] = { oh };
3567
3568@@ -536,7 +536,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3569 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3570 int pdev_id,
3571 struct omap_hwmod **ohs,
3572- int oh_cnt, void *pdata,
3573+ int oh_cnt, const void *pdata,
3574 int pdata_len)
3575 {
3576 int ret = -ENOMEM;
3577diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3578index 78c02b3..c94109a 100644
3579--- a/arch/arm/mach-omap2/omap_device.h
3580+++ b/arch/arm/mach-omap2/omap_device.h
3581@@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3582 /* Core code interface */
3583
3584 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3585- struct omap_hwmod *oh, void *pdata,
3586+ struct omap_hwmod *oh, const void *pdata,
3587 int pdata_len);
3588
3589 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3590 struct omap_hwmod **oh, int oh_cnt,
3591- void *pdata, int pdata_len);
3592+ const void *pdata, int pdata_len);
3593
3594 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3595 struct omap_hwmod **ohs, int oh_cnt);
3596diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3597index 8a1b5e0..5f30074 100644
3598--- a/arch/arm/mach-omap2/omap_hwmod.c
3599+++ b/arch/arm/mach-omap2/omap_hwmod.c
3600@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3601 int (*init_clkdm)(struct omap_hwmod *oh);
3602 void (*update_context_lost)(struct omap_hwmod *oh);
3603 int (*get_context_lost)(struct omap_hwmod *oh);
3604-};
3605+} __no_const;
3606
3607 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3608-static struct omap_hwmod_soc_ops soc_ops;
3609+static struct omap_hwmod_soc_ops soc_ops __read_only;
3610
3611 /* omap_hwmod_list contains all registered struct omap_hwmods */
3612 static LIST_HEAD(omap_hwmod_list);
3613diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3614index 95fee54..cfa9cf1 100644
3615--- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3616+++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3617@@ -10,6 +10,7 @@
3618
3619 #include <linux/kernel.h>
3620 #include <linux/init.h>
3621+#include <asm/pgtable.h>
3622
3623 #include "powerdomain.h"
3624
3625@@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3626
3627 void __init am43xx_powerdomains_init(void)
3628 {
3629- omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3630+ pax_open_kernel();
3631+ *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3632+ pax_close_kernel();
3633 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3634 pwrdm_register_pwrdms(powerdomains_am43xx);
3635 pwrdm_complete_init();
3636diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3637index d15c7bb..b2d1f0c 100644
3638--- a/arch/arm/mach-omap2/wd_timer.c
3639+++ b/arch/arm/mach-omap2/wd_timer.c
3640@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3641 struct omap_hwmod *oh;
3642 char *oh_name = "wd_timer2";
3643 char *dev_name = "omap_wdt";
3644- struct omap_wd_timer_platform_data pdata;
3645+ static struct omap_wd_timer_platform_data pdata = {
3646+ .read_reset_sources = prm_read_reset_sources
3647+ };
3648
3649 if (!cpu_class_is_omap2() || of_have_populated_dt())
3650 return 0;
3651@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3652 return -EINVAL;
3653 }
3654
3655- pdata.read_reset_sources = prm_read_reset_sources;
3656-
3657 pdev = omap_device_build(dev_name, id, oh, &pdata,
3658 sizeof(struct omap_wd_timer_platform_data));
3659 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3660diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3661index b82dcae..44ee5b6 100644
3662--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3663+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3664@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3665 bool entered_lp2 = false;
3666
3667 if (tegra_pending_sgi())
3668- ACCESS_ONCE(abort_flag) = true;
3669+ ACCESS_ONCE_RW(abort_flag) = true;
3670
3671 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3672
3673diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3674index bdb3564..cebb96f 100644
3675--- a/arch/arm/mach-ux500/setup.h
3676+++ b/arch/arm/mach-ux500/setup.h
3677@@ -39,13 +39,6 @@ extern void ux500_timer_init(void);
3678 .type = MT_DEVICE, \
3679 }
3680
3681-#define __MEM_DEV_DESC(x, sz) { \
3682- .virtual = IO_ADDRESS(x), \
3683- .pfn = __phys_to_pfn(x), \
3684- .length = sz, \
3685- .type = MT_MEMORY, \
3686-}
3687-
3688 extern struct smp_operations ux500_smp_ops;
3689 extern void ux500_cpu_die(unsigned int cpu);
3690
3691diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3692index 1f8fed9..14d7823 100644
3693--- a/arch/arm/mm/Kconfig
3694+++ b/arch/arm/mm/Kconfig
3695@@ -446,7 +446,7 @@ config CPU_32v5
3696
3697 config CPU_32v6
3698 bool
3699- select CPU_USE_DOMAINS if CPU_V6 && MMU
3700+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3701 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3702
3703 config CPU_32v6K
3704@@ -601,6 +601,7 @@ config CPU_CP15_MPU
3705
3706 config CPU_USE_DOMAINS
3707 bool
3708+ depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3709 help
3710 This option enables or disables the use of domain switching
3711 via the set_fs() function.
3712@@ -800,6 +801,7 @@ config NEED_KUSER_HELPERS
3713 config KUSER_HELPERS
3714 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3715 default y
3716+ depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3717 help
3718 Warning: disabling this option may break user programs.
3719
3720@@ -812,7 +814,7 @@ config KUSER_HELPERS
3721 See Documentation/arm/kernel_user_helpers.txt for details.
3722
3723 However, the fixed address nature of these helpers can be used
3724- by ROP (return orientated programming) authors when creating
3725+ by ROP (Return Oriented Programming) authors when creating
3726 exploits.
3727
3728 If all of the binaries and libraries which run on your platform
3729diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3730index 9240364..a2b8cf3 100644
3731--- a/arch/arm/mm/alignment.c
3732+++ b/arch/arm/mm/alignment.c
3733@@ -212,10 +212,12 @@ union offset_union {
3734 #define __get16_unaligned_check(ins,val,addr) \
3735 do { \
3736 unsigned int err = 0, v, a = addr; \
3737+ pax_open_userland(); \
3738 __get8_unaligned_check(ins,v,a,err); \
3739 val = v << ((BE) ? 8 : 0); \
3740 __get8_unaligned_check(ins,v,a,err); \
3741 val |= v << ((BE) ? 0 : 8); \
3742+ pax_close_userland(); \
3743 if (err) \
3744 goto fault; \
3745 } while (0)
3746@@ -229,6 +231,7 @@ union offset_union {
3747 #define __get32_unaligned_check(ins,val,addr) \
3748 do { \
3749 unsigned int err = 0, v, a = addr; \
3750+ pax_open_userland(); \
3751 __get8_unaligned_check(ins,v,a,err); \
3752 val = v << ((BE) ? 24 : 0); \
3753 __get8_unaligned_check(ins,v,a,err); \
3754@@ -237,6 +240,7 @@ union offset_union {
3755 val |= v << ((BE) ? 8 : 16); \
3756 __get8_unaligned_check(ins,v,a,err); \
3757 val |= v << ((BE) ? 0 : 24); \
3758+ pax_close_userland(); \
3759 if (err) \
3760 goto fault; \
3761 } while (0)
3762@@ -250,6 +254,7 @@ union offset_union {
3763 #define __put16_unaligned_check(ins,val,addr) \
3764 do { \
3765 unsigned int err = 0, v = val, a = addr; \
3766+ pax_open_userland(); \
3767 __asm__( FIRST_BYTE_16 \
3768 ARM( "1: "ins" %1, [%2], #1\n" ) \
3769 THUMB( "1: "ins" %1, [%2]\n" ) \
3770@@ -269,6 +274,7 @@ union offset_union {
3771 " .popsection\n" \
3772 : "=r" (err), "=&r" (v), "=&r" (a) \
3773 : "0" (err), "1" (v), "2" (a)); \
3774+ pax_close_userland(); \
3775 if (err) \
3776 goto fault; \
3777 } while (0)
3778@@ -282,6 +288,7 @@ union offset_union {
3779 #define __put32_unaligned_check(ins,val,addr) \
3780 do { \
3781 unsigned int err = 0, v = val, a = addr; \
3782+ pax_open_userland(); \
3783 __asm__( FIRST_BYTE_32 \
3784 ARM( "1: "ins" %1, [%2], #1\n" ) \
3785 THUMB( "1: "ins" %1, [%2]\n" ) \
3786@@ -311,6 +318,7 @@ union offset_union {
3787 " .popsection\n" \
3788 : "=r" (err), "=&r" (v), "=&r" (a) \
3789 : "0" (err), "1" (v), "2" (a)); \
3790+ pax_close_userland(); \
3791 if (err) \
3792 goto fault; \
3793 } while (0)
3794diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3795index 447da6f..77a5057 100644
3796--- a/arch/arm/mm/cache-l2x0.c
3797+++ b/arch/arm/mm/cache-l2x0.c
3798@@ -45,7 +45,7 @@ struct l2x0_of_data {
3799 void (*setup)(const struct device_node *, u32 *, u32 *);
3800 void (*save)(void);
3801 struct outer_cache_fns outer_cache;
3802-};
3803+} __do_const;
3804
3805 static bool of_init = false;
3806
3807diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3808index 84e6f77..0b52f31 100644
3809--- a/arch/arm/mm/context.c
3810+++ b/arch/arm/mm/context.c
3811@@ -43,7 +43,7 @@
3812 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3813
3814 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3815-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3816+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3817 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3818
3819 static DEFINE_PER_CPU(atomic64_t, active_asids);
3820@@ -180,7 +180,7 @@ static int is_reserved_asid(u64 asid)
3821 static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3822 {
3823 u64 asid = atomic64_read(&mm->context.id);
3824- u64 generation = atomic64_read(&asid_generation);
3825+ u64 generation = atomic64_read_unchecked(&asid_generation);
3826
3827 if (asid != 0 && is_reserved_asid(asid)) {
3828 /*
3829@@ -198,7 +198,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3830 */
3831 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3832 if (asid == NUM_USER_ASIDS) {
3833- generation = atomic64_add_return(ASID_FIRST_VERSION,
3834+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3835 &asid_generation);
3836 flush_context(cpu);
3837 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3838@@ -227,14 +227,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3839 cpu_set_reserved_ttbr0();
3840
3841 asid = atomic64_read(&mm->context.id);
3842- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3843+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3844 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3845 goto switch_mm_fastpath;
3846
3847 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3848 /* Check that our ASID belongs to the current generation. */
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 asid = new_context(mm, cpu);
3853 atomic64_set(&mm->context.id, asid);
3854 }
3855diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3856index eb8830a..5360ce7 100644
3857--- a/arch/arm/mm/fault.c
3858+++ b/arch/arm/mm/fault.c
3859@@ -25,6 +25,7 @@
3860 #include <asm/system_misc.h>
3861 #include <asm/system_info.h>
3862 #include <asm/tlbflush.h>
3863+#include <asm/sections.h>
3864
3865 #include "fault.h"
3866
3867@@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3868 if (fixup_exception(regs))
3869 return;
3870
3871+#ifdef CONFIG_PAX_MEMORY_UDEREF
3872+ if (addr < TASK_SIZE) {
3873+ if (current->signal->curr_ip)
3874+ 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),
3875+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3876+ else
3877+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3878+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3879+ }
3880+#endif
3881+
3882+#ifdef CONFIG_PAX_KERNEXEC
3883+ if ((fsr & FSR_WRITE) &&
3884+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3885+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3886+ {
3887+ if (current->signal->curr_ip)
3888+ 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),
3889+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3890+ else
3891+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3892+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3893+ }
3894+#endif
3895+
3896 /*
3897 * No handler, we'll have to terminate things with extreme prejudice.
3898 */
3899@@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3900 }
3901 #endif
3902
3903+#ifdef CONFIG_PAX_PAGEEXEC
3904+ if (fsr & FSR_LNX_PF) {
3905+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3906+ do_group_exit(SIGKILL);
3907+ }
3908+#endif
3909+
3910 tsk->thread.address = addr;
3911 tsk->thread.error_code = fsr;
3912 tsk->thread.trap_no = 14;
3913@@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3914 }
3915 #endif /* CONFIG_MMU */
3916
3917+#ifdef CONFIG_PAX_PAGEEXEC
3918+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3919+{
3920+ long i;
3921+
3922+ printk(KERN_ERR "PAX: bytes at PC: ");
3923+ for (i = 0; i < 20; i++) {
3924+ unsigned char c;
3925+ if (get_user(c, (__force unsigned char __user *)pc+i))
3926+ printk(KERN_CONT "?? ");
3927+ else
3928+ printk(KERN_CONT "%02x ", c);
3929+ }
3930+ printk("\n");
3931+
3932+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3933+ for (i = -1; i < 20; i++) {
3934+ unsigned long c;
3935+ if (get_user(c, (__force unsigned long __user *)sp+i))
3936+ printk(KERN_CONT "???????? ");
3937+ else
3938+ printk(KERN_CONT "%08lx ", c);
3939+ }
3940+ printk("\n");
3941+}
3942+#endif
3943+
3944 /*
3945 * First Level Translation Fault Handler
3946 *
3947@@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3948 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3949 struct siginfo info;
3950
3951+#ifdef CONFIG_PAX_MEMORY_UDEREF
3952+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3953+ if (current->signal->curr_ip)
3954+ 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),
3955+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3956+ else
3957+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3958+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3959+ goto die;
3960+ }
3961+#endif
3962+
3963 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3964 return;
3965
3966+die:
3967 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3968 inf->name, fsr, addr);
3969
3970@@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3971 ifsr_info[nr].name = name;
3972 }
3973
3974+asmlinkage int sys_sigreturn(struct pt_regs *regs);
3975+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3976+
3977 asmlinkage void __exception
3978 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3979 {
3980 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3981 struct siginfo info;
3982+ unsigned long pc = instruction_pointer(regs);
3983+
3984+ if (user_mode(regs)) {
3985+ unsigned long sigpage = current->mm->context.sigpage;
3986+
3987+ if (sigpage <= pc && pc < sigpage + 7*4) {
3988+ if (pc < sigpage + 3*4)
3989+ sys_sigreturn(regs);
3990+ else
3991+ sys_rt_sigreturn(regs);
3992+ return;
3993+ }
3994+ if (pc == 0xffff0f60UL) {
3995+ /*
3996+ * PaX: __kuser_cmpxchg64 emulation
3997+ */
3998+ // TODO
3999+ //regs->ARM_pc = regs->ARM_lr;
4000+ //return;
4001+ }
4002+ if (pc == 0xffff0fa0UL) {
4003+ /*
4004+ * PaX: __kuser_memory_barrier emulation
4005+ */
4006+ // dmb(); implied by the exception
4007+ regs->ARM_pc = regs->ARM_lr;
4008+ return;
4009+ }
4010+ if (pc == 0xffff0fc0UL) {
4011+ /*
4012+ * PaX: __kuser_cmpxchg emulation
4013+ */
4014+ // TODO
4015+ //long new;
4016+ //int op;
4017+
4018+ //op = FUTEX_OP_SET << 28;
4019+ //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4020+ //regs->ARM_r0 = old != new;
4021+ //regs->ARM_pc = regs->ARM_lr;
4022+ //return;
4023+ }
4024+ if (pc == 0xffff0fe0UL) {
4025+ /*
4026+ * PaX: __kuser_get_tls emulation
4027+ */
4028+ regs->ARM_r0 = current_thread_info()->tp_value[0];
4029+ regs->ARM_pc = regs->ARM_lr;
4030+ return;
4031+ }
4032+ }
4033+
4034+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4035+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4036+ if (current->signal->curr_ip)
4037+ 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),
4038+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4039+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4040+ else
4041+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4042+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4043+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4044+ goto die;
4045+ }
4046+#endif
4047+
4048+#ifdef CONFIG_PAX_REFCOUNT
4049+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4050+ unsigned int bkpt;
4051+
4052+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4053+ current->thread.error_code = ifsr;
4054+ current->thread.trap_no = 0;
4055+ pax_report_refcount_overflow(regs);
4056+ fixup_exception(regs);
4057+ return;
4058+ }
4059+ }
4060+#endif
4061
4062 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4063 return;
4064
4065+die:
4066 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4067 inf->name, ifsr, addr);
4068
4069diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4070index cf08bdf..772656c 100644
4071--- a/arch/arm/mm/fault.h
4072+++ b/arch/arm/mm/fault.h
4073@@ -3,6 +3,7 @@
4074
4075 /*
4076 * Fault status register encodings. We steal bit 31 for our own purposes.
4077+ * Set when the FSR value is from an instruction fault.
4078 */
4079 #define FSR_LNX_PF (1 << 31)
4080 #define FSR_WRITE (1 << 11)
4081@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4082 }
4083 #endif
4084
4085+/* valid for LPAE and !LPAE */
4086+static inline int is_xn_fault(unsigned int fsr)
4087+{
4088+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4089+}
4090+
4091+static inline int is_domain_fault(unsigned int fsr)
4092+{
4093+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4094+}
4095+
4096 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4097 unsigned long search_exception_table(unsigned long addr);
4098
4099diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4100index ac1d883..5a7bb91 100644
4101--- a/arch/arm/mm/init.c
4102+++ b/arch/arm/mm/init.c
4103@@ -30,6 +30,8 @@
4104 #include <asm/setup.h>
4105 #include <asm/tlb.h>
4106 #include <asm/fixmap.h>
4107+#include <asm/system_info.h>
4108+#include <asm/cp15.h>
4109
4110 #include <asm/mach/arch.h>
4111 #include <asm/mach/map.h>
4112@@ -682,7 +684,46 @@ void free_initmem(void)
4113 {
4114 #ifdef CONFIG_HAVE_TCM
4115 extern char __tcm_start, __tcm_end;
4116+#endif
4117
4118+#ifdef CONFIG_PAX_KERNEXEC
4119+ unsigned long addr;
4120+ pgd_t *pgd;
4121+ pud_t *pud;
4122+ pmd_t *pmd;
4123+ int cpu_arch = cpu_architecture();
4124+ unsigned int cr = get_cr();
4125+
4126+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4127+ /* make pages tables, etc before .text NX */
4128+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4129+ pgd = pgd_offset_k(addr);
4130+ pud = pud_offset(pgd, addr);
4131+ pmd = pmd_offset(pud, addr);
4132+ __section_update(pmd, addr, PMD_SECT_XN);
4133+ }
4134+ /* make init NX */
4135+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4136+ pgd = pgd_offset_k(addr);
4137+ pud = pud_offset(pgd, addr);
4138+ pmd = pmd_offset(pud, addr);
4139+ __section_update(pmd, addr, PMD_SECT_XN);
4140+ }
4141+ /* make kernel code/rodata RX */
4142+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4143+ pgd = pgd_offset_k(addr);
4144+ pud = pud_offset(pgd, addr);
4145+ pmd = pmd_offset(pud, addr);
4146+#ifdef CONFIG_ARM_LPAE
4147+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4148+#else
4149+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4150+#endif
4151+ }
4152+ }
4153+#endif
4154+
4155+#ifdef CONFIG_HAVE_TCM
4156 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4157 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4158 #endif
4159diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4160index f123d6e..04bf569 100644
4161--- a/arch/arm/mm/ioremap.c
4162+++ b/arch/arm/mm/ioremap.c
4163@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4164 unsigned int mtype;
4165
4166 if (cached)
4167- mtype = MT_MEMORY;
4168+ mtype = MT_MEMORY_RX;
4169 else
4170- mtype = MT_MEMORY_NONCACHED;
4171+ mtype = MT_MEMORY_NONCACHED_RX;
4172
4173 return __arm_ioremap_caller(phys_addr, size, mtype,
4174 __builtin_return_address(0));
4175diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4176index 5e85ed3..b10a7ed 100644
4177--- a/arch/arm/mm/mmap.c
4178+++ b/arch/arm/mm/mmap.c
4179@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4180 struct vm_area_struct *vma;
4181 int do_align = 0;
4182 int aliasing = cache_is_vipt_aliasing();
4183+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4184 struct vm_unmapped_area_info info;
4185
4186 /*
4187@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4188 if (len > TASK_SIZE)
4189 return -ENOMEM;
4190
4191+#ifdef CONFIG_PAX_RANDMMAP
4192+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4193+#endif
4194+
4195 if (addr) {
4196 if (do_align)
4197 addr = COLOUR_ALIGN(addr, pgoff);
4198@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4199 addr = PAGE_ALIGN(addr);
4200
4201 vma = find_vma(mm, addr);
4202- if (TASK_SIZE - len >= addr &&
4203- (!vma || addr + len <= vma->vm_start))
4204+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4205 return addr;
4206 }
4207
4208@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4209 info.high_limit = TASK_SIZE;
4210 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4211 info.align_offset = pgoff << PAGE_SHIFT;
4212+ info.threadstack_offset = offset;
4213 return vm_unmapped_area(&info);
4214 }
4215
4216@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4217 unsigned long addr = addr0;
4218 int do_align = 0;
4219 int aliasing = cache_is_vipt_aliasing();
4220+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4221 struct vm_unmapped_area_info info;
4222
4223 /*
4224@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4225 return addr;
4226 }
4227
4228+#ifdef CONFIG_PAX_RANDMMAP
4229+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4230+#endif
4231+
4232 /* requesting a specific address */
4233 if (addr) {
4234 if (do_align)
4235@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4236 else
4237 addr = PAGE_ALIGN(addr);
4238 vma = find_vma(mm, addr);
4239- if (TASK_SIZE - len >= addr &&
4240- (!vma || addr + len <= vma->vm_start))
4241+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4242 return addr;
4243 }
4244
4245@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4246 info.high_limit = mm->mmap_base;
4247 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4248 info.align_offset = pgoff << PAGE_SHIFT;
4249+ info.threadstack_offset = offset;
4250 addr = vm_unmapped_area(&info);
4251
4252 /*
4253@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4254 {
4255 unsigned long random_factor = 0UL;
4256
4257+#ifdef CONFIG_PAX_RANDMMAP
4258+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4259+#endif
4260+
4261 /* 8 bits of randomness in 20 address space bits */
4262 if ((current->flags & PF_RANDOMIZE) &&
4263 !(current->personality & ADDR_NO_RANDOMIZE))
4264@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4265
4266 if (mmap_is_legacy()) {
4267 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4268+
4269+#ifdef CONFIG_PAX_RANDMMAP
4270+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4271+ mm->mmap_base += mm->delta_mmap;
4272+#endif
4273+
4274 mm->get_unmapped_area = arch_get_unmapped_area;
4275 } else {
4276 mm->mmap_base = mmap_base(random_factor);
4277+
4278+#ifdef CONFIG_PAX_RANDMMAP
4279+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4280+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4281+#endif
4282+
4283 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4284 }
4285 }
4286diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4287index 911d433..8580952 100644
4288--- a/arch/arm/mm/mmu.c
4289+++ b/arch/arm/mm/mmu.c
4290@@ -38,6 +38,22 @@
4291 #include "mm.h"
4292 #include "tcm.h"
4293
4294+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4295+void modify_domain(unsigned int dom, unsigned int type)
4296+{
4297+ struct thread_info *thread = current_thread_info();
4298+ unsigned int domain = thread->cpu_domain;
4299+ /*
4300+ * DOMAIN_MANAGER might be defined to some other value,
4301+ * use the arch-defined constant
4302+ */
4303+ domain &= ~domain_val(dom, 3);
4304+ thread->cpu_domain = domain | domain_val(dom, type);
4305+ set_domain(thread->cpu_domain);
4306+}
4307+EXPORT_SYMBOL(modify_domain);
4308+#endif
4309+
4310 /*
4311 * empty_zero_page is a special page that is used for
4312 * zero-initialized data and COW.
4313@@ -230,11 +246,19 @@ __setup("noalign", noalign_setup);
4314
4315 #endif /* ifdef CONFIG_CPU_CP15 / else */
4316
4317-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4318+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4319 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4320 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4321
4322-static struct mem_type mem_types[] = {
4323+#ifdef CONFIG_PAX_KERNEXEC
4324+#define L_PTE_KERNEXEC L_PTE_RDONLY
4325+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4326+#else
4327+#define L_PTE_KERNEXEC L_PTE_DIRTY
4328+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4329+#endif
4330+
4331+static struct mem_type mem_types[] __read_only = {
4332 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4333 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4334 L_PTE_SHARED,
4335@@ -266,16 +290,16 @@ static struct mem_type mem_types[] = {
4336 [MT_UNCACHED] = {
4337 .prot_pte = PROT_PTE_DEVICE,
4338 .prot_l1 = PMD_TYPE_TABLE,
4339- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4340+ .prot_sect = PROT_SECT_DEVICE,
4341 .domain = DOMAIN_IO,
4342 },
4343 [MT_CACHECLEAN] = {
4344- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4345+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4346 .domain = DOMAIN_KERNEL,
4347 },
4348 #ifndef CONFIG_ARM_LPAE
4349 [MT_MINICLEAN] = {
4350- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4351+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4352 .domain = DOMAIN_KERNEL,
4353 },
4354 #endif
4355@@ -283,36 +307,54 @@ static struct mem_type mem_types[] = {
4356 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4357 L_PTE_RDONLY,
4358 .prot_l1 = PMD_TYPE_TABLE,
4359- .domain = DOMAIN_USER,
4360+ .domain = DOMAIN_VECTORS,
4361 },
4362 [MT_HIGH_VECTORS] = {
4363 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4364 L_PTE_USER | L_PTE_RDONLY,
4365 .prot_l1 = PMD_TYPE_TABLE,
4366- .domain = DOMAIN_USER,
4367+ .domain = DOMAIN_VECTORS,
4368 },
4369- [MT_MEMORY] = {
4370+ [MT_MEMORY_RWX] = {
4371 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4372 .prot_l1 = PMD_TYPE_TABLE,
4373 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4374 .domain = DOMAIN_KERNEL,
4375 },
4376+ [MT_MEMORY_RW] = {
4377+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4378+ .prot_l1 = PMD_TYPE_TABLE,
4379+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4380+ .domain = DOMAIN_KERNEL,
4381+ },
4382+ [MT_MEMORY_RX] = {
4383+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4384+ .prot_l1 = PMD_TYPE_TABLE,
4385+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4386+ .domain = DOMAIN_KERNEL,
4387+ },
4388 [MT_ROM] = {
4389- .prot_sect = PMD_TYPE_SECT,
4390+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4391 .domain = DOMAIN_KERNEL,
4392 },
4393- [MT_MEMORY_NONCACHED] = {
4394+ [MT_MEMORY_NONCACHED_RW] = {
4395 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4396 L_PTE_MT_BUFFERABLE,
4397 .prot_l1 = PMD_TYPE_TABLE,
4398 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4399 .domain = DOMAIN_KERNEL,
4400 },
4401+ [MT_MEMORY_NONCACHED_RX] = {
4402+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4403+ L_PTE_MT_BUFFERABLE,
4404+ .prot_l1 = PMD_TYPE_TABLE,
4405+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4406+ .domain = DOMAIN_KERNEL,
4407+ },
4408 [MT_MEMORY_DTCM] = {
4409- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4410- L_PTE_XN,
4411+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4412 .prot_l1 = PMD_TYPE_TABLE,
4413- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4414+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4415 .domain = DOMAIN_KERNEL,
4416 },
4417 [MT_MEMORY_ITCM] = {
4418@@ -322,10 +364,10 @@ static struct mem_type mem_types[] = {
4419 },
4420 [MT_MEMORY_SO] = {
4421 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4422- L_PTE_MT_UNCACHED | L_PTE_XN,
4423+ L_PTE_MT_UNCACHED,
4424 .prot_l1 = PMD_TYPE_TABLE,
4425 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4426- PMD_SECT_UNCACHED | PMD_SECT_XN,
4427+ PMD_SECT_UNCACHED,
4428 .domain = DOMAIN_KERNEL,
4429 },
4430 [MT_MEMORY_DMA_READY] = {
4431@@ -411,9 +453,35 @@ static void __init build_mem_type_table(void)
4432 * to prevent speculative instruction fetches.
4433 */
4434 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4435+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4436 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4437+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4438 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4439+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4440 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4441+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4442+
4443+ /* Mark other regions on ARMv6+ as execute-never */
4444+
4445+#ifdef CONFIG_PAX_KERNEXEC
4446+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4447+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4448+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4449+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4450+#ifndef CONFIG_ARM_LPAE
4451+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4452+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4453+#endif
4454+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4455+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4456+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4457+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4458+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4459+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4460+#endif
4461+
4462+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4463+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4464 }
4465 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4466 /*
4467@@ -475,6 +543,9 @@ static void __init build_mem_type_table(void)
4468 * from SVC mode and no access from userspace.
4469 */
4470 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4471+#ifdef CONFIG_PAX_KERNEXEC
4472+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4473+#endif
4474 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4475 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4476 #endif
4477@@ -492,11 +563,17 @@ static void __init build_mem_type_table(void)
4478 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4479 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4480 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4481- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4482- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4483+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4484+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4485+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4486+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4487+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4488+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4489 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4490- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4491- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4492+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4493+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4494+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4495+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4496 }
4497 }
4498
4499@@ -507,15 +584,20 @@ static void __init build_mem_type_table(void)
4500 if (cpu_arch >= CPU_ARCH_ARMv6) {
4501 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4502 /* Non-cacheable Normal is XCB = 001 */
4503- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4504+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4505+ PMD_SECT_BUFFERED;
4506+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4507 PMD_SECT_BUFFERED;
4508 } else {
4509 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4510- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4511+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4512+ PMD_SECT_TEX(1);
4513+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4514 PMD_SECT_TEX(1);
4515 }
4516 } else {
4517- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4518+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4519+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4520 }
4521
4522 #ifdef CONFIG_ARM_LPAE
4523@@ -531,6 +613,8 @@ static void __init build_mem_type_table(void)
4524 vecs_pgprot |= PTE_EXT_AF;
4525 #endif
4526
4527+ user_pgprot |= __supported_pte_mask;
4528+
4529 for (i = 0; i < 16; i++) {
4530 pteval_t v = pgprot_val(protection_map[i]);
4531 protection_map[i] = __pgprot(v | user_pgprot);
4532@@ -548,10 +632,15 @@ static void __init build_mem_type_table(void)
4533
4534 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4535 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4536- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4537- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4538+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4539+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4540+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4541+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4542+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4543+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4544 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4545- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4546+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4547+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4548 mem_types[MT_ROM].prot_sect |= cp->pmd;
4549
4550 switch (cp->pmd) {
4551@@ -1193,18 +1282,15 @@ void __init arm_mm_memblock_reserve(void)
4552 * called function. This means you can't use any function or debugging
4553 * method which may touch any device, otherwise the kernel _will_ crash.
4554 */
4555+
4556+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4557+
4558 static void __init devicemaps_init(const struct machine_desc *mdesc)
4559 {
4560 struct map_desc map;
4561 unsigned long addr;
4562- void *vectors;
4563
4564- /*
4565- * Allocate the vector page early.
4566- */
4567- vectors = early_alloc(PAGE_SIZE * 2);
4568-
4569- early_trap_init(vectors);
4570+ early_trap_init(&vectors);
4571
4572 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4573 pmd_clear(pmd_off_k(addr));
4574@@ -1244,7 +1330,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4575 * location (0xffff0000). If we aren't using high-vectors, also
4576 * create a mapping at the low-vectors virtual address.
4577 */
4578- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4579+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4580 map.virtual = 0xffff0000;
4581 map.length = PAGE_SIZE;
4582 #ifdef CONFIG_KUSER_HELPERS
4583@@ -1316,8 +1402,39 @@ static void __init map_lowmem(void)
4584 map.pfn = __phys_to_pfn(start);
4585 map.virtual = __phys_to_virt(start);
4586 map.length = end - start;
4587- map.type = MT_MEMORY;
4588
4589+#ifdef CONFIG_PAX_KERNEXEC
4590+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4591+ struct map_desc kernel;
4592+ struct map_desc initmap;
4593+
4594+ /* when freeing initmem we will make this RW */
4595+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4596+ initmap.virtual = (unsigned long)__init_begin;
4597+ initmap.length = _sdata - __init_begin;
4598+ initmap.type = MT_MEMORY_RWX;
4599+ create_mapping(&initmap);
4600+
4601+ /* when freeing initmem we will make this RX */
4602+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4603+ kernel.virtual = (unsigned long)_stext;
4604+ kernel.length = __init_begin - _stext;
4605+ kernel.type = MT_MEMORY_RWX;
4606+ create_mapping(&kernel);
4607+
4608+ if (map.virtual < (unsigned long)_stext) {
4609+ map.length = (unsigned long)_stext - map.virtual;
4610+ map.type = MT_MEMORY_RWX;
4611+ create_mapping(&map);
4612+ }
4613+
4614+ map.pfn = __phys_to_pfn(__pa(_sdata));
4615+ map.virtual = (unsigned long)_sdata;
4616+ map.length = end - __pa(_sdata);
4617+ }
4618+#endif
4619+
4620+ map.type = MT_MEMORY_RW;
4621 create_mapping(&map);
4622 }
4623 }
4624diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4625index a5bc92d..0bb4730 100644
4626--- a/arch/arm/plat-omap/sram.c
4627+++ b/arch/arm/plat-omap/sram.c
4628@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4629 * Looks like we need to preserve some bootloader code at the
4630 * beginning of SRAM for jumping to flash for reboot to work...
4631 */
4632+ pax_open_kernel();
4633 memset_io(omap_sram_base + omap_sram_skip, 0,
4634 omap_sram_size - omap_sram_skip);
4635+ pax_close_kernel();
4636 }
4637diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4638index ce6d763..cfea917 100644
4639--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4640+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4641@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4642 int (*started)(unsigned ch);
4643 int (*flush)(unsigned ch);
4644 int (*stop)(unsigned ch);
4645-};
4646+} __no_const;
4647
4648 extern void *samsung_dmadev_get_ops(void);
4649 extern void *s3c_dma_get_ops(void);
4650diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4651index 7ecc2b2..5e56c66 100644
4652--- a/arch/arm64/include/asm/uaccess.h
4653+++ b/arch/arm64/include/asm/uaccess.h
4654@@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4655 flag; \
4656 })
4657
4658+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4659 #define access_ok(type, addr, size) __range_ok(addr, size)
4660
4661 /*
4662diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4663index c3a58a1..78fbf54 100644
4664--- a/arch/avr32/include/asm/cache.h
4665+++ b/arch/avr32/include/asm/cache.h
4666@@ -1,8 +1,10 @@
4667 #ifndef __ASM_AVR32_CACHE_H
4668 #define __ASM_AVR32_CACHE_H
4669
4670+#include <linux/const.h>
4671+
4672 #define L1_CACHE_SHIFT 5
4673-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4674+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4675
4676 /*
4677 * Memory returned by kmalloc() may be used for DMA, so we must make
4678diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4679index d232888..87c8df1 100644
4680--- a/arch/avr32/include/asm/elf.h
4681+++ b/arch/avr32/include/asm/elf.h
4682@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4683 the loader. We need to make sure that it is out of the way of the program
4684 that it will "exec", and that there is sufficient room for the brk. */
4685
4686-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4687+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4688
4689+#ifdef CONFIG_PAX_ASLR
4690+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4691+
4692+#define PAX_DELTA_MMAP_LEN 15
4693+#define PAX_DELTA_STACK_LEN 15
4694+#endif
4695
4696 /* This yields a mask that user programs can use to figure out what
4697 instruction set this CPU supports. This could be done in user space,
4698diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4699index 479330b..53717a8 100644
4700--- a/arch/avr32/include/asm/kmap_types.h
4701+++ b/arch/avr32/include/asm/kmap_types.h
4702@@ -2,9 +2,9 @@
4703 #define __ASM_AVR32_KMAP_TYPES_H
4704
4705 #ifdef CONFIG_DEBUG_HIGHMEM
4706-# define KM_TYPE_NR 29
4707+# define KM_TYPE_NR 30
4708 #else
4709-# define KM_TYPE_NR 14
4710+# define KM_TYPE_NR 15
4711 #endif
4712
4713 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4714diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4715index 0eca933..eb78c7b 100644
4716--- a/arch/avr32/mm/fault.c
4717+++ b/arch/avr32/mm/fault.c
4718@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4719
4720 int exception_trace = 1;
4721
4722+#ifdef CONFIG_PAX_PAGEEXEC
4723+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4724+{
4725+ unsigned long i;
4726+
4727+ printk(KERN_ERR "PAX: bytes at PC: ");
4728+ for (i = 0; i < 20; i++) {
4729+ unsigned char c;
4730+ if (get_user(c, (unsigned char *)pc+i))
4731+ printk(KERN_CONT "???????? ");
4732+ else
4733+ printk(KERN_CONT "%02x ", c);
4734+ }
4735+ printk("\n");
4736+}
4737+#endif
4738+
4739 /*
4740 * This routine handles page faults. It determines the address and the
4741 * problem, and then passes it off to one of the appropriate routines.
4742@@ -176,6 +193,16 @@ bad_area:
4743 up_read(&mm->mmap_sem);
4744
4745 if (user_mode(regs)) {
4746+
4747+#ifdef CONFIG_PAX_PAGEEXEC
4748+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4749+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4750+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4751+ do_group_exit(SIGKILL);
4752+ }
4753+ }
4754+#endif
4755+
4756 if (exception_trace && printk_ratelimit())
4757 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4758 "sp %08lx ecr %lu\n",
4759diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4760index 568885a..f8008df 100644
4761--- a/arch/blackfin/include/asm/cache.h
4762+++ b/arch/blackfin/include/asm/cache.h
4763@@ -7,6 +7,7 @@
4764 #ifndef __ARCH_BLACKFIN_CACHE_H
4765 #define __ARCH_BLACKFIN_CACHE_H
4766
4767+#include <linux/const.h>
4768 #include <linux/linkage.h> /* for asmlinkage */
4769
4770 /*
4771@@ -14,7 +15,7 @@
4772 * Blackfin loads 32 bytes for cache
4773 */
4774 #define L1_CACHE_SHIFT 5
4775-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4776+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4777 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4778
4779 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4780diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4781index aea2718..3639a60 100644
4782--- a/arch/cris/include/arch-v10/arch/cache.h
4783+++ b/arch/cris/include/arch-v10/arch/cache.h
4784@@ -1,8 +1,9 @@
4785 #ifndef _ASM_ARCH_CACHE_H
4786 #define _ASM_ARCH_CACHE_H
4787
4788+#include <linux/const.h>
4789 /* Etrax 100LX have 32-byte cache-lines. */
4790-#define L1_CACHE_BYTES 32
4791 #define L1_CACHE_SHIFT 5
4792+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4793
4794 #endif /* _ASM_ARCH_CACHE_H */
4795diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4796index 7caf25d..ee65ac5 100644
4797--- a/arch/cris/include/arch-v32/arch/cache.h
4798+++ b/arch/cris/include/arch-v32/arch/cache.h
4799@@ -1,11 +1,12 @@
4800 #ifndef _ASM_CRIS_ARCH_CACHE_H
4801 #define _ASM_CRIS_ARCH_CACHE_H
4802
4803+#include <linux/const.h>
4804 #include <arch/hwregs/dma.h>
4805
4806 /* A cache-line is 32 bytes. */
4807-#define L1_CACHE_BYTES 32
4808 #define L1_CACHE_SHIFT 5
4809+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4810
4811 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4812
4813diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4814index b86329d..6709906 100644
4815--- a/arch/frv/include/asm/atomic.h
4816+++ b/arch/frv/include/asm/atomic.h
4817@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4818 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4819 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4820
4821+#define atomic64_read_unchecked(v) atomic64_read(v)
4822+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4823+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4824+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4825+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4826+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4827+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4828+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4829+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4830+
4831 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4832 {
4833 int c, old;
4834diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4835index 2797163..c2a401d 100644
4836--- a/arch/frv/include/asm/cache.h
4837+++ b/arch/frv/include/asm/cache.h
4838@@ -12,10 +12,11 @@
4839 #ifndef __ASM_CACHE_H
4840 #define __ASM_CACHE_H
4841
4842+#include <linux/const.h>
4843
4844 /* bytes per L1 cache line */
4845 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4846-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4847+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4848
4849 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4850 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4851diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4852index 43901f2..0d8b865 100644
4853--- a/arch/frv/include/asm/kmap_types.h
4854+++ b/arch/frv/include/asm/kmap_types.h
4855@@ -2,6 +2,6 @@
4856 #ifndef _ASM_KMAP_TYPES_H
4857 #define _ASM_KMAP_TYPES_H
4858
4859-#define KM_TYPE_NR 17
4860+#define KM_TYPE_NR 18
4861
4862 #endif
4863diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4864index 836f147..4cf23f5 100644
4865--- a/arch/frv/mm/elf-fdpic.c
4866+++ b/arch/frv/mm/elf-fdpic.c
4867@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4868 {
4869 struct vm_area_struct *vma;
4870 struct vm_unmapped_area_info info;
4871+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4872
4873 if (len > TASK_SIZE)
4874 return -ENOMEM;
4875@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4876 if (addr) {
4877 addr = PAGE_ALIGN(addr);
4878 vma = find_vma(current->mm, addr);
4879- if (TASK_SIZE - len >= addr &&
4880- (!vma || addr + len <= vma->vm_start))
4881+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4882 goto success;
4883 }
4884
4885@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4886 info.high_limit = (current->mm->start_stack - 0x00200000);
4887 info.align_mask = 0;
4888 info.align_offset = 0;
4889+ info.threadstack_offset = offset;
4890 addr = vm_unmapped_area(&info);
4891 if (!(addr & ~PAGE_MASK))
4892 goto success;
4893diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4894index f4ca594..adc72fd6 100644
4895--- a/arch/hexagon/include/asm/cache.h
4896+++ b/arch/hexagon/include/asm/cache.h
4897@@ -21,9 +21,11 @@
4898 #ifndef __ASM_CACHE_H
4899 #define __ASM_CACHE_H
4900
4901+#include <linux/const.h>
4902+
4903 /* Bytes per L1 cache line */
4904-#define L1_CACHE_SHIFT (5)
4905-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4906+#define L1_CACHE_SHIFT 5
4907+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4908
4909 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4910 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4911diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
4912index 4e4119b..dd7de0a 100644
4913--- a/arch/ia64/Kconfig
4914+++ b/arch/ia64/Kconfig
4915@@ -554,6 +554,7 @@ source "drivers/sn/Kconfig"
4916 config KEXEC
4917 bool "kexec system call"
4918 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
4919+ depends on !GRKERNSEC_KMEM
4920 help
4921 kexec is a system call that implements the ability to shutdown your
4922 current kernel, and to start another kernel. It is like a reboot
4923diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4924index 6e6fe18..a6ae668 100644
4925--- a/arch/ia64/include/asm/atomic.h
4926+++ b/arch/ia64/include/asm/atomic.h
4927@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4928 #define atomic64_inc(v) atomic64_add(1, (v))
4929 #define atomic64_dec(v) atomic64_sub(1, (v))
4930
4931+#define atomic64_read_unchecked(v) atomic64_read(v)
4932+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4933+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4934+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4935+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4936+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4937+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4938+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4939+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4940+
4941 /* Atomic operations are already serializing */
4942 #define smp_mb__before_atomic_dec() barrier()
4943 #define smp_mb__after_atomic_dec() barrier()
4944diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4945index 988254a..e1ee885 100644
4946--- a/arch/ia64/include/asm/cache.h
4947+++ b/arch/ia64/include/asm/cache.h
4948@@ -1,6 +1,7 @@
4949 #ifndef _ASM_IA64_CACHE_H
4950 #define _ASM_IA64_CACHE_H
4951
4952+#include <linux/const.h>
4953
4954 /*
4955 * Copyright (C) 1998-2000 Hewlett-Packard Co
4956@@ -9,7 +10,7 @@
4957
4958 /* Bytes per L1 (data) cache line. */
4959 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4960-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4961+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4962
4963 #ifdef CONFIG_SMP
4964 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4965diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4966index 5a83c5c..4d7f553 100644
4967--- a/arch/ia64/include/asm/elf.h
4968+++ b/arch/ia64/include/asm/elf.h
4969@@ -42,6 +42,13 @@
4970 */
4971 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4972
4973+#ifdef CONFIG_PAX_ASLR
4974+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4975+
4976+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4977+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4978+#endif
4979+
4980 #define PT_IA_64_UNWIND 0x70000001
4981
4982 /* IA-64 relocations: */
4983diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4984index 5767cdf..7462574 100644
4985--- a/arch/ia64/include/asm/pgalloc.h
4986+++ b/arch/ia64/include/asm/pgalloc.h
4987@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4988 pgd_val(*pgd_entry) = __pa(pud);
4989 }
4990
4991+static inline void
4992+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4993+{
4994+ pgd_populate(mm, pgd_entry, pud);
4995+}
4996+
4997 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4998 {
4999 return quicklist_alloc(0, GFP_KERNEL, NULL);
5000@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5001 pud_val(*pud_entry) = __pa(pmd);
5002 }
5003
5004+static inline void
5005+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5006+{
5007+ pud_populate(mm, pud_entry, pmd);
5008+}
5009+
5010 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5011 {
5012 return quicklist_alloc(0, GFP_KERNEL, NULL);
5013diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5014index 7935115..c0eca6a 100644
5015--- a/arch/ia64/include/asm/pgtable.h
5016+++ b/arch/ia64/include/asm/pgtable.h
5017@@ -12,7 +12,7 @@
5018 * David Mosberger-Tang <davidm@hpl.hp.com>
5019 */
5020
5021-
5022+#include <linux/const.h>
5023 #include <asm/mman.h>
5024 #include <asm/page.h>
5025 #include <asm/processor.h>
5026@@ -142,6 +142,17 @@
5027 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5028 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5029 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5030+
5031+#ifdef CONFIG_PAX_PAGEEXEC
5032+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5033+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5034+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5035+#else
5036+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5037+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5038+# define PAGE_COPY_NOEXEC PAGE_COPY
5039+#endif
5040+
5041 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5042 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5043 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5044diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5045index 45698cd..e8e2dbc 100644
5046--- a/arch/ia64/include/asm/spinlock.h
5047+++ b/arch/ia64/include/asm/spinlock.h
5048@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5049 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5050
5051 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5052- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5053+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5054 }
5055
5056 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5057diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5058index 449c8c0..3d4b1e9 100644
5059--- a/arch/ia64/include/asm/uaccess.h
5060+++ b/arch/ia64/include/asm/uaccess.h
5061@@ -70,6 +70,7 @@
5062 && ((segment).seg == KERNEL_DS.seg \
5063 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5064 })
5065+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5066 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5067
5068 /*
5069@@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5070 static inline unsigned long
5071 __copy_to_user (void __user *to, const void *from, unsigned long count)
5072 {
5073+ if (count > INT_MAX)
5074+ return count;
5075+
5076+ if (!__builtin_constant_p(count))
5077+ check_object_size(from, count, true);
5078+
5079 return __copy_user(to, (__force void __user *) from, count);
5080 }
5081
5082 static inline unsigned long
5083 __copy_from_user (void *to, const void __user *from, unsigned long count)
5084 {
5085+ if (count > INT_MAX)
5086+ return count;
5087+
5088+ if (!__builtin_constant_p(count))
5089+ check_object_size(to, count, false);
5090+
5091 return __copy_user((__force void __user *) to, from, count);
5092 }
5093
5094@@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5095 ({ \
5096 void __user *__cu_to = (to); \
5097 const void *__cu_from = (from); \
5098- long __cu_len = (n); \
5099+ unsigned long __cu_len = (n); \
5100 \
5101- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5102+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5103+ if (!__builtin_constant_p(n)) \
5104+ check_object_size(__cu_from, __cu_len, true); \
5105 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5106+ } \
5107 __cu_len; \
5108 })
5109
5110@@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5111 ({ \
5112 void *__cu_to = (to); \
5113 const void __user *__cu_from = (from); \
5114- long __cu_len = (n); \
5115+ unsigned long __cu_len = (n); \
5116 \
5117 __chk_user_ptr(__cu_from); \
5118- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5119+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5120+ if (!__builtin_constant_p(n)) \
5121+ check_object_size(__cu_to, __cu_len, false); \
5122 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5123+ } \
5124 __cu_len; \
5125 })
5126
5127diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5128index 24603be..948052d 100644
5129--- a/arch/ia64/kernel/module.c
5130+++ b/arch/ia64/kernel/module.c
5131@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5132 void
5133 module_free (struct module *mod, void *module_region)
5134 {
5135- if (mod && mod->arch.init_unw_table &&
5136- module_region == mod->module_init) {
5137+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5138 unw_remove_unwind_table(mod->arch.init_unw_table);
5139 mod->arch.init_unw_table = NULL;
5140 }
5141@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5142 }
5143
5144 static inline int
5145+in_init_rx (const struct module *mod, uint64_t addr)
5146+{
5147+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5148+}
5149+
5150+static inline int
5151+in_init_rw (const struct module *mod, uint64_t addr)
5152+{
5153+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5154+}
5155+
5156+static inline int
5157 in_init (const struct module *mod, uint64_t addr)
5158 {
5159- return addr - (uint64_t) mod->module_init < mod->init_size;
5160+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5161+}
5162+
5163+static inline int
5164+in_core_rx (const struct module *mod, uint64_t addr)
5165+{
5166+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5167+}
5168+
5169+static inline int
5170+in_core_rw (const struct module *mod, uint64_t addr)
5171+{
5172+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5173 }
5174
5175 static inline int
5176 in_core (const struct module *mod, uint64_t addr)
5177 {
5178- return addr - (uint64_t) mod->module_core < mod->core_size;
5179+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5180 }
5181
5182 static inline int
5183@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5184 break;
5185
5186 case RV_BDREL:
5187- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5188+ if (in_init_rx(mod, val))
5189+ val -= (uint64_t) mod->module_init_rx;
5190+ else if (in_init_rw(mod, val))
5191+ val -= (uint64_t) mod->module_init_rw;
5192+ else if (in_core_rx(mod, val))
5193+ val -= (uint64_t) mod->module_core_rx;
5194+ else if (in_core_rw(mod, val))
5195+ val -= (uint64_t) mod->module_core_rw;
5196 break;
5197
5198 case RV_LTV:
5199@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5200 * addresses have been selected...
5201 */
5202 uint64_t gp;
5203- if (mod->core_size > MAX_LTOFF)
5204+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5205 /*
5206 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5207 * at the end of the module.
5208 */
5209- gp = mod->core_size - MAX_LTOFF / 2;
5210+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5211 else
5212- gp = mod->core_size / 2;
5213- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5214+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5215+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5216 mod->arch.gp = gp;
5217 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5218 }
5219diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5220index ab33328..f39506c 100644
5221--- a/arch/ia64/kernel/palinfo.c
5222+++ b/arch/ia64/kernel/palinfo.c
5223@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5224 return NOTIFY_OK;
5225 }
5226
5227-static struct notifier_block __refdata palinfo_cpu_notifier =
5228+static struct notifier_block palinfo_cpu_notifier =
5229 {
5230 .notifier_call = palinfo_cpu_callback,
5231 .priority = 0,
5232diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5233index 41e33f8..65180b2a 100644
5234--- a/arch/ia64/kernel/sys_ia64.c
5235+++ b/arch/ia64/kernel/sys_ia64.c
5236@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5237 unsigned long align_mask = 0;
5238 struct mm_struct *mm = current->mm;
5239 struct vm_unmapped_area_info info;
5240+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5241
5242 if (len > RGN_MAP_LIMIT)
5243 return -ENOMEM;
5244@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5245 if (REGION_NUMBER(addr) == RGN_HPAGE)
5246 addr = 0;
5247 #endif
5248+
5249+#ifdef CONFIG_PAX_RANDMMAP
5250+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5251+ addr = mm->free_area_cache;
5252+ else
5253+#endif
5254+
5255 if (!addr)
5256 addr = TASK_UNMAPPED_BASE;
5257
5258@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5259 info.high_limit = TASK_SIZE;
5260 info.align_mask = align_mask;
5261 info.align_offset = 0;
5262+ info.threadstack_offset = offset;
5263 return vm_unmapped_area(&info);
5264 }
5265
5266diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5267index 0ccb28f..8992469 100644
5268--- a/arch/ia64/kernel/vmlinux.lds.S
5269+++ b/arch/ia64/kernel/vmlinux.lds.S
5270@@ -198,7 +198,7 @@ SECTIONS {
5271 /* Per-cpu data: */
5272 . = ALIGN(PERCPU_PAGE_SIZE);
5273 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5274- __phys_per_cpu_start = __per_cpu_load;
5275+ __phys_per_cpu_start = per_cpu_load;
5276 /*
5277 * ensure percpu data fits
5278 * into percpu page size
5279diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5280index 7225dad..2a7c8256 100644
5281--- a/arch/ia64/mm/fault.c
5282+++ b/arch/ia64/mm/fault.c
5283@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5284 return pte_present(pte);
5285 }
5286
5287+#ifdef CONFIG_PAX_PAGEEXEC
5288+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5289+{
5290+ unsigned long i;
5291+
5292+ printk(KERN_ERR "PAX: bytes at PC: ");
5293+ for (i = 0; i < 8; i++) {
5294+ unsigned int c;
5295+ if (get_user(c, (unsigned int *)pc+i))
5296+ printk(KERN_CONT "???????? ");
5297+ else
5298+ printk(KERN_CONT "%08x ", c);
5299+ }
5300+ printk("\n");
5301+}
5302+#endif
5303+
5304 # define VM_READ_BIT 0
5305 # define VM_WRITE_BIT 1
5306 # define VM_EXEC_BIT 2
5307@@ -151,8 +168,21 @@ retry:
5308 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5309 goto bad_area;
5310
5311- if ((vma->vm_flags & mask) != mask)
5312+ if ((vma->vm_flags & mask) != mask) {
5313+
5314+#ifdef CONFIG_PAX_PAGEEXEC
5315+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5316+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5317+ goto bad_area;
5318+
5319+ up_read(&mm->mmap_sem);
5320+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5321+ do_group_exit(SIGKILL);
5322+ }
5323+#endif
5324+
5325 goto bad_area;
5326+ }
5327
5328 /*
5329 * If for any reason at all we couldn't handle the fault, make
5330diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5331index 68232db..6ca80af 100644
5332--- a/arch/ia64/mm/hugetlbpage.c
5333+++ b/arch/ia64/mm/hugetlbpage.c
5334@@ -154,6 +154,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5335 unsigned long pgoff, unsigned long flags)
5336 {
5337 struct vm_unmapped_area_info info;
5338+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5339
5340 if (len > RGN_MAP_LIMIT)
5341 return -ENOMEM;
5342@@ -177,6 +178,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5343 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5344 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5345 info.align_offset = 0;
5346+ info.threadstack_offset = offset;
5347 return vm_unmapped_area(&info);
5348 }
5349
5350diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5351index 88504ab..cbb6c9f 100644
5352--- a/arch/ia64/mm/init.c
5353+++ b/arch/ia64/mm/init.c
5354@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5355 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5356 vma->vm_end = vma->vm_start + PAGE_SIZE;
5357 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5358+
5359+#ifdef CONFIG_PAX_PAGEEXEC
5360+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5361+ vma->vm_flags &= ~VM_EXEC;
5362+
5363+#ifdef CONFIG_PAX_MPROTECT
5364+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5365+ vma->vm_flags &= ~VM_MAYEXEC;
5366+#endif
5367+
5368+ }
5369+#endif
5370+
5371 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5372 down_write(&current->mm->mmap_sem);
5373 if (insert_vm_struct(current->mm, vma)) {
5374diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5375index 40b3ee9..8c2c112 100644
5376--- a/arch/m32r/include/asm/cache.h
5377+++ b/arch/m32r/include/asm/cache.h
5378@@ -1,8 +1,10 @@
5379 #ifndef _ASM_M32R_CACHE_H
5380 #define _ASM_M32R_CACHE_H
5381
5382+#include <linux/const.h>
5383+
5384 /* L1 cache line size */
5385 #define L1_CACHE_SHIFT 4
5386-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5387+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5388
5389 #endif /* _ASM_M32R_CACHE_H */
5390diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5391index 82abd15..d95ae5d 100644
5392--- a/arch/m32r/lib/usercopy.c
5393+++ b/arch/m32r/lib/usercopy.c
5394@@ -14,6 +14,9 @@
5395 unsigned long
5396 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5397 {
5398+ if ((long)n < 0)
5399+ return n;
5400+
5401 prefetch(from);
5402 if (access_ok(VERIFY_WRITE, to, n))
5403 __copy_user(to,from,n);
5404@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5405 unsigned long
5406 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5407 {
5408+ if ((long)n < 0)
5409+ return n;
5410+
5411 prefetchw(to);
5412 if (access_ok(VERIFY_READ, from, n))
5413 __copy_user_zeroing(to,from,n);
5414diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5415index 0395c51..5f26031 100644
5416--- a/arch/m68k/include/asm/cache.h
5417+++ b/arch/m68k/include/asm/cache.h
5418@@ -4,9 +4,11 @@
5419 #ifndef __ARCH_M68K_CACHE_H
5420 #define __ARCH_M68K_CACHE_H
5421
5422+#include <linux/const.h>
5423+
5424 /* bytes per L1 cache line */
5425 #define L1_CACHE_SHIFT 4
5426-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5427+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5428
5429 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5430
5431diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5432index 0424315..defcca9 100644
5433--- a/arch/metag/mm/hugetlbpage.c
5434+++ b/arch/metag/mm/hugetlbpage.c
5435@@ -205,6 +205,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5436 info.high_limit = TASK_SIZE;
5437 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5438 info.align_offset = 0;
5439+ info.threadstack_offset = 0;
5440 return vm_unmapped_area(&info);
5441 }
5442
5443diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5444index 4efe96a..60e8699 100644
5445--- a/arch/microblaze/include/asm/cache.h
5446+++ b/arch/microblaze/include/asm/cache.h
5447@@ -13,11 +13,12 @@
5448 #ifndef _ASM_MICROBLAZE_CACHE_H
5449 #define _ASM_MICROBLAZE_CACHE_H
5450
5451+#include <linux/const.h>
5452 #include <asm/registers.h>
5453
5454 #define L1_CACHE_SHIFT 5
5455 /* word-granular cache in microblaze */
5456-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5457+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5458
5459 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5460
5461diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5462index 650de39..6982b02 100644
5463--- a/arch/mips/Kconfig
5464+++ b/arch/mips/Kconfig
5465@@ -2268,6 +2268,7 @@ source "kernel/Kconfig.preempt"
5466
5467 config KEXEC
5468 bool "Kexec system call"
5469+ depends on !GRKERNSEC_KMEM
5470 help
5471 kexec is a system call that implements the ability to shutdown your
5472 current kernel, and to start another kernel. It is like a reboot
5473diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5474index 02f2444..506969c 100644
5475--- a/arch/mips/cavium-octeon/dma-octeon.c
5476+++ b/arch/mips/cavium-octeon/dma-octeon.c
5477@@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5478 if (dma_release_from_coherent(dev, order, vaddr))
5479 return;
5480
5481- swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5482+ swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5483 }
5484
5485 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5486diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5487index 7eed2f2..c4e385d 100644
5488--- a/arch/mips/include/asm/atomic.h
5489+++ b/arch/mips/include/asm/atomic.h
5490@@ -21,15 +21,39 @@
5491 #include <asm/cmpxchg.h>
5492 #include <asm/war.h>
5493
5494+#ifdef CONFIG_GENERIC_ATOMIC64
5495+#include <asm-generic/atomic64.h>
5496+#endif
5497+
5498 #define ATOMIC_INIT(i) { (i) }
5499
5500+#ifdef CONFIG_64BIT
5501+#define _ASM_EXTABLE(from, to) \
5502+" .section __ex_table,\"a\"\n" \
5503+" .dword " #from ", " #to"\n" \
5504+" .previous\n"
5505+#else
5506+#define _ASM_EXTABLE(from, to) \
5507+" .section __ex_table,\"a\"\n" \
5508+" .word " #from ", " #to"\n" \
5509+" .previous\n"
5510+#endif
5511+
5512 /*
5513 * atomic_read - read atomic variable
5514 * @v: pointer of type atomic_t
5515 *
5516 * Atomically reads the value of @v.
5517 */
5518-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5519+static inline int atomic_read(const atomic_t *v)
5520+{
5521+ return (*(volatile const int *) &v->counter);
5522+}
5523+
5524+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5525+{
5526+ return (*(volatile const int *) &v->counter);
5527+}
5528
5529 /*
5530 * atomic_set - set atomic variable
5531@@ -38,7 +62,15 @@
5532 *
5533 * Atomically sets the value of @v to @i.
5534 */
5535-#define atomic_set(v, i) ((v)->counter = (i))
5536+static inline void atomic_set(atomic_t *v, int i)
5537+{
5538+ v->counter = i;
5539+}
5540+
5541+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5542+{
5543+ v->counter = i;
5544+}
5545
5546 /*
5547 * atomic_add - add integer to atomic variable
5548@@ -47,7 +79,67 @@
5549 *
5550 * Atomically adds @i to @v.
5551 */
5552-static __inline__ void atomic_add(int i, atomic_t * v)
5553+static __inline__ void atomic_add(int i, atomic_t *v)
5554+{
5555+ int temp;
5556+
5557+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5558+ __asm__ __volatile__(
5559+ " .set mips3 \n"
5560+ "1: ll %0, %1 # atomic_add \n"
5561+#ifdef CONFIG_PAX_REFCOUNT
5562+ /* Exception on overflow. */
5563+ "2: add %0, %2 \n"
5564+#else
5565+ " addu %0, %2 \n"
5566+#endif
5567+ " sc %0, %1 \n"
5568+ " beqzl %0, 1b \n"
5569+#ifdef CONFIG_PAX_REFCOUNT
5570+ "3: \n"
5571+ _ASM_EXTABLE(2b, 3b)
5572+#endif
5573+ " .set mips0 \n"
5574+ : "=&r" (temp), "+m" (v->counter)
5575+ : "Ir" (i));
5576+ } else if (kernel_uses_llsc) {
5577+ __asm__ __volatile__(
5578+ " .set mips3 \n"
5579+ "1: ll %0, %1 # atomic_add \n"
5580+#ifdef CONFIG_PAX_REFCOUNT
5581+ /* Exception on overflow. */
5582+ "2: add %0, %2 \n"
5583+#else
5584+ " addu %0, %2 \n"
5585+#endif
5586+ " sc %0, %1 \n"
5587+ " beqz %0, 1b \n"
5588+#ifdef CONFIG_PAX_REFCOUNT
5589+ "3: \n"
5590+ _ASM_EXTABLE(2b, 3b)
5591+#endif
5592+ " .set mips0 \n"
5593+ : "=&r" (temp), "+m" (v->counter)
5594+ : "Ir" (i));
5595+ } else {
5596+ unsigned long flags;
5597+
5598+ raw_local_irq_save(flags);
5599+ __asm__ __volatile__(
5600+#ifdef CONFIG_PAX_REFCOUNT
5601+ /* Exception on overflow. */
5602+ "1: add %0, %1 \n"
5603+ "2: \n"
5604+ _ASM_EXTABLE(1b, 2b)
5605+#else
5606+ " addu %0, %1 \n"
5607+#endif
5608+ : "+r" (v->counter) : "Ir" (i));
5609+ raw_local_irq_restore(flags);
5610+ }
5611+}
5612+
5613+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5614 {
5615 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5616 int temp;
5617@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5618 *
5619 * Atomically subtracts @i from @v.
5620 */
5621-static __inline__ void atomic_sub(int i, atomic_t * v)
5622+static __inline__ void atomic_sub(int i, atomic_t *v)
5623+{
5624+ int temp;
5625+
5626+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5627+ __asm__ __volatile__(
5628+ " .set mips3 \n"
5629+ "1: ll %0, %1 # atomic64_sub \n"
5630+#ifdef CONFIG_PAX_REFCOUNT
5631+ /* Exception on overflow. */
5632+ "2: sub %0, %2 \n"
5633+#else
5634+ " subu %0, %2 \n"
5635+#endif
5636+ " sc %0, %1 \n"
5637+ " beqzl %0, 1b \n"
5638+#ifdef CONFIG_PAX_REFCOUNT
5639+ "3: \n"
5640+ _ASM_EXTABLE(2b, 3b)
5641+#endif
5642+ " .set mips0 \n"
5643+ : "=&r" (temp), "+m" (v->counter)
5644+ : "Ir" (i));
5645+ } else if (kernel_uses_llsc) {
5646+ __asm__ __volatile__(
5647+ " .set mips3 \n"
5648+ "1: ll %0, %1 # atomic64_sub \n"
5649+#ifdef CONFIG_PAX_REFCOUNT
5650+ /* Exception on overflow. */
5651+ "2: sub %0, %2 \n"
5652+#else
5653+ " subu %0, %2 \n"
5654+#endif
5655+ " sc %0, %1 \n"
5656+ " beqz %0, 1b \n"
5657+#ifdef CONFIG_PAX_REFCOUNT
5658+ "3: \n"
5659+ _ASM_EXTABLE(2b, 3b)
5660+#endif
5661+ " .set mips0 \n"
5662+ : "=&r" (temp), "+m" (v->counter)
5663+ : "Ir" (i));
5664+ } else {
5665+ unsigned long flags;
5666+
5667+ raw_local_irq_save(flags);
5668+ __asm__ __volatile__(
5669+#ifdef CONFIG_PAX_REFCOUNT
5670+ /* Exception on overflow. */
5671+ "1: sub %0, %1 \n"
5672+ "2: \n"
5673+ _ASM_EXTABLE(1b, 2b)
5674+#else
5675+ " subu %0, %1 \n"
5676+#endif
5677+ : "+r" (v->counter) : "Ir" (i));
5678+ raw_local_irq_restore(flags);
5679+ }
5680+}
5681+
5682+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5683 {
5684 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5685 int temp;
5686@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5687 /*
5688 * Same as above, but return the result value
5689 */
5690-static __inline__ int atomic_add_return(int i, atomic_t * v)
5691+static __inline__ int atomic_add_return(int i, atomic_t *v)
5692+{
5693+ int result;
5694+ int temp;
5695+
5696+ smp_mb__before_llsc();
5697+
5698+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5699+ __asm__ __volatile__(
5700+ " .set mips3 \n"
5701+ "1: ll %1, %2 # atomic_add_return \n"
5702+#ifdef CONFIG_PAX_REFCOUNT
5703+ "2: add %0, %1, %3 \n"
5704+#else
5705+ " addu %0, %1, %3 \n"
5706+#endif
5707+ " sc %0, %2 \n"
5708+ " beqzl %0, 1b \n"
5709+#ifdef CONFIG_PAX_REFCOUNT
5710+ " b 4f \n"
5711+ " .set noreorder \n"
5712+ "3: b 5f \n"
5713+ " move %0, %1 \n"
5714+ " .set reorder \n"
5715+ _ASM_EXTABLE(2b, 3b)
5716+#endif
5717+ "4: addu %0, %1, %3 \n"
5718+#ifdef CONFIG_PAX_REFCOUNT
5719+ "5: \n"
5720+#endif
5721+ " .set mips0 \n"
5722+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5723+ : "Ir" (i));
5724+ } else if (kernel_uses_llsc) {
5725+ __asm__ __volatile__(
5726+ " .set mips3 \n"
5727+ "1: ll %1, %2 # atomic_add_return \n"
5728+#ifdef CONFIG_PAX_REFCOUNT
5729+ "2: add %0, %1, %3 \n"
5730+#else
5731+ " addu %0, %1, %3 \n"
5732+#endif
5733+ " sc %0, %2 \n"
5734+ " bnez %0, 4f \n"
5735+ " b 1b \n"
5736+#ifdef CONFIG_PAX_REFCOUNT
5737+ " .set noreorder \n"
5738+ "3: b 5f \n"
5739+ " move %0, %1 \n"
5740+ " .set reorder \n"
5741+ _ASM_EXTABLE(2b, 3b)
5742+#endif
5743+ "4: addu %0, %1, %3 \n"
5744+#ifdef CONFIG_PAX_REFCOUNT
5745+ "5: \n"
5746+#endif
5747+ " .set mips0 \n"
5748+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5749+ : "Ir" (i));
5750+ } else {
5751+ unsigned long flags;
5752+
5753+ raw_local_irq_save(flags);
5754+ __asm__ __volatile__(
5755+ " lw %0, %1 \n"
5756+#ifdef CONFIG_PAX_REFCOUNT
5757+ /* Exception on overflow. */
5758+ "1: add %0, %2 \n"
5759+#else
5760+ " addu %0, %2 \n"
5761+#endif
5762+ " sw %0, %1 \n"
5763+#ifdef CONFIG_PAX_REFCOUNT
5764+ /* Note: Dest reg is not modified on overflow */
5765+ "2: \n"
5766+ _ASM_EXTABLE(1b, 2b)
5767+#endif
5768+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5769+ raw_local_irq_restore(flags);
5770+ }
5771+
5772+ smp_llsc_mb();
5773+
5774+ return result;
5775+}
5776+
5777+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5778 {
5779 int result;
5780
5781@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5782 return result;
5783 }
5784
5785-static __inline__ int atomic_sub_return(int i, atomic_t * v)
5786+static __inline__ int atomic_sub_return(int i, atomic_t *v)
5787+{
5788+ int result;
5789+ int temp;
5790+
5791+ smp_mb__before_llsc();
5792+
5793+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5794+ __asm__ __volatile__(
5795+ " .set mips3 \n"
5796+ "1: ll %1, %2 # atomic_sub_return \n"
5797+#ifdef CONFIG_PAX_REFCOUNT
5798+ "2: sub %0, %1, %3 \n"
5799+#else
5800+ " subu %0, %1, %3 \n"
5801+#endif
5802+ " sc %0, %2 \n"
5803+ " beqzl %0, 1b \n"
5804+#ifdef CONFIG_PAX_REFCOUNT
5805+ " b 4f \n"
5806+ " .set noreorder \n"
5807+ "3: b 5f \n"
5808+ " move %0, %1 \n"
5809+ " .set reorder \n"
5810+ _ASM_EXTABLE(2b, 3b)
5811+#endif
5812+ "4: subu %0, %1, %3 \n"
5813+#ifdef CONFIG_PAX_REFCOUNT
5814+ "5: \n"
5815+#endif
5816+ " .set mips0 \n"
5817+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5818+ : "Ir" (i), "m" (v->counter)
5819+ : "memory");
5820+ } else if (kernel_uses_llsc) {
5821+ __asm__ __volatile__(
5822+ " .set mips3 \n"
5823+ "1: ll %1, %2 # atomic_sub_return \n"
5824+#ifdef CONFIG_PAX_REFCOUNT
5825+ "2: sub %0, %1, %3 \n"
5826+#else
5827+ " subu %0, %1, %3 \n"
5828+#endif
5829+ " sc %0, %2 \n"
5830+ " bnez %0, 4f \n"
5831+ " b 1b \n"
5832+#ifdef CONFIG_PAX_REFCOUNT
5833+ " .set noreorder \n"
5834+ "3: b 5f \n"
5835+ " move %0, %1 \n"
5836+ " .set reorder \n"
5837+ _ASM_EXTABLE(2b, 3b)
5838+#endif
5839+ "4: subu %0, %1, %3 \n"
5840+#ifdef CONFIG_PAX_REFCOUNT
5841+ "5: \n"
5842+#endif
5843+ " .set mips0 \n"
5844+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5845+ : "Ir" (i));
5846+ } else {
5847+ unsigned long flags;
5848+
5849+ raw_local_irq_save(flags);
5850+ __asm__ __volatile__(
5851+ " lw %0, %1 \n"
5852+#ifdef CONFIG_PAX_REFCOUNT
5853+ /* Exception on overflow. */
5854+ "1: sub %0, %2 \n"
5855+#else
5856+ " subu %0, %2 \n"
5857+#endif
5858+ " sw %0, %1 \n"
5859+#ifdef CONFIG_PAX_REFCOUNT
5860+ /* Note: Dest reg is not modified on overflow */
5861+ "2: \n"
5862+ _ASM_EXTABLE(1b, 2b)
5863+#endif
5864+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5865+ raw_local_irq_restore(flags);
5866+ }
5867+
5868+ smp_llsc_mb();
5869+
5870+ return result;
5871+}
5872+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5873 {
5874 int result;
5875
5876@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5877 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5878 * The function returns the old value of @v minus @i.
5879 */
5880-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5881+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5882 {
5883 int result;
5884
5885@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5886 return result;
5887 }
5888
5889-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5890-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5891+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5892+{
5893+ return cmpxchg(&v->counter, old, new);
5894+}
5895+
5896+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5897+ int new)
5898+{
5899+ return cmpxchg(&(v->counter), old, new);
5900+}
5901+
5902+static inline int atomic_xchg(atomic_t *v, int new)
5903+{
5904+ return xchg(&v->counter, new);
5905+}
5906+
5907+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5908+{
5909+ return xchg(&(v->counter), new);
5910+}
5911
5912 /**
5913 * __atomic_add_unless - add unless the number is a given value
5914@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5915
5916 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5917 #define atomic_inc_return(v) atomic_add_return(1, (v))
5918+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5919+{
5920+ return atomic_add_return_unchecked(1, v);
5921+}
5922
5923 /*
5924 * atomic_sub_and_test - subtract value from variable and test result
5925@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5926 * other cases.
5927 */
5928 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5929+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5930+{
5931+ return atomic_add_return_unchecked(1, v) == 0;
5932+}
5933
5934 /*
5935 * atomic_dec_and_test - decrement by 1 and test
5936@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5937 * Atomically increments @v by 1.
5938 */
5939 #define atomic_inc(v) atomic_add(1, (v))
5940+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
5941+{
5942+ atomic_add_unchecked(1, v);
5943+}
5944
5945 /*
5946 * atomic_dec - decrement and test
5947@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5948 * Atomically decrements @v by 1.
5949 */
5950 #define atomic_dec(v) atomic_sub(1, (v))
5951+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
5952+{
5953+ atomic_sub_unchecked(1, v);
5954+}
5955
5956 /*
5957 * atomic_add_negative - add and test if negative
5958@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5959 * @v: pointer of type atomic64_t
5960 *
5961 */
5962-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
5963+static inline long atomic64_read(const atomic64_t *v)
5964+{
5965+ return (*(volatile const long *) &v->counter);
5966+}
5967+
5968+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5969+{
5970+ return (*(volatile const long *) &v->counter);
5971+}
5972
5973 /*
5974 * atomic64_set - set atomic variable
5975 * @v: pointer of type atomic64_t
5976 * @i: required value
5977 */
5978-#define atomic64_set(v, i) ((v)->counter = (i))
5979+static inline void atomic64_set(atomic64_t *v, long i)
5980+{
5981+ v->counter = i;
5982+}
5983+
5984+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5985+{
5986+ v->counter = i;
5987+}
5988
5989 /*
5990 * atomic64_add - add integer to atomic variable
5991@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5992 *
5993 * Atomically adds @i to @v.
5994 */
5995-static __inline__ void atomic64_add(long i, atomic64_t * v)
5996+static __inline__ void atomic64_add(long i, atomic64_t *v)
5997+{
5998+ long temp;
5999+
6000+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6001+ __asm__ __volatile__(
6002+ " .set mips3 \n"
6003+ "1: lld %0, %1 # atomic64_add \n"
6004+#ifdef CONFIG_PAX_REFCOUNT
6005+ /* Exception on overflow. */
6006+ "2: dadd %0, %2 \n"
6007+#else
6008+ " daddu %0, %2 \n"
6009+#endif
6010+ " scd %0, %1 \n"
6011+ " beqzl %0, 1b \n"
6012+#ifdef CONFIG_PAX_REFCOUNT
6013+ "3: \n"
6014+ _ASM_EXTABLE(2b, 3b)
6015+#endif
6016+ " .set mips0 \n"
6017+ : "=&r" (temp), "+m" (v->counter)
6018+ : "Ir" (i));
6019+ } else if (kernel_uses_llsc) {
6020+ __asm__ __volatile__(
6021+ " .set mips3 \n"
6022+ "1: lld %0, %1 # atomic64_add \n"
6023+#ifdef CONFIG_PAX_REFCOUNT
6024+ /* Exception on overflow. */
6025+ "2: dadd %0, %2 \n"
6026+#else
6027+ " daddu %0, %2 \n"
6028+#endif
6029+ " scd %0, %1 \n"
6030+ " beqz %0, 1b \n"
6031+#ifdef CONFIG_PAX_REFCOUNT
6032+ "3: \n"
6033+ _ASM_EXTABLE(2b, 3b)
6034+#endif
6035+ " .set mips0 \n"
6036+ : "=&r" (temp), "+m" (v->counter)
6037+ : "Ir" (i));
6038+ } else {
6039+ unsigned long flags;
6040+
6041+ raw_local_irq_save(flags);
6042+ __asm__ __volatile__(
6043+#ifdef CONFIG_PAX_REFCOUNT
6044+ /* Exception on overflow. */
6045+ "1: dadd %0, %1 \n"
6046+ "2: \n"
6047+ _ASM_EXTABLE(1b, 2b)
6048+#else
6049+ " daddu %0, %1 \n"
6050+#endif
6051+ : "+r" (v->counter) : "Ir" (i));
6052+ raw_local_irq_restore(flags);
6053+ }
6054+}
6055+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6056 {
6057 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6058 long temp;
6059@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6060 *
6061 * Atomically subtracts @i from @v.
6062 */
6063-static __inline__ void atomic64_sub(long i, atomic64_t * v)
6064+static __inline__ void atomic64_sub(long i, atomic64_t *v)
6065+{
6066+ long temp;
6067+
6068+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6069+ __asm__ __volatile__(
6070+ " .set mips3 \n"
6071+ "1: lld %0, %1 # atomic64_sub \n"
6072+#ifdef CONFIG_PAX_REFCOUNT
6073+ /* Exception on overflow. */
6074+ "2: dsub %0, %2 \n"
6075+#else
6076+ " dsubu %0, %2 \n"
6077+#endif
6078+ " scd %0, %1 \n"
6079+ " beqzl %0, 1b \n"
6080+#ifdef CONFIG_PAX_REFCOUNT
6081+ "3: \n"
6082+ _ASM_EXTABLE(2b, 3b)
6083+#endif
6084+ " .set mips0 \n"
6085+ : "=&r" (temp), "+m" (v->counter)
6086+ : "Ir" (i));
6087+ } else if (kernel_uses_llsc) {
6088+ __asm__ __volatile__(
6089+ " .set mips3 \n"
6090+ "1: lld %0, %1 # atomic64_sub \n"
6091+#ifdef CONFIG_PAX_REFCOUNT
6092+ /* Exception on overflow. */
6093+ "2: dsub %0, %2 \n"
6094+#else
6095+ " dsubu %0, %2 \n"
6096+#endif
6097+ " scd %0, %1 \n"
6098+ " beqz %0, 1b \n"
6099+#ifdef CONFIG_PAX_REFCOUNT
6100+ "3: \n"
6101+ _ASM_EXTABLE(2b, 3b)
6102+#endif
6103+ " .set mips0 \n"
6104+ : "=&r" (temp), "+m" (v->counter)
6105+ : "Ir" (i));
6106+ } else {
6107+ unsigned long flags;
6108+
6109+ raw_local_irq_save(flags);
6110+ __asm__ __volatile__(
6111+#ifdef CONFIG_PAX_REFCOUNT
6112+ /* Exception on overflow. */
6113+ "1: dsub %0, %1 \n"
6114+ "2: \n"
6115+ _ASM_EXTABLE(1b, 2b)
6116+#else
6117+ " dsubu %0, %1 \n"
6118+#endif
6119+ : "+r" (v->counter) : "Ir" (i));
6120+ raw_local_irq_restore(flags);
6121+ }
6122+}
6123+
6124+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6125 {
6126 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6127 long temp;
6128@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6129 /*
6130 * Same as above, but return the result value
6131 */
6132-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6133+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6134+{
6135+ long result;
6136+ long temp;
6137+
6138+ smp_mb__before_llsc();
6139+
6140+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6141+ __asm__ __volatile__(
6142+ " .set mips3 \n"
6143+ "1: lld %1, %2 # atomic64_add_return \n"
6144+#ifdef CONFIG_PAX_REFCOUNT
6145+ "2: dadd %0, %1, %3 \n"
6146+#else
6147+ " daddu %0, %1, %3 \n"
6148+#endif
6149+ " scd %0, %2 \n"
6150+ " beqzl %0, 1b \n"
6151+#ifdef CONFIG_PAX_REFCOUNT
6152+ " b 4f \n"
6153+ " .set noreorder \n"
6154+ "3: b 5f \n"
6155+ " move %0, %1 \n"
6156+ " .set reorder \n"
6157+ _ASM_EXTABLE(2b, 3b)
6158+#endif
6159+ "4: daddu %0, %1, %3 \n"
6160+#ifdef CONFIG_PAX_REFCOUNT
6161+ "5: \n"
6162+#endif
6163+ " .set mips0 \n"
6164+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6165+ : "Ir" (i));
6166+ } else if (kernel_uses_llsc) {
6167+ __asm__ __volatile__(
6168+ " .set mips3 \n"
6169+ "1: lld %1, %2 # atomic64_add_return \n"
6170+#ifdef CONFIG_PAX_REFCOUNT
6171+ "2: dadd %0, %1, %3 \n"
6172+#else
6173+ " daddu %0, %1, %3 \n"
6174+#endif
6175+ " scd %0, %2 \n"
6176+ " bnez %0, 4f \n"
6177+ " b 1b \n"
6178+#ifdef CONFIG_PAX_REFCOUNT
6179+ " .set noreorder \n"
6180+ "3: b 5f \n"
6181+ " move %0, %1 \n"
6182+ " .set reorder \n"
6183+ _ASM_EXTABLE(2b, 3b)
6184+#endif
6185+ "4: daddu %0, %1, %3 \n"
6186+#ifdef CONFIG_PAX_REFCOUNT
6187+ "5: \n"
6188+#endif
6189+ " .set mips0 \n"
6190+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6191+ : "Ir" (i), "m" (v->counter)
6192+ : "memory");
6193+ } else {
6194+ unsigned long flags;
6195+
6196+ raw_local_irq_save(flags);
6197+ __asm__ __volatile__(
6198+ " ld %0, %1 \n"
6199+#ifdef CONFIG_PAX_REFCOUNT
6200+ /* Exception on overflow. */
6201+ "1: dadd %0, %2 \n"
6202+#else
6203+ " daddu %0, %2 \n"
6204+#endif
6205+ " sd %0, %1 \n"
6206+#ifdef CONFIG_PAX_REFCOUNT
6207+ /* Note: Dest reg is not modified on overflow */
6208+ "2: \n"
6209+ _ASM_EXTABLE(1b, 2b)
6210+#endif
6211+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6212+ raw_local_irq_restore(flags);
6213+ }
6214+
6215+ smp_llsc_mb();
6216+
6217+ return result;
6218+}
6219+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6220 {
6221 long result;
6222
6223@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6224 return result;
6225 }
6226
6227-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6228+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6229+{
6230+ long result;
6231+ long temp;
6232+
6233+ smp_mb__before_llsc();
6234+
6235+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6236+ long temp;
6237+
6238+ __asm__ __volatile__(
6239+ " .set mips3 \n"
6240+ "1: lld %1, %2 # atomic64_sub_return \n"
6241+#ifdef CONFIG_PAX_REFCOUNT
6242+ "2: dsub %0, %1, %3 \n"
6243+#else
6244+ " dsubu %0, %1, %3 \n"
6245+#endif
6246+ " scd %0, %2 \n"
6247+ " beqzl %0, 1b \n"
6248+#ifdef CONFIG_PAX_REFCOUNT
6249+ " b 4f \n"
6250+ " .set noreorder \n"
6251+ "3: b 5f \n"
6252+ " move %0, %1 \n"
6253+ " .set reorder \n"
6254+ _ASM_EXTABLE(2b, 3b)
6255+#endif
6256+ "4: dsubu %0, %1, %3 \n"
6257+#ifdef CONFIG_PAX_REFCOUNT
6258+ "5: \n"
6259+#endif
6260+ " .set mips0 \n"
6261+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6262+ : "Ir" (i), "m" (v->counter)
6263+ : "memory");
6264+ } else if (kernel_uses_llsc) {
6265+ __asm__ __volatile__(
6266+ " .set mips3 \n"
6267+ "1: lld %1, %2 # atomic64_sub_return \n"
6268+#ifdef CONFIG_PAX_REFCOUNT
6269+ "2: dsub %0, %1, %3 \n"
6270+#else
6271+ " dsubu %0, %1, %3 \n"
6272+#endif
6273+ " scd %0, %2 \n"
6274+ " bnez %0, 4f \n"
6275+ " b 1b \n"
6276+#ifdef CONFIG_PAX_REFCOUNT
6277+ " .set noreorder \n"
6278+ "3: b 5f \n"
6279+ " move %0, %1 \n"
6280+ " .set reorder \n"
6281+ _ASM_EXTABLE(2b, 3b)
6282+#endif
6283+ "4: dsubu %0, %1, %3 \n"
6284+#ifdef CONFIG_PAX_REFCOUNT
6285+ "5: \n"
6286+#endif
6287+ " .set mips0 \n"
6288+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6289+ : "Ir" (i), "m" (v->counter)
6290+ : "memory");
6291+ } else {
6292+ unsigned long flags;
6293+
6294+ raw_local_irq_save(flags);
6295+ __asm__ __volatile__(
6296+ " ld %0, %1 \n"
6297+#ifdef CONFIG_PAX_REFCOUNT
6298+ /* Exception on overflow. */
6299+ "1: dsub %0, %2 \n"
6300+#else
6301+ " dsubu %0, %2 \n"
6302+#endif
6303+ " sd %0, %1 \n"
6304+#ifdef CONFIG_PAX_REFCOUNT
6305+ /* Note: Dest reg is not modified on overflow */
6306+ "2: \n"
6307+ _ASM_EXTABLE(1b, 2b)
6308+#endif
6309+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6310+ raw_local_irq_restore(flags);
6311+ }
6312+
6313+ smp_llsc_mb();
6314+
6315+ return result;
6316+}
6317+
6318+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6319 {
6320 long result;
6321
6322@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6323 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6324 * The function returns the old value of @v minus @i.
6325 */
6326-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6327+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6328 {
6329 long result;
6330
6331@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6332 return result;
6333 }
6334
6335-#define atomic64_cmpxchg(v, o, n) \
6336- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6337-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6338+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6339+{
6340+ return cmpxchg(&v->counter, old, new);
6341+}
6342+
6343+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6344+ long new)
6345+{
6346+ return cmpxchg(&(v->counter), old, new);
6347+}
6348+
6349+static inline long atomic64_xchg(atomic64_t *v, long new)
6350+{
6351+ return xchg(&v->counter, new);
6352+}
6353+
6354+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6355+{
6356+ return xchg(&(v->counter), new);
6357+}
6358
6359 /**
6360 * atomic64_add_unless - add unless the number is a given value
6361@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6362
6363 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6364 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6365+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6366
6367 /*
6368 * atomic64_sub_and_test - subtract value from variable and test result
6369@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6370 * other cases.
6371 */
6372 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6373+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6374
6375 /*
6376 * atomic64_dec_and_test - decrement by 1 and test
6377@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6378 * Atomically increments @v by 1.
6379 */
6380 #define atomic64_inc(v) atomic64_add(1, (v))
6381+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6382
6383 /*
6384 * atomic64_dec - decrement and test
6385@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6386 * Atomically decrements @v by 1.
6387 */
6388 #define atomic64_dec(v) atomic64_sub(1, (v))
6389+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6390
6391 /*
6392 * atomic64_add_negative - add and test if negative
6393diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6394index b4db69f..8f3b093 100644
6395--- a/arch/mips/include/asm/cache.h
6396+++ b/arch/mips/include/asm/cache.h
6397@@ -9,10 +9,11 @@
6398 #ifndef _ASM_CACHE_H
6399 #define _ASM_CACHE_H
6400
6401+#include <linux/const.h>
6402 #include <kmalloc.h>
6403
6404 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6405-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6406+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6407
6408 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6409 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6410diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6411index a66359e..d3d474a 100644
6412--- a/arch/mips/include/asm/elf.h
6413+++ b/arch/mips/include/asm/elf.h
6414@@ -373,13 +373,16 @@ extern const char *__elf_platform;
6415 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6416 #endif
6417
6418+#ifdef CONFIG_PAX_ASLR
6419+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6420+
6421+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6422+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6423+#endif
6424+
6425 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6426 struct linux_binprm;
6427 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6428 int uses_interp);
6429
6430-struct mm_struct;
6431-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6432-#define arch_randomize_brk arch_randomize_brk
6433-
6434 #endif /* _ASM_ELF_H */
6435diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6436index c1f6afa..38cc6e9 100644
6437--- a/arch/mips/include/asm/exec.h
6438+++ b/arch/mips/include/asm/exec.h
6439@@ -12,6 +12,6 @@
6440 #ifndef _ASM_EXEC_H
6441 #define _ASM_EXEC_H
6442
6443-extern unsigned long arch_align_stack(unsigned long sp);
6444+#define arch_align_stack(x) ((x) & ~0xfUL)
6445
6446 #endif /* _ASM_EXEC_H */
6447diff --git a/arch/mips/include/asm/ftrace.h b/arch/mips/include/asm/ftrace.h
6448index ce35c9a..434321c 100644
6449--- a/arch/mips/include/asm/ftrace.h
6450+++ b/arch/mips/include/asm/ftrace.h
6451@@ -22,12 +22,12 @@ extern void _mcount(void);
6452 #define safe_load(load, src, dst, error) \
6453 do { \
6454 asm volatile ( \
6455- "1: " load " %[" STR(dst) "], 0(%[" STR(src) "])\n"\
6456- " li %[" STR(error) "], 0\n" \
6457+ "1: " load " %[dest], 0(%[source])\n" \
6458+ " li %[err], 0\n" \
6459 "2:\n" \
6460 \
6461 ".section .fixup, \"ax\"\n" \
6462- "3: li %[" STR(error) "], 1\n" \
6463+ "3: li %[err], 1\n" \
6464 " j 2b\n" \
6465 ".previous\n" \
6466 \
6467@@ -35,8 +35,8 @@ do { \
6468 STR(PTR) "\t1b, 3b\n\t" \
6469 ".previous\n" \
6470 \
6471- : [dst] "=&r" (dst), [error] "=r" (error)\
6472- : [src] "r" (src) \
6473+ : [dest] "=&r" (dst), [err] "=r" (error)\
6474+ : [source] "r" (src) \
6475 : "memory" \
6476 ); \
6477 } while (0)
6478@@ -44,12 +44,12 @@ do { \
6479 #define safe_store(store, src, dst, error) \
6480 do { \
6481 asm volatile ( \
6482- "1: " store " %[" STR(src) "], 0(%[" STR(dst) "])\n"\
6483- " li %[" STR(error) "], 0\n" \
6484+ "1: " store " %[source], 0(%[dest])\n"\
6485+ " li %[err], 0\n" \
6486 "2:\n" \
6487 \
6488 ".section .fixup, \"ax\"\n" \
6489- "3: li %[" STR(error) "], 1\n" \
6490+ "3: li %[err], 1\n" \
6491 " j 2b\n" \
6492 ".previous\n" \
6493 \
6494@@ -57,8 +57,8 @@ do { \
6495 STR(PTR) "\t1b, 3b\n\t" \
6496 ".previous\n" \
6497 \
6498- : [error] "=r" (error) \
6499- : [dst] "r" (dst), [src] "r" (src)\
6500+ : [err] "=r" (error) \
6501+ : [dest] "r" (dst), [source] "r" (src)\
6502 : "memory" \
6503 ); \
6504 } while (0)
6505diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6506index 9e8ef59..1139d6b 100644
6507--- a/arch/mips/include/asm/hw_irq.h
6508+++ b/arch/mips/include/asm/hw_irq.h
6509@@ -10,7 +10,7 @@
6510
6511 #include <linux/atomic.h>
6512
6513-extern atomic_t irq_err_count;
6514+extern atomic_unchecked_t irq_err_count;
6515
6516 /*
6517 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6518diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6519index d44622c..64990d2 100644
6520--- a/arch/mips/include/asm/local.h
6521+++ b/arch/mips/include/asm/local.h
6522@@ -12,15 +12,25 @@ typedef struct
6523 atomic_long_t a;
6524 } local_t;
6525
6526+typedef struct {
6527+ atomic_long_unchecked_t a;
6528+} local_unchecked_t;
6529+
6530 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6531
6532 #define local_read(l) atomic_long_read(&(l)->a)
6533+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6534 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6535+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6536
6537 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6538+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6539 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6540+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6541 #define local_inc(l) atomic_long_inc(&(l)->a)
6542+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6543 #define local_dec(l) atomic_long_dec(&(l)->a)
6544+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6545
6546 /*
6547 * Same as above, but return the result value
6548@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6549 return result;
6550 }
6551
6552+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6553+{
6554+ unsigned long result;
6555+
6556+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6557+ unsigned long temp;
6558+
6559+ __asm__ __volatile__(
6560+ " .set mips3 \n"
6561+ "1:" __LL "%1, %2 # local_add_return \n"
6562+ " addu %0, %1, %3 \n"
6563+ __SC "%0, %2 \n"
6564+ " beqzl %0, 1b \n"
6565+ " addu %0, %1, %3 \n"
6566+ " .set mips0 \n"
6567+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6568+ : "Ir" (i), "m" (l->a.counter)
6569+ : "memory");
6570+ } else if (kernel_uses_llsc) {
6571+ unsigned long temp;
6572+
6573+ __asm__ __volatile__(
6574+ " .set mips3 \n"
6575+ "1:" __LL "%1, %2 # local_add_return \n"
6576+ " addu %0, %1, %3 \n"
6577+ __SC "%0, %2 \n"
6578+ " beqz %0, 1b \n"
6579+ " addu %0, %1, %3 \n"
6580+ " .set mips0 \n"
6581+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6582+ : "Ir" (i), "m" (l->a.counter)
6583+ : "memory");
6584+ } else {
6585+ unsigned long flags;
6586+
6587+ local_irq_save(flags);
6588+ result = l->a.counter;
6589+ result += i;
6590+ l->a.counter = result;
6591+ local_irq_restore(flags);
6592+ }
6593+
6594+ return result;
6595+}
6596+
6597 static __inline__ long local_sub_return(long i, local_t * l)
6598 {
6599 unsigned long result;
6600@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6601
6602 #define local_cmpxchg(l, o, n) \
6603 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6604+#define local_cmpxchg_unchecked(l, o, n) \
6605+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6606 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6607
6608 /**
6609diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6610index f6be474..12ad554 100644
6611--- a/arch/mips/include/asm/page.h
6612+++ b/arch/mips/include/asm/page.h
6613@@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6614 #ifdef CONFIG_CPU_MIPS32
6615 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6616 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6617- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6618+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6619 #else
6620 typedef struct { unsigned long long pte; } pte_t;
6621 #define pte_val(x) ((x).pte)
6622diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6623index b336037..5b874cc 100644
6624--- a/arch/mips/include/asm/pgalloc.h
6625+++ b/arch/mips/include/asm/pgalloc.h
6626@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6627 {
6628 set_pud(pud, __pud((unsigned long)pmd));
6629 }
6630+
6631+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6632+{
6633+ pud_populate(mm, pud, pmd);
6634+}
6635 #endif
6636
6637 /*
6638diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6639index 008324d..f67c239 100644
6640--- a/arch/mips/include/asm/pgtable.h
6641+++ b/arch/mips/include/asm/pgtable.h
6642@@ -20,6 +20,9 @@
6643 #include <asm/io.h>
6644 #include <asm/pgtable-bits.h>
6645
6646+#define ktla_ktva(addr) (addr)
6647+#define ktva_ktla(addr) (addr)
6648+
6649 struct mm_struct;
6650 struct vm_area_struct;
6651
6652diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6653index 25da651..ae2a259 100644
6654--- a/arch/mips/include/asm/smtc_proc.h
6655+++ b/arch/mips/include/asm/smtc_proc.h
6656@@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6657
6658 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6659
6660-extern atomic_t smtc_fpu_recoveries;
6661+extern atomic_unchecked_t smtc_fpu_recoveries;
6662
6663 #endif /* __ASM_SMTC_PROC_H */
6664diff --git a/arch/mips/include/asm/syscall.h b/arch/mips/include/asm/syscall.h
6665index 33e8dbf..81d8432 100644
6666--- a/arch/mips/include/asm/syscall.h
6667+++ b/arch/mips/include/asm/syscall.h
6668@@ -39,14 +39,14 @@ static inline unsigned long mips_get_syscall_arg(unsigned long *arg,
6669
6670 #ifdef CONFIG_32BIT
6671 case 4: case 5: case 6: case 7:
6672- return get_user(*arg, (int *)usp + 4 * n);
6673+ return get_user(*arg, (int *)usp + n);
6674 #endif
6675
6676 #ifdef CONFIG_64BIT
6677 case 4: case 5: case 6: case 7:
6678 #ifdef CONFIG_MIPS32_O32
6679 if (test_thread_flag(TIF_32BIT_REGS))
6680- return get_user(*arg, (int *)usp + 4 * n);
6681+ return get_user(*arg, (int *)usp + n);
6682 else
6683 #endif
6684 *arg = regs->regs[4 + n];
6685@@ -83,11 +83,10 @@ static inline void syscall_get_arguments(struct task_struct *task,
6686 unsigned int i, unsigned int n,
6687 unsigned long *args)
6688 {
6689- unsigned long arg;
6690 int ret;
6691
6692 while (n--)
6693- ret |= mips_get_syscall_arg(&arg, task, regs, i++);
6694+ ret |= mips_get_syscall_arg(args++, task, regs, i++);
6695
6696 /*
6697 * No way to communicate an error because this is a void function.
6698diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6699index 4f58ef6..5e7081b 100644
6700--- a/arch/mips/include/asm/thread_info.h
6701+++ b/arch/mips/include/asm/thread_info.h
6702@@ -115,6 +115,8 @@ static inline struct thread_info *current_thread_info(void)
6703 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
6704 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6705 #define TIF_SYSCALL_TRACEPOINT 26 /* syscall tracepoint instrumentation */
6706+/* li takes a 32bit immediate */
6707+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6708 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6709
6710 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6711@@ -132,13 +134,14 @@ static inline struct thread_info *current_thread_info(void)
6712 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
6713 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6714 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6715+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6716
6717 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6718- _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6719+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6720
6721 /* work to do in syscall_trace_leave() */
6722 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6723- _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6724+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6725
6726 /* work to do on interrupt/exception return */
6727 #define _TIF_WORK_MASK \
6728@@ -146,7 +149,7 @@ static inline struct thread_info *current_thread_info(void)
6729 /* work to do on any return to u-space */
6730 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6731 _TIF_WORK_SYSCALL_EXIT | \
6732- _TIF_SYSCALL_TRACEPOINT)
6733+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6734
6735 /*
6736 * We stash processor id into a COP0 register to retrieve it fast
6737diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6738index f3fa375..3af6637 100644
6739--- a/arch/mips/include/asm/uaccess.h
6740+++ b/arch/mips/include/asm/uaccess.h
6741@@ -128,6 +128,7 @@ extern u64 __ua_limit;
6742 __ok == 0; \
6743 })
6744
6745+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6746 #define access_ok(type, addr, size) \
6747 likely(__access_ok((addr), (size), __access_mask))
6748
6749diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6750index 1188e00..41cf144 100644
6751--- a/arch/mips/kernel/binfmt_elfn32.c
6752+++ b/arch/mips/kernel/binfmt_elfn32.c
6753@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6754 #undef ELF_ET_DYN_BASE
6755 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6756
6757+#ifdef CONFIG_PAX_ASLR
6758+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6759+
6760+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6761+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6762+#endif
6763+
6764 #include <asm/processor.h>
6765 #include <linux/module.h>
6766 #include <linux/elfcore.h>
6767diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6768index 202e581..689ca79 100644
6769--- a/arch/mips/kernel/binfmt_elfo32.c
6770+++ b/arch/mips/kernel/binfmt_elfo32.c
6771@@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6772 #undef ELF_ET_DYN_BASE
6773 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6774
6775+#ifdef CONFIG_PAX_ASLR
6776+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6777+
6778+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6779+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6780+#endif
6781+
6782 #include <asm/processor.h>
6783
6784 /*
6785diff --git a/arch/mips/kernel/ftrace.c b/arch/mips/kernel/ftrace.c
6786index 185ba25..374ed74 100644
6787--- a/arch/mips/kernel/ftrace.c
6788+++ b/arch/mips/kernel/ftrace.c
6789@@ -111,11 +111,10 @@ static int ftrace_modify_code_2(unsigned long ip, unsigned int new_code1,
6790 safe_store_code(new_code1, ip, faulted);
6791 if (unlikely(faulted))
6792 return -EFAULT;
6793- ip += 4;
6794- safe_store_code(new_code2, ip, faulted);
6795+ safe_store_code(new_code2, ip + 4, faulted);
6796 if (unlikely(faulted))
6797 return -EFAULT;
6798- flush_icache_range(ip, ip + 8); /* original ip + 12 */
6799+ flush_icache_range(ip, ip + 8);
6800 return 0;
6801 }
6802 #endif
6803diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6804index 2b91fe8..fe4f6b4 100644
6805--- a/arch/mips/kernel/i8259.c
6806+++ b/arch/mips/kernel/i8259.c
6807@@ -205,7 +205,7 @@ spurious_8259A_irq:
6808 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6809 spurious_irq_mask |= irqmask;
6810 }
6811- atomic_inc(&irq_err_count);
6812+ atomic_inc_unchecked(&irq_err_count);
6813 /*
6814 * Theoretically we do not have to handle this IRQ,
6815 * but in Linux this does not cause problems and is
6816diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6817index 44a1f79..2bd6aa3 100644
6818--- a/arch/mips/kernel/irq-gt641xx.c
6819+++ b/arch/mips/kernel/irq-gt641xx.c
6820@@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6821 }
6822 }
6823
6824- atomic_inc(&irq_err_count);
6825+ atomic_inc_unchecked(&irq_err_count);
6826 }
6827
6828 void __init gt641xx_irq_init(void)
6829diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6830index d1fea7a..45602ea 100644
6831--- a/arch/mips/kernel/irq.c
6832+++ b/arch/mips/kernel/irq.c
6833@@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6834 printk("unexpected IRQ # %d\n", irq);
6835 }
6836
6837-atomic_t irq_err_count;
6838+atomic_unchecked_t irq_err_count;
6839
6840 int arch_show_interrupts(struct seq_file *p, int prec)
6841 {
6842- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6843+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6844 return 0;
6845 }
6846
6847 asmlinkage void spurious_interrupt(void)
6848 {
6849- atomic_inc(&irq_err_count);
6850+ atomic_inc_unchecked(&irq_err_count);
6851 }
6852
6853 void __init init_IRQ(void)
6854diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6855index ddc7610..8c58f17 100644
6856--- a/arch/mips/kernel/process.c
6857+++ b/arch/mips/kernel/process.c
6858@@ -566,15 +566,3 @@ unsigned long get_wchan(struct task_struct *task)
6859 out:
6860 return pc;
6861 }
6862-
6863-/*
6864- * Don't forget that the stack pointer must be aligned on a 8 bytes
6865- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6866- */
6867-unsigned long arch_align_stack(unsigned long sp)
6868-{
6869- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6870- sp -= get_random_int() & ~PAGE_MASK;
6871-
6872- return sp & ALMASK;
6873-}
6874diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6875index b52e1d2..1a3ca09 100644
6876--- a/arch/mips/kernel/ptrace.c
6877+++ b/arch/mips/kernel/ptrace.c
6878@@ -652,6 +652,10 @@ long arch_ptrace(struct task_struct *child, long request,
6879 return ret;
6880 }
6881
6882+#ifdef CONFIG_GRKERNSEC_SETXID
6883+extern void gr_delayed_cred_worker(void);
6884+#endif
6885+
6886 /*
6887 * Notification of system call entry/exit
6888 * - triggered by current->work.syscall_trace
6889@@ -668,6 +672,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6890 tracehook_report_syscall_entry(regs))
6891 ret = -1;
6892
6893+#ifdef CONFIG_GRKERNSEC_SETXID
6894+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6895+ gr_delayed_cred_worker();
6896+#endif
6897+
6898 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6899 trace_sys_enter(regs, regs->regs[2]);
6900
6901diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6902index 07fc524..b9d7f28 100644
6903--- a/arch/mips/kernel/reset.c
6904+++ b/arch/mips/kernel/reset.c
6905@@ -13,6 +13,7 @@
6906 #include <linux/reboot.h>
6907
6908 #include <asm/reboot.h>
6909+#include <asm/bug.h>
6910
6911 /*
6912 * Urgs ... Too many MIPS machines to handle this in a generic way.
6913@@ -29,16 +30,19 @@ void machine_restart(char *command)
6914 {
6915 if (_machine_restart)
6916 _machine_restart(command);
6917+ BUG();
6918 }
6919
6920 void machine_halt(void)
6921 {
6922 if (_machine_halt)
6923 _machine_halt();
6924+ BUG();
6925 }
6926
6927 void machine_power_off(void)
6928 {
6929 if (pm_power_off)
6930 pm_power_off();
6931+ BUG();
6932 }
6933diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6934index c10aa84..9ec2e60 100644
6935--- a/arch/mips/kernel/smtc-proc.c
6936+++ b/arch/mips/kernel/smtc-proc.c
6937@@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6938
6939 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6940
6941-atomic_t smtc_fpu_recoveries;
6942+atomic_unchecked_t smtc_fpu_recoveries;
6943
6944 static int smtc_proc_show(struct seq_file *m, void *v)
6945 {
6946@@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6947 for(i = 0; i < NR_CPUS; i++)
6948 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6949 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6950- atomic_read(&smtc_fpu_recoveries));
6951+ atomic_read_unchecked(&smtc_fpu_recoveries));
6952 return 0;
6953 }
6954
6955@@ -73,7 +73,7 @@ void init_smtc_stats(void)
6956 smtc_cpu_stats[i].selfipis = 0;
6957 }
6958
6959- atomic_set(&smtc_fpu_recoveries, 0);
6960+ atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6961
6962 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6963 }
6964diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6965index dfc1b91..11a2c07 100644
6966--- a/arch/mips/kernel/smtc.c
6967+++ b/arch/mips/kernel/smtc.c
6968@@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6969 }
6970 smtc_ipi_qdump();
6971 printk("%d Recoveries of \"stolen\" FPU\n",
6972- atomic_read(&smtc_fpu_recoveries));
6973+ atomic_read_unchecked(&smtc_fpu_recoveries));
6974 }
6975
6976
6977diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6978index 84536bf..79caa4d 100644
6979--- a/arch/mips/kernel/sync-r4k.c
6980+++ b/arch/mips/kernel/sync-r4k.c
6981@@ -21,8 +21,8 @@
6982 #include <asm/mipsregs.h>
6983
6984 static atomic_t count_start_flag = ATOMIC_INIT(0);
6985-static atomic_t count_count_start = ATOMIC_INIT(0);
6986-static atomic_t count_count_stop = ATOMIC_INIT(0);
6987+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6988+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6989 static atomic_t count_reference = ATOMIC_INIT(0);
6990
6991 #define COUNTON 100
6992@@ -69,13 +69,13 @@ void synchronise_count_master(int cpu)
6993
6994 for (i = 0; i < NR_LOOPS; i++) {
6995 /* slaves loop on '!= 2' */
6996- while (atomic_read(&count_count_start) != 1)
6997+ while (atomic_read_unchecked(&count_count_start) != 1)
6998 mb();
6999- atomic_set(&count_count_stop, 0);
7000+ atomic_set_unchecked(&count_count_stop, 0);
7001 smp_wmb();
7002
7003 /* this lets the slaves write their count register */
7004- atomic_inc(&count_count_start);
7005+ atomic_inc_unchecked(&count_count_start);
7006
7007 /*
7008 * Everyone initialises count in the last loop:
7009@@ -86,11 +86,11 @@ void synchronise_count_master(int cpu)
7010 /*
7011 * Wait for all slaves to leave the synchronization point:
7012 */
7013- while (atomic_read(&count_count_stop) != 1)
7014+ while (atomic_read_unchecked(&count_count_stop) != 1)
7015 mb();
7016- atomic_set(&count_count_start, 0);
7017+ atomic_set_unchecked(&count_count_start, 0);
7018 smp_wmb();
7019- atomic_inc(&count_count_stop);
7020+ atomic_inc_unchecked(&count_count_stop);
7021 }
7022 /* Arrange for an interrupt in a short while */
7023 write_c0_compare(read_c0_count() + COUNTON);
7024@@ -131,8 +131,8 @@ void synchronise_count_slave(int cpu)
7025 initcount = atomic_read(&count_reference);
7026
7027 for (i = 0; i < NR_LOOPS; i++) {
7028- atomic_inc(&count_count_start);
7029- while (atomic_read(&count_count_start) != 2)
7030+ atomic_inc_unchecked(&count_count_start);
7031+ while (atomic_read_unchecked(&count_count_start) != 2)
7032 mb();
7033
7034 /*
7035@@ -141,8 +141,8 @@ void synchronise_count_slave(int cpu)
7036 if (i == NR_LOOPS-1)
7037 write_c0_count(initcount);
7038
7039- atomic_inc(&count_count_stop);
7040- while (atomic_read(&count_count_stop) != 2)
7041+ atomic_inc_unchecked(&count_count_stop);
7042+ while (atomic_read_unchecked(&count_count_stop) != 2)
7043 mb();
7044 }
7045 /* Arrange for an interrupt in a short while */
7046diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7047index f9c8746..78b64e3 100644
7048--- a/arch/mips/kernel/traps.c
7049+++ b/arch/mips/kernel/traps.c
7050@@ -690,7 +690,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7051 siginfo_t info;
7052
7053 prev_state = exception_enter();
7054- die_if_kernel("Integer overflow", regs);
7055+ if (unlikely(!user_mode(regs))) {
7056+
7057+#ifdef CONFIG_PAX_REFCOUNT
7058+ if (fixup_exception(regs)) {
7059+ pax_report_refcount_overflow(regs);
7060+ exception_exit(prev_state);
7061+ return;
7062+ }
7063+#endif
7064+
7065+ die("Integer overflow", regs);
7066+ }
7067
7068 info.si_code = FPE_INTOVF;
7069 info.si_signo = SIGFPE;
7070diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7071index becc42b..9e43d4b 100644
7072--- a/arch/mips/mm/fault.c
7073+++ b/arch/mips/mm/fault.c
7074@@ -28,6 +28,23 @@
7075 #include <asm/highmem.h> /* For VMALLOC_END */
7076 #include <linux/kdebug.h>
7077
7078+#ifdef CONFIG_PAX_PAGEEXEC
7079+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7080+{
7081+ unsigned long i;
7082+
7083+ printk(KERN_ERR "PAX: bytes at PC: ");
7084+ for (i = 0; i < 5; i++) {
7085+ unsigned int c;
7086+ if (get_user(c, (unsigned int *)pc+i))
7087+ printk(KERN_CONT "???????? ");
7088+ else
7089+ printk(KERN_CONT "%08x ", c);
7090+ }
7091+ printk("\n");
7092+}
7093+#endif
7094+
7095 /*
7096 * This routine handles page faults. It determines the address,
7097 * and the problem, and then passes it off to one of the appropriate
7098@@ -199,6 +216,14 @@ bad_area:
7099 bad_area_nosemaphore:
7100 /* User mode accesses just cause a SIGSEGV */
7101 if (user_mode(regs)) {
7102+
7103+#ifdef CONFIG_PAX_PAGEEXEC
7104+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7105+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7106+ do_group_exit(SIGKILL);
7107+ }
7108+#endif
7109+
7110 tsk->thread.cp0_badvaddr = address;
7111 tsk->thread.error_code = write;
7112 #if 0
7113diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7114index f1baadd..5472dca 100644
7115--- a/arch/mips/mm/mmap.c
7116+++ b/arch/mips/mm/mmap.c
7117@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7118 struct vm_area_struct *vma;
7119 unsigned long addr = addr0;
7120 int do_color_align;
7121+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7122 struct vm_unmapped_area_info info;
7123
7124 if (unlikely(len > TASK_SIZE))
7125@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7126 do_color_align = 1;
7127
7128 /* requesting a specific address */
7129+
7130+#ifdef CONFIG_PAX_RANDMMAP
7131+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7132+#endif
7133+
7134 if (addr) {
7135 if (do_color_align)
7136 addr = COLOUR_ALIGN(addr, pgoff);
7137@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7138 addr = PAGE_ALIGN(addr);
7139
7140 vma = find_vma(mm, addr);
7141- if (TASK_SIZE - len >= addr &&
7142- (!vma || addr + len <= vma->vm_start))
7143+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7144 return addr;
7145 }
7146
7147 info.length = len;
7148 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7149 info.align_offset = pgoff << PAGE_SHIFT;
7150+ info.threadstack_offset = offset;
7151
7152 if (dir == DOWN) {
7153 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7154@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7155 {
7156 unsigned long random_factor = 0UL;
7157
7158+#ifdef CONFIG_PAX_RANDMMAP
7159+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7160+#endif
7161+
7162 if (current->flags & PF_RANDOMIZE) {
7163 random_factor = get_random_int();
7164 random_factor = random_factor << PAGE_SHIFT;
7165@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7166
7167 if (mmap_is_legacy()) {
7168 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7169+
7170+#ifdef CONFIG_PAX_RANDMMAP
7171+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7172+ mm->mmap_base += mm->delta_mmap;
7173+#endif
7174+
7175 mm->get_unmapped_area = arch_get_unmapped_area;
7176 } else {
7177 mm->mmap_base = mmap_base(random_factor);
7178+
7179+#ifdef CONFIG_PAX_RANDMMAP
7180+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7181+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7182+#endif
7183+
7184 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7185 }
7186 }
7187
7188-static inline unsigned long brk_rnd(void)
7189-{
7190- unsigned long rnd = get_random_int();
7191-
7192- rnd = rnd << PAGE_SHIFT;
7193- /* 8MB for 32bit, 256MB for 64bit */
7194- if (TASK_IS_32BIT_ADDR)
7195- rnd = rnd & 0x7ffffful;
7196- else
7197- rnd = rnd & 0xffffffful;
7198-
7199- return rnd;
7200-}
7201-
7202-unsigned long arch_randomize_brk(struct mm_struct *mm)
7203-{
7204- unsigned long base = mm->brk;
7205- unsigned long ret;
7206-
7207- ret = PAGE_ALIGN(base + brk_rnd());
7208-
7209- if (ret < mm->brk)
7210- return mm->brk;
7211-
7212- return ret;
7213-}
7214-
7215 int __virt_addr_valid(const volatile void *kaddr)
7216 {
7217 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7218diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7219index 59cccd9..f39ac2f 100644
7220--- a/arch/mips/pci/pci-octeon.c
7221+++ b/arch/mips/pci/pci-octeon.c
7222@@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7223
7224
7225 static struct pci_ops octeon_pci_ops = {
7226- octeon_read_config,
7227- octeon_write_config,
7228+ .read = octeon_read_config,
7229+ .write = octeon_write_config,
7230 };
7231
7232 static struct resource octeon_pci_mem_resource = {
7233diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7234index 5e36c33..eb4a17b 100644
7235--- a/arch/mips/pci/pcie-octeon.c
7236+++ b/arch/mips/pci/pcie-octeon.c
7237@@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7238 }
7239
7240 static struct pci_ops octeon_pcie0_ops = {
7241- octeon_pcie0_read_config,
7242- octeon_pcie0_write_config,
7243+ .read = octeon_pcie0_read_config,
7244+ .write = octeon_pcie0_write_config,
7245 };
7246
7247 static struct resource octeon_pcie0_mem_resource = {
7248@@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7249 };
7250
7251 static struct pci_ops octeon_pcie1_ops = {
7252- octeon_pcie1_read_config,
7253- octeon_pcie1_write_config,
7254+ .read = octeon_pcie1_read_config,
7255+ .write = octeon_pcie1_write_config,
7256 };
7257
7258 static struct resource octeon_pcie1_mem_resource = {
7259@@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7260 };
7261
7262 static struct pci_ops octeon_dummy_ops = {
7263- octeon_dummy_read_config,
7264- octeon_dummy_write_config,
7265+ .read = octeon_dummy_read_config,
7266+ .write = octeon_dummy_write_config,
7267 };
7268
7269 static struct resource octeon_dummy_mem_resource = {
7270diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7271index a2358b4..7cead4f 100644
7272--- a/arch/mips/sgi-ip27/ip27-nmi.c
7273+++ b/arch/mips/sgi-ip27/ip27-nmi.c
7274@@ -187,9 +187,9 @@ void
7275 cont_nmi_dump(void)
7276 {
7277 #ifndef REAL_NMI_SIGNAL
7278- static atomic_t nmied_cpus = ATOMIC_INIT(0);
7279+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7280
7281- atomic_inc(&nmied_cpus);
7282+ atomic_inc_unchecked(&nmied_cpus);
7283 #endif
7284 /*
7285 * Only allow 1 cpu to proceed
7286@@ -233,7 +233,7 @@ cont_nmi_dump(void)
7287 udelay(10000);
7288 }
7289 #else
7290- while (atomic_read(&nmied_cpus) != num_online_cpus());
7291+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7292 #endif
7293
7294 /*
7295diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7296index a046b30..6799527 100644
7297--- a/arch/mips/sni/rm200.c
7298+++ b/arch/mips/sni/rm200.c
7299@@ -270,7 +270,7 @@ spurious_8259A_irq:
7300 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7301 spurious_irq_mask |= irqmask;
7302 }
7303- atomic_inc(&irq_err_count);
7304+ atomic_inc_unchecked(&irq_err_count);
7305 /*
7306 * Theoretically we do not have to handle this IRQ,
7307 * but in Linux this does not cause problems and is
7308diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7309index 41e873b..34d33a7 100644
7310--- a/arch/mips/vr41xx/common/icu.c
7311+++ b/arch/mips/vr41xx/common/icu.c
7312@@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7313
7314 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7315
7316- atomic_inc(&irq_err_count);
7317+ atomic_inc_unchecked(&irq_err_count);
7318
7319 return -1;
7320 }
7321diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7322index ae0e4ee..e8f0692 100644
7323--- a/arch/mips/vr41xx/common/irq.c
7324+++ b/arch/mips/vr41xx/common/irq.c
7325@@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7326 irq_cascade_t *cascade;
7327
7328 if (irq >= NR_IRQS) {
7329- atomic_inc(&irq_err_count);
7330+ atomic_inc_unchecked(&irq_err_count);
7331 return;
7332 }
7333
7334@@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7335 ret = cascade->get_irq(irq);
7336 irq = ret;
7337 if (ret < 0)
7338- atomic_inc(&irq_err_count);
7339+ atomic_inc_unchecked(&irq_err_count);
7340 else
7341 irq_dispatch(irq);
7342 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7343diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7344index 967d144..db12197 100644
7345--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7346+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7347@@ -11,12 +11,14 @@
7348 #ifndef _ASM_PROC_CACHE_H
7349 #define _ASM_PROC_CACHE_H
7350
7351+#include <linux/const.h>
7352+
7353 /* L1 cache */
7354
7355 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7356 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7357-#define L1_CACHE_BYTES 16 /* bytes per entry */
7358 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7359+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7360 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7361
7362 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7363diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7364index bcb5df2..84fabd2 100644
7365--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7366+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7367@@ -16,13 +16,15 @@
7368 #ifndef _ASM_PROC_CACHE_H
7369 #define _ASM_PROC_CACHE_H
7370
7371+#include <linux/const.h>
7372+
7373 /*
7374 * L1 cache
7375 */
7376 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7377 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7378-#define L1_CACHE_BYTES 32 /* bytes per entry */
7379 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7380+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7381 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7382
7383 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7384diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7385index 4ce7a01..449202a 100644
7386--- a/arch/openrisc/include/asm/cache.h
7387+++ b/arch/openrisc/include/asm/cache.h
7388@@ -19,11 +19,13 @@
7389 #ifndef __ASM_OPENRISC_CACHE_H
7390 #define __ASM_OPENRISC_CACHE_H
7391
7392+#include <linux/const.h>
7393+
7394 /* FIXME: How can we replace these with values from the CPU...
7395 * they shouldn't be hard-coded!
7396 */
7397
7398-#define L1_CACHE_BYTES 16
7399 #define L1_CACHE_SHIFT 4
7400+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7401
7402 #endif /* __ASM_OPENRISC_CACHE_H */
7403diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7404index 472886c..00e7df9 100644
7405--- a/arch/parisc/include/asm/atomic.h
7406+++ b/arch/parisc/include/asm/atomic.h
7407@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7408 return dec;
7409 }
7410
7411+#define atomic64_read_unchecked(v) atomic64_read(v)
7412+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7413+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7414+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7415+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7416+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7417+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7418+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7419+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7420+
7421 #endif /* !CONFIG_64BIT */
7422
7423
7424diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7425index 47f11c7..3420df2 100644
7426--- a/arch/parisc/include/asm/cache.h
7427+++ b/arch/parisc/include/asm/cache.h
7428@@ -5,6 +5,7 @@
7429 #ifndef __ARCH_PARISC_CACHE_H
7430 #define __ARCH_PARISC_CACHE_H
7431
7432+#include <linux/const.h>
7433
7434 /*
7435 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7436@@ -15,13 +16,13 @@
7437 * just ruin performance.
7438 */
7439 #ifdef CONFIG_PA20
7440-#define L1_CACHE_BYTES 64
7441 #define L1_CACHE_SHIFT 6
7442 #else
7443-#define L1_CACHE_BYTES 32
7444 #define L1_CACHE_SHIFT 5
7445 #endif
7446
7447+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7448+
7449 #ifndef __ASSEMBLY__
7450
7451 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7452diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7453index ad2b503..bdf1651 100644
7454--- a/arch/parisc/include/asm/elf.h
7455+++ b/arch/parisc/include/asm/elf.h
7456@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7457
7458 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7459
7460+#ifdef CONFIG_PAX_ASLR
7461+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7462+
7463+#define PAX_DELTA_MMAP_LEN 16
7464+#define PAX_DELTA_STACK_LEN 16
7465+#endif
7466+
7467 /* This yields a mask that user programs can use to figure out what
7468 instruction set this CPU supports. This could be done in user space,
7469 but it's not easy, and we've already done it here. */
7470diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7471index f213f5b..0af3e8e 100644
7472--- a/arch/parisc/include/asm/pgalloc.h
7473+++ b/arch/parisc/include/asm/pgalloc.h
7474@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7475 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7476 }
7477
7478+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7479+{
7480+ pgd_populate(mm, pgd, pmd);
7481+}
7482+
7483 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7484 {
7485 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7486@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7487 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7488 #define pmd_free(mm, x) do { } while (0)
7489 #define pgd_populate(mm, pmd, pte) BUG()
7490+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7491
7492 #endif
7493
7494diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7495index 34899b5..02dd060 100644
7496--- a/arch/parisc/include/asm/pgtable.h
7497+++ b/arch/parisc/include/asm/pgtable.h
7498@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7499 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7500 #define PAGE_COPY PAGE_EXECREAD
7501 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7502+
7503+#ifdef CONFIG_PAX_PAGEEXEC
7504+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7505+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7506+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7507+#else
7508+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7509+# define PAGE_COPY_NOEXEC PAGE_COPY
7510+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7511+#endif
7512+
7513 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7514 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7515 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7516diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7517index 4006964..fcb3cc2 100644
7518--- a/arch/parisc/include/asm/uaccess.h
7519+++ b/arch/parisc/include/asm/uaccess.h
7520@@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7521 const void __user *from,
7522 unsigned long n)
7523 {
7524- int sz = __compiletime_object_size(to);
7525+ size_t sz = __compiletime_object_size(to);
7526 int ret = -EFAULT;
7527
7528- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7529+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7530 ret = __copy_from_user(to, from, n);
7531 else
7532 copy_from_user_overflow();
7533diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7534index 50dfafc..b9fc230 100644
7535--- a/arch/parisc/kernel/module.c
7536+++ b/arch/parisc/kernel/module.c
7537@@ -98,16 +98,38 @@
7538
7539 /* three functions to determine where in the module core
7540 * or init pieces the location is */
7541+static inline int in_init_rx(struct module *me, void *loc)
7542+{
7543+ return (loc >= me->module_init_rx &&
7544+ loc < (me->module_init_rx + me->init_size_rx));
7545+}
7546+
7547+static inline int in_init_rw(struct module *me, void *loc)
7548+{
7549+ return (loc >= me->module_init_rw &&
7550+ loc < (me->module_init_rw + me->init_size_rw));
7551+}
7552+
7553 static inline int in_init(struct module *me, void *loc)
7554 {
7555- return (loc >= me->module_init &&
7556- loc <= (me->module_init + me->init_size));
7557+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7558+}
7559+
7560+static inline int in_core_rx(struct module *me, void *loc)
7561+{
7562+ return (loc >= me->module_core_rx &&
7563+ loc < (me->module_core_rx + me->core_size_rx));
7564+}
7565+
7566+static inline int in_core_rw(struct module *me, void *loc)
7567+{
7568+ return (loc >= me->module_core_rw &&
7569+ loc < (me->module_core_rw + me->core_size_rw));
7570 }
7571
7572 static inline int in_core(struct module *me, void *loc)
7573 {
7574- return (loc >= me->module_core &&
7575- loc <= (me->module_core + me->core_size));
7576+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7577 }
7578
7579 static inline int in_local(struct module *me, void *loc)
7580@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7581 }
7582
7583 /* align things a bit */
7584- me->core_size = ALIGN(me->core_size, 16);
7585- me->arch.got_offset = me->core_size;
7586- me->core_size += gots * sizeof(struct got_entry);
7587+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7588+ me->arch.got_offset = me->core_size_rw;
7589+ me->core_size_rw += gots * sizeof(struct got_entry);
7590
7591- me->core_size = ALIGN(me->core_size, 16);
7592- me->arch.fdesc_offset = me->core_size;
7593- me->core_size += fdescs * sizeof(Elf_Fdesc);
7594+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7595+ me->arch.fdesc_offset = me->core_size_rw;
7596+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7597
7598 me->arch.got_max = gots;
7599 me->arch.fdesc_max = fdescs;
7600@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7601
7602 BUG_ON(value == 0);
7603
7604- got = me->module_core + me->arch.got_offset;
7605+ got = me->module_core_rw + me->arch.got_offset;
7606 for (i = 0; got[i].addr; i++)
7607 if (got[i].addr == value)
7608 goto out;
7609@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7610 #ifdef CONFIG_64BIT
7611 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7612 {
7613- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7614+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7615
7616 if (!value) {
7617 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7618@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7619
7620 /* Create new one */
7621 fdesc->addr = value;
7622- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7623+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7624 return (Elf_Addr)fdesc;
7625 }
7626 #endif /* CONFIG_64BIT */
7627@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7628
7629 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7630 end = table + sechdrs[me->arch.unwind_section].sh_size;
7631- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7632+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7633
7634 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7635 me->arch.unwind_section, table, end, gp);
7636diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7637index 0d3a9d4..20a99b0 100644
7638--- a/arch/parisc/kernel/sys_parisc.c
7639+++ b/arch/parisc/kernel/sys_parisc.c
7640@@ -33,9 +33,11 @@
7641 #include <linux/utsname.h>
7642 #include <linux/personality.h>
7643
7644-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7645+static unsigned long get_unshared_area(unsigned long addr, unsigned long len,
7646+ unsigned long flags)
7647 {
7648 struct vm_unmapped_area_info info;
7649+ unsigned long offset = gr_rand_threadstack_offset(current->mm, NULL, flags);
7650
7651 info.flags = 0;
7652 info.length = len;
7653@@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7654 info.high_limit = TASK_SIZE;
7655 info.align_mask = 0;
7656 info.align_offset = 0;
7657+ info.threadstack_offset = offset;
7658 return vm_unmapped_area(&info);
7659 }
7660
7661@@ -69,9 +72,10 @@ static unsigned long shared_align_offset(struct file *filp, unsigned long pgoff)
7662 }
7663
7664 static unsigned long get_shared_area(struct file *filp, unsigned long addr,
7665- unsigned long len, unsigned long pgoff)
7666+ unsigned long len, unsigned long pgoff, unsigned long flags)
7667 {
7668 struct vm_unmapped_area_info info;
7669+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7670
7671 info.flags = 0;
7672 info.length = len;
7673@@ -79,6 +83,7 @@ static unsigned long get_shared_area(struct file *filp, unsigned long addr,
7674 info.high_limit = TASK_SIZE;
7675 info.align_mask = PAGE_MASK & (SHMLBA - 1);
7676 info.align_offset = shared_align_offset(filp, pgoff);
7677+ info.threadstack_offset = offset;
7678 return vm_unmapped_area(&info);
7679 }
7680
7681@@ -93,13 +98,20 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7682 return -EINVAL;
7683 return addr;
7684 }
7685- if (!addr)
7686+ if (!addr) {
7687 addr = TASK_UNMAPPED_BASE;
7688
7689+#ifdef CONFIG_PAX_RANDMMAP
7690+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
7691+ addr += current->mm->delta_mmap;
7692+#endif
7693+
7694+ }
7695+
7696 if (filp || (flags & MAP_SHARED))
7697- addr = get_shared_area(filp, addr, len, pgoff);
7698+ addr = get_shared_area(filp, addr, len, pgoff, flags);
7699 else
7700- addr = get_unshared_area(addr, len);
7701+ addr = get_unshared_area(addr, len, flags);
7702
7703 return addr;
7704 }
7705diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7706index 1cd1d0c..44ec918 100644
7707--- a/arch/parisc/kernel/traps.c
7708+++ b/arch/parisc/kernel/traps.c
7709@@ -722,9 +722,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7710
7711 down_read(&current->mm->mmap_sem);
7712 vma = find_vma(current->mm,regs->iaoq[0]);
7713- if (vma && (regs->iaoq[0] >= vma->vm_start)
7714- && (vma->vm_flags & VM_EXEC)) {
7715-
7716+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7717 fault_address = regs->iaoq[0];
7718 fault_space = regs->iasq[0];
7719
7720diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7721index 9d08c71..e2b4d20 100644
7722--- a/arch/parisc/mm/fault.c
7723+++ b/arch/parisc/mm/fault.c
7724@@ -15,6 +15,7 @@
7725 #include <linux/sched.h>
7726 #include <linux/interrupt.h>
7727 #include <linux/module.h>
7728+#include <linux/unistd.h>
7729
7730 #include <asm/uaccess.h>
7731 #include <asm/traps.h>
7732@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7733 static unsigned long
7734 parisc_acctyp(unsigned long code, unsigned int inst)
7735 {
7736- if (code == 6 || code == 16)
7737+ if (code == 6 || code == 7 || code == 16)
7738 return VM_EXEC;
7739
7740 switch (inst & 0xf0000000) {
7741@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7742 }
7743 #endif
7744
7745+#ifdef CONFIG_PAX_PAGEEXEC
7746+/*
7747+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7748+ *
7749+ * returns 1 when task should be killed
7750+ * 2 when rt_sigreturn trampoline was detected
7751+ * 3 when unpatched PLT trampoline was detected
7752+ */
7753+static int pax_handle_fetch_fault(struct pt_regs *regs)
7754+{
7755+
7756+#ifdef CONFIG_PAX_EMUPLT
7757+ int err;
7758+
7759+ do { /* PaX: unpatched PLT emulation */
7760+ unsigned int bl, depwi;
7761+
7762+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7763+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7764+
7765+ if (err)
7766+ break;
7767+
7768+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7769+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7770+
7771+ err = get_user(ldw, (unsigned int *)addr);
7772+ err |= get_user(bv, (unsigned int *)(addr+4));
7773+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7774+
7775+ if (err)
7776+ break;
7777+
7778+ if (ldw == 0x0E801096U &&
7779+ bv == 0xEAC0C000U &&
7780+ ldw2 == 0x0E881095U)
7781+ {
7782+ unsigned int resolver, map;
7783+
7784+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7785+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7786+ if (err)
7787+ break;
7788+
7789+ regs->gr[20] = instruction_pointer(regs)+8;
7790+ regs->gr[21] = map;
7791+ regs->gr[22] = resolver;
7792+ regs->iaoq[0] = resolver | 3UL;
7793+ regs->iaoq[1] = regs->iaoq[0] + 4;
7794+ return 3;
7795+ }
7796+ }
7797+ } while (0);
7798+#endif
7799+
7800+#ifdef CONFIG_PAX_EMUTRAMP
7801+
7802+#ifndef CONFIG_PAX_EMUSIGRT
7803+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7804+ return 1;
7805+#endif
7806+
7807+ do { /* PaX: rt_sigreturn emulation */
7808+ unsigned int ldi1, ldi2, bel, nop;
7809+
7810+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7811+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7812+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7813+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7814+
7815+ if (err)
7816+ break;
7817+
7818+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7819+ ldi2 == 0x3414015AU &&
7820+ bel == 0xE4008200U &&
7821+ nop == 0x08000240U)
7822+ {
7823+ regs->gr[25] = (ldi1 & 2) >> 1;
7824+ regs->gr[20] = __NR_rt_sigreturn;
7825+ regs->gr[31] = regs->iaoq[1] + 16;
7826+ regs->sr[0] = regs->iasq[1];
7827+ regs->iaoq[0] = 0x100UL;
7828+ regs->iaoq[1] = regs->iaoq[0] + 4;
7829+ regs->iasq[0] = regs->sr[2];
7830+ regs->iasq[1] = regs->sr[2];
7831+ return 2;
7832+ }
7833+ } while (0);
7834+#endif
7835+
7836+ return 1;
7837+}
7838+
7839+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7840+{
7841+ unsigned long i;
7842+
7843+ printk(KERN_ERR "PAX: bytes at PC: ");
7844+ for (i = 0; i < 5; i++) {
7845+ unsigned int c;
7846+ if (get_user(c, (unsigned int *)pc+i))
7847+ printk(KERN_CONT "???????? ");
7848+ else
7849+ printk(KERN_CONT "%08x ", c);
7850+ }
7851+ printk("\n");
7852+}
7853+#endif
7854+
7855 int fixup_exception(struct pt_regs *regs)
7856 {
7857 const struct exception_table_entry *fix;
7858@@ -210,8 +321,33 @@ retry:
7859
7860 good_area:
7861
7862- if ((vma->vm_flags & acc_type) != acc_type)
7863+ if ((vma->vm_flags & acc_type) != acc_type) {
7864+
7865+#ifdef CONFIG_PAX_PAGEEXEC
7866+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7867+ (address & ~3UL) == instruction_pointer(regs))
7868+ {
7869+ up_read(&mm->mmap_sem);
7870+ switch (pax_handle_fetch_fault(regs)) {
7871+
7872+#ifdef CONFIG_PAX_EMUPLT
7873+ case 3:
7874+ return;
7875+#endif
7876+
7877+#ifdef CONFIG_PAX_EMUTRAMP
7878+ case 2:
7879+ return;
7880+#endif
7881+
7882+ }
7883+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7884+ do_group_exit(SIGKILL);
7885+ }
7886+#endif
7887+
7888 goto bad_area;
7889+ }
7890
7891 /*
7892 * If for any reason at all we couldn't handle the fault, make
7893diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7894index b44b52c..4cd253c 100644
7895--- a/arch/powerpc/Kconfig
7896+++ b/arch/powerpc/Kconfig
7897@@ -382,6 +382,7 @@ config ARCH_ENABLE_MEMORY_HOTREMOVE
7898 config KEXEC
7899 bool "kexec system call"
7900 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7901+ depends on !GRKERNSEC_KMEM
7902 help
7903 kexec is a system call that implements the ability to shutdown your
7904 current kernel, and to start another kernel. It is like a reboot
7905diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7906index e3b1d41..8e81edf 100644
7907--- a/arch/powerpc/include/asm/atomic.h
7908+++ b/arch/powerpc/include/asm/atomic.h
7909@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7910 return t1;
7911 }
7912
7913+#define atomic64_read_unchecked(v) atomic64_read(v)
7914+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7915+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7916+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7917+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7918+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7919+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7920+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7921+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7922+
7923 #endif /* __powerpc64__ */
7924
7925 #endif /* __KERNEL__ */
7926diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7927index 9e495c9..b6878e5 100644
7928--- a/arch/powerpc/include/asm/cache.h
7929+++ b/arch/powerpc/include/asm/cache.h
7930@@ -3,6 +3,7 @@
7931
7932 #ifdef __KERNEL__
7933
7934+#include <linux/const.h>
7935
7936 /* bytes per L1 cache line */
7937 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7938@@ -22,7 +23,7 @@
7939 #define L1_CACHE_SHIFT 7
7940 #endif
7941
7942-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7943+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7944
7945 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7946
7947diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7948index 935b5e7..7001d2d 100644
7949--- a/arch/powerpc/include/asm/elf.h
7950+++ b/arch/powerpc/include/asm/elf.h
7951@@ -28,8 +28,19 @@
7952 the loader. We need to make sure that it is out of the way of the program
7953 that it will "exec", and that there is sufficient room for the brk. */
7954
7955-extern unsigned long randomize_et_dyn(unsigned long base);
7956-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7957+#define ELF_ET_DYN_BASE (0x20000000)
7958+
7959+#ifdef CONFIG_PAX_ASLR
7960+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7961+
7962+#ifdef __powerpc64__
7963+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7964+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7965+#else
7966+#define PAX_DELTA_MMAP_LEN 15
7967+#define PAX_DELTA_STACK_LEN 15
7968+#endif
7969+#endif
7970
7971 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
7972
7973@@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7974 (0x7ff >> (PAGE_SHIFT - 12)) : \
7975 (0x3ffff >> (PAGE_SHIFT - 12)))
7976
7977-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7978-#define arch_randomize_brk arch_randomize_brk
7979-
7980-
7981 #ifdef CONFIG_SPU_BASE
7982 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7983 #define NT_SPU 1
7984diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7985index 8196e9c..d83a9f3 100644
7986--- a/arch/powerpc/include/asm/exec.h
7987+++ b/arch/powerpc/include/asm/exec.h
7988@@ -4,6 +4,6 @@
7989 #ifndef _ASM_POWERPC_EXEC_H
7990 #define _ASM_POWERPC_EXEC_H
7991
7992-extern unsigned long arch_align_stack(unsigned long sp);
7993+#define arch_align_stack(x) ((x) & ~0xfUL)
7994
7995 #endif /* _ASM_POWERPC_EXEC_H */
7996diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7997index 5acabbd..7ea14fa 100644
7998--- a/arch/powerpc/include/asm/kmap_types.h
7999+++ b/arch/powerpc/include/asm/kmap_types.h
8000@@ -10,7 +10,7 @@
8001 * 2 of the License, or (at your option) any later version.
8002 */
8003
8004-#define KM_TYPE_NR 16
8005+#define KM_TYPE_NR 17
8006
8007 #endif /* __KERNEL__ */
8008 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8009diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8010index b8da913..60b608a 100644
8011--- a/arch/powerpc/include/asm/local.h
8012+++ b/arch/powerpc/include/asm/local.h
8013@@ -9,15 +9,26 @@ typedef struct
8014 atomic_long_t a;
8015 } local_t;
8016
8017+typedef struct
8018+{
8019+ atomic_long_unchecked_t a;
8020+} local_unchecked_t;
8021+
8022 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8023
8024 #define local_read(l) atomic_long_read(&(l)->a)
8025+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8026 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8027+#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8028
8029 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8030+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8031 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8032+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8033 #define local_inc(l) atomic_long_inc(&(l)->a)
8034+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8035 #define local_dec(l) atomic_long_dec(&(l)->a)
8036+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8037
8038 static __inline__ long local_add_return(long a, local_t *l)
8039 {
8040@@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8041
8042 return t;
8043 }
8044+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8045
8046 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8047
8048@@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8049
8050 return t;
8051 }
8052+#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8053
8054 static __inline__ long local_inc_return(local_t *l)
8055 {
8056@@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8057
8058 #define local_cmpxchg(l, o, n) \
8059 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8060+#define local_cmpxchg_unchecked(l, o, n) \
8061+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
8062 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8063
8064 /**
8065diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8066index 8565c25..2865190 100644
8067--- a/arch/powerpc/include/asm/mman.h
8068+++ b/arch/powerpc/include/asm/mman.h
8069@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8070 }
8071 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8072
8073-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8074+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8075 {
8076 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8077 }
8078diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8079index 32e4e21..62afb12 100644
8080--- a/arch/powerpc/include/asm/page.h
8081+++ b/arch/powerpc/include/asm/page.h
8082@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8083 * and needs to be executable. This means the whole heap ends
8084 * up being executable.
8085 */
8086-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8087- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8088+#define VM_DATA_DEFAULT_FLAGS32 \
8089+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8090+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8091
8092 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8093 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8094@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8095 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8096 #endif
8097
8098+#define ktla_ktva(addr) (addr)
8099+#define ktva_ktla(addr) (addr)
8100+
8101 #ifndef CONFIG_PPC_BOOK3S_64
8102 /*
8103 * Use the top bit of the higher-level page table entries to indicate whether
8104diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8105index 88693ce..ac6f9ab 100644
8106--- a/arch/powerpc/include/asm/page_64.h
8107+++ b/arch/powerpc/include/asm/page_64.h
8108@@ -153,15 +153,18 @@ do { \
8109 * stack by default, so in the absence of a PT_GNU_STACK program header
8110 * we turn execute permission off.
8111 */
8112-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8113- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8114+#define VM_STACK_DEFAULT_FLAGS32 \
8115+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8116+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8117
8118 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8119 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8120
8121+#ifndef CONFIG_PAX_PAGEEXEC
8122 #define VM_STACK_DEFAULT_FLAGS \
8123 (is_32bit_task() ? \
8124 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8125+#endif
8126
8127 #include <asm-generic/getorder.h>
8128
8129diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8130index 4b0be20..c15a27d 100644
8131--- a/arch/powerpc/include/asm/pgalloc-64.h
8132+++ b/arch/powerpc/include/asm/pgalloc-64.h
8133@@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8134 #ifndef CONFIG_PPC_64K_PAGES
8135
8136 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8137+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8138
8139 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8140 {
8141@@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8142 pud_set(pud, (unsigned long)pmd);
8143 }
8144
8145+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8146+{
8147+ pud_populate(mm, pud, pmd);
8148+}
8149+
8150 #define pmd_populate(mm, pmd, pte_page) \
8151 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8152 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8153@@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8154 #endif
8155
8156 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8157+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8158
8159 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8160 pte_t *pte)
8161diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8162index 7d6eacf..14c0240 100644
8163--- a/arch/powerpc/include/asm/pgtable.h
8164+++ b/arch/powerpc/include/asm/pgtable.h
8165@@ -2,6 +2,7 @@
8166 #define _ASM_POWERPC_PGTABLE_H
8167 #ifdef __KERNEL__
8168
8169+#include <linux/const.h>
8170 #ifndef __ASSEMBLY__
8171 #include <asm/processor.h> /* For TASK_SIZE */
8172 #include <asm/mmu.h>
8173diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8174index 4aad413..85d86bf 100644
8175--- a/arch/powerpc/include/asm/pte-hash32.h
8176+++ b/arch/powerpc/include/asm/pte-hash32.h
8177@@ -21,6 +21,7 @@
8178 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8179 #define _PAGE_USER 0x004 /* usermode access allowed */
8180 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8181+#define _PAGE_EXEC _PAGE_GUARDED
8182 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8183 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8184 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8185diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8186index fa8388e..f985549 100644
8187--- a/arch/powerpc/include/asm/reg.h
8188+++ b/arch/powerpc/include/asm/reg.h
8189@@ -239,6 +239,7 @@
8190 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8191 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8192 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8193+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8194 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8195 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8196 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8197diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8198index 084e080..9415a3d 100644
8199--- a/arch/powerpc/include/asm/smp.h
8200+++ b/arch/powerpc/include/asm/smp.h
8201@@ -51,7 +51,7 @@ struct smp_ops_t {
8202 int (*cpu_disable)(void);
8203 void (*cpu_die)(unsigned int nr);
8204 int (*cpu_bootable)(unsigned int nr);
8205-};
8206+} __no_const;
8207
8208 extern void smp_send_debugger_break(void);
8209 extern void start_secondary_resume(void);
8210diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8211index 9854c56..7517190 100644
8212--- a/arch/powerpc/include/asm/thread_info.h
8213+++ b/arch/powerpc/include/asm/thread_info.h
8214@@ -91,7 +91,6 @@ static inline struct thread_info *current_thread_info(void)
8215 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
8216 TIF_NEED_RESCHED */
8217 #define TIF_32BIT 4 /* 32 bit binary */
8218-#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
8219 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
8220 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
8221 #define TIF_SINGLESTEP 8 /* singlestepping active */
8222@@ -108,6 +107,9 @@ static inline struct thread_info *current_thread_info(void)
8223 #if defined(CONFIG_PPC64)
8224 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8225 #endif
8226+#define TIF_PERFMON_WORK 19 /* work for pfm_handle_work() */
8227+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8228+#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
8229
8230 /* as above, but as bit values */
8231 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8232@@ -127,9 +129,10 @@ static inline struct thread_info *current_thread_info(void)
8233 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8234 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8235 #define _TIF_NOHZ (1<<TIF_NOHZ)
8236+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8237 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8238 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8239- _TIF_NOHZ)
8240+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
8241
8242 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8243 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
8244diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8245index 9485b43..3bd3c16 100644
8246--- a/arch/powerpc/include/asm/uaccess.h
8247+++ b/arch/powerpc/include/asm/uaccess.h
8248@@ -58,6 +58,7 @@
8249
8250 #endif
8251
8252+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8253 #define access_ok(type, addr, size) \
8254 (__chk_user_ptr(addr), \
8255 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8256@@ -318,52 +319,6 @@ do { \
8257 extern unsigned long __copy_tofrom_user(void __user *to,
8258 const void __user *from, unsigned long size);
8259
8260-#ifndef __powerpc64__
8261-
8262-static inline unsigned long copy_from_user(void *to,
8263- const void __user *from, unsigned long n)
8264-{
8265- unsigned long over;
8266-
8267- if (access_ok(VERIFY_READ, from, n))
8268- return __copy_tofrom_user((__force void __user *)to, from, n);
8269- if ((unsigned long)from < TASK_SIZE) {
8270- over = (unsigned long)from + n - TASK_SIZE;
8271- return __copy_tofrom_user((__force void __user *)to, from,
8272- n - over) + over;
8273- }
8274- return n;
8275-}
8276-
8277-static inline unsigned long copy_to_user(void __user *to,
8278- const void *from, unsigned long n)
8279-{
8280- unsigned long over;
8281-
8282- if (access_ok(VERIFY_WRITE, to, n))
8283- return __copy_tofrom_user(to, (__force void __user *)from, n);
8284- if ((unsigned long)to < TASK_SIZE) {
8285- over = (unsigned long)to + n - TASK_SIZE;
8286- return __copy_tofrom_user(to, (__force void __user *)from,
8287- n - over) + over;
8288- }
8289- return n;
8290-}
8291-
8292-#else /* __powerpc64__ */
8293-
8294-#define __copy_in_user(to, from, size) \
8295- __copy_tofrom_user((to), (from), (size))
8296-
8297-extern unsigned long copy_from_user(void *to, const void __user *from,
8298- unsigned long n);
8299-extern unsigned long copy_to_user(void __user *to, const void *from,
8300- unsigned long n);
8301-extern unsigned long copy_in_user(void __user *to, const void __user *from,
8302- unsigned long n);
8303-
8304-#endif /* __powerpc64__ */
8305-
8306 static inline unsigned long __copy_from_user_inatomic(void *to,
8307 const void __user *from, unsigned long n)
8308 {
8309@@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8310 if (ret == 0)
8311 return 0;
8312 }
8313+
8314+ if (!__builtin_constant_p(n))
8315+ check_object_size(to, n, false);
8316+
8317 return __copy_tofrom_user((__force void __user *)to, from, n);
8318 }
8319
8320@@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8321 if (ret == 0)
8322 return 0;
8323 }
8324+
8325+ if (!__builtin_constant_p(n))
8326+ check_object_size(from, n, true);
8327+
8328 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8329 }
8330
8331@@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8332 return __copy_to_user_inatomic(to, from, size);
8333 }
8334
8335+#ifndef __powerpc64__
8336+
8337+static inline unsigned long __must_check copy_from_user(void *to,
8338+ const void __user *from, unsigned long n)
8339+{
8340+ unsigned long over;
8341+
8342+ if ((long)n < 0)
8343+ return n;
8344+
8345+ if (access_ok(VERIFY_READ, from, n)) {
8346+ if (!__builtin_constant_p(n))
8347+ check_object_size(to, n, false);
8348+ return __copy_tofrom_user((__force void __user *)to, from, n);
8349+ }
8350+ if ((unsigned long)from < TASK_SIZE) {
8351+ over = (unsigned long)from + n - TASK_SIZE;
8352+ if (!__builtin_constant_p(n - over))
8353+ check_object_size(to, n - over, false);
8354+ return __copy_tofrom_user((__force void __user *)to, from,
8355+ n - over) + over;
8356+ }
8357+ return n;
8358+}
8359+
8360+static inline unsigned long __must_check copy_to_user(void __user *to,
8361+ const void *from, unsigned long n)
8362+{
8363+ unsigned long over;
8364+
8365+ if ((long)n < 0)
8366+ return n;
8367+
8368+ if (access_ok(VERIFY_WRITE, to, n)) {
8369+ if (!__builtin_constant_p(n))
8370+ check_object_size(from, n, true);
8371+ return __copy_tofrom_user(to, (__force void __user *)from, n);
8372+ }
8373+ if ((unsigned long)to < TASK_SIZE) {
8374+ over = (unsigned long)to + n - TASK_SIZE;
8375+ if (!__builtin_constant_p(n))
8376+ check_object_size(from, n - over, true);
8377+ return __copy_tofrom_user(to, (__force void __user *)from,
8378+ n - over) + over;
8379+ }
8380+ return n;
8381+}
8382+
8383+#else /* __powerpc64__ */
8384+
8385+#define __copy_in_user(to, from, size) \
8386+ __copy_tofrom_user((to), (from), (size))
8387+
8388+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8389+{
8390+ if ((long)n < 0 || n > INT_MAX)
8391+ return n;
8392+
8393+ if (!__builtin_constant_p(n))
8394+ check_object_size(to, n, false);
8395+
8396+ if (likely(access_ok(VERIFY_READ, from, n)))
8397+ n = __copy_from_user(to, from, n);
8398+ else
8399+ memset(to, 0, n);
8400+ return n;
8401+}
8402+
8403+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8404+{
8405+ if ((long)n < 0 || n > INT_MAX)
8406+ return n;
8407+
8408+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
8409+ if (!__builtin_constant_p(n))
8410+ check_object_size(from, n, true);
8411+ n = __copy_to_user(to, from, n);
8412+ }
8413+ return n;
8414+}
8415+
8416+extern unsigned long copy_in_user(void __user *to, const void __user *from,
8417+ unsigned long n);
8418+
8419+#endif /* __powerpc64__ */
8420+
8421 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8422
8423 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8424diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8425index 445cb6e..4f80c5d 100644
8426--- a/arch/powerpc/kernel/Makefile
8427+++ b/arch/powerpc/kernel/Makefile
8428@@ -26,6 +26,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8429 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8430 endif
8431
8432+CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8433+
8434 obj-y := cputable.o ptrace.o syscalls.o \
8435 irq.o align.o signal_32.o pmc.o vdso.o \
8436 process.o systbl.o idle.o \
8437diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8438index e775156..af2d1c0 100644
8439--- a/arch/powerpc/kernel/exceptions-64e.S
8440+++ b/arch/powerpc/kernel/exceptions-64e.S
8441@@ -759,6 +759,7 @@ storage_fault_common:
8442 std r14,_DAR(r1)
8443 std r15,_DSISR(r1)
8444 addi r3,r1,STACK_FRAME_OVERHEAD
8445+ bl .save_nvgprs
8446 mr r4,r14
8447 mr r5,r15
8448 ld r14,PACA_EXGEN+EX_R14(r13)
8449@@ -767,8 +768,7 @@ storage_fault_common:
8450 cmpdi r3,0
8451 bne- 1f
8452 b .ret_from_except_lite
8453-1: bl .save_nvgprs
8454- mr r5,r3
8455+1: mr r5,r3
8456 addi r3,r1,STACK_FRAME_OVERHEAD
8457 ld r4,_DAR(r1)
8458 bl .bad_page_fault
8459diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8460index 9f905e4..1d6b3d2 100644
8461--- a/arch/powerpc/kernel/exceptions-64s.S
8462+++ b/arch/powerpc/kernel/exceptions-64s.S
8463@@ -1390,10 +1390,10 @@ handle_page_fault:
8464 11: ld r4,_DAR(r1)
8465 ld r5,_DSISR(r1)
8466 addi r3,r1,STACK_FRAME_OVERHEAD
8467+ bl .save_nvgprs
8468 bl .do_page_fault
8469 cmpdi r3,0
8470 beq+ 12f
8471- bl .save_nvgprs
8472 mr r5,r3
8473 addi r3,r1,STACK_FRAME_OVERHEAD
8474 lwz r4,_DAR(r1)
8475diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8476index 6cff040..74ac5d1 100644
8477--- a/arch/powerpc/kernel/module_32.c
8478+++ b/arch/powerpc/kernel/module_32.c
8479@@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8480 me->arch.core_plt_section = i;
8481 }
8482 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8483- printk("Module doesn't contain .plt or .init.plt sections.\n");
8484+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8485 return -ENOEXEC;
8486 }
8487
8488@@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8489
8490 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8491 /* Init, or core PLT? */
8492- if (location >= mod->module_core
8493- && location < mod->module_core + mod->core_size)
8494+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8495+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8496 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8497- else
8498+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8499+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8500 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8501+ else {
8502+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8503+ return ~0UL;
8504+ }
8505
8506 /* Find this entry, or if that fails, the next avail. entry */
8507 while (entry->jump[0]) {
8508@@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8509 }
8510 #ifdef CONFIG_DYNAMIC_FTRACE
8511 module->arch.tramp =
8512- do_plt_call(module->module_core,
8513+ do_plt_call(module->module_core_rx,
8514 (unsigned long)ftrace_caller,
8515 sechdrs, module);
8516 #endif
8517diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8518index ea2f6a3..dbb2be3 100644
8519--- a/arch/powerpc/kernel/process.c
8520+++ b/arch/powerpc/kernel/process.c
8521@@ -888,8 +888,8 @@ void show_regs(struct pt_regs * regs)
8522 * Lookup NIP late so we have the best change of getting the
8523 * above info out without failing
8524 */
8525- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8526- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8527+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8528+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8529 #endif
8530 show_stack(current, (unsigned long *) regs->gpr[1]);
8531 if (!user_mode(regs))
8532@@ -1385,10 +1385,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8533 newsp = stack[0];
8534 ip = stack[STACK_FRAME_LR_SAVE];
8535 if (!firstframe || ip != lr) {
8536- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8537+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8538 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8539 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8540- printk(" (%pS)",
8541+ printk(" (%pA)",
8542 (void *)current->ret_stack[curr_frame].ret);
8543 curr_frame--;
8544 }
8545@@ -1408,7 +1408,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8546 struct pt_regs *regs = (struct pt_regs *)
8547 (sp + STACK_FRAME_OVERHEAD);
8548 lr = regs->link;
8549- printk("--- Exception: %lx at %pS\n LR = %pS\n",
8550+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
8551 regs->trap, (void *)regs->nip, (void *)lr);
8552 firstframe = 1;
8553 }
8554@@ -1444,58 +1444,3 @@ void notrace __ppc64_runlatch_off(void)
8555 mtspr(SPRN_CTRLT, ctrl);
8556 }
8557 #endif /* CONFIG_PPC64 */
8558-
8559-unsigned long arch_align_stack(unsigned long sp)
8560-{
8561- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8562- sp -= get_random_int() & ~PAGE_MASK;
8563- return sp & ~0xf;
8564-}
8565-
8566-static inline unsigned long brk_rnd(void)
8567-{
8568- unsigned long rnd = 0;
8569-
8570- /* 8MB for 32bit, 1GB for 64bit */
8571- if (is_32bit_task())
8572- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8573- else
8574- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8575-
8576- return rnd << PAGE_SHIFT;
8577-}
8578-
8579-unsigned long arch_randomize_brk(struct mm_struct *mm)
8580-{
8581- unsigned long base = mm->brk;
8582- unsigned long ret;
8583-
8584-#ifdef CONFIG_PPC_STD_MMU_64
8585- /*
8586- * If we are using 1TB segments and we are allowed to randomise
8587- * the heap, we can put it above 1TB so it is backed by a 1TB
8588- * segment. Otherwise the heap will be in the bottom 1TB
8589- * which always uses 256MB segments and this may result in a
8590- * performance penalty.
8591- */
8592- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8593- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8594-#endif
8595-
8596- ret = PAGE_ALIGN(base + brk_rnd());
8597-
8598- if (ret < mm->brk)
8599- return mm->brk;
8600-
8601- return ret;
8602-}
8603-
8604-unsigned long randomize_et_dyn(unsigned long base)
8605-{
8606- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8607-
8608- if (ret < base)
8609- return base;
8610-
8611- return ret;
8612-}
8613diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8614index 2e3d2bf..35df241 100644
8615--- a/arch/powerpc/kernel/ptrace.c
8616+++ b/arch/powerpc/kernel/ptrace.c
8617@@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8618 return ret;
8619 }
8620
8621+#ifdef CONFIG_GRKERNSEC_SETXID
8622+extern void gr_delayed_cred_worker(void);
8623+#endif
8624+
8625 /*
8626 * We must return the syscall number to actually look up in the table.
8627 * This can be -1L to skip running any syscall at all.
8628@@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8629
8630 secure_computing_strict(regs->gpr[0]);
8631
8632+#ifdef CONFIG_GRKERNSEC_SETXID
8633+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8634+ gr_delayed_cred_worker();
8635+#endif
8636+
8637 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8638 tracehook_report_syscall_entry(regs))
8639 /*
8640@@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8641 {
8642 int step;
8643
8644+#ifdef CONFIG_GRKERNSEC_SETXID
8645+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8646+ gr_delayed_cred_worker();
8647+#endif
8648+
8649 audit_syscall_exit(regs);
8650
8651 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8652diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8653index 68027bf..b26fd31 100644
8654--- a/arch/powerpc/kernel/signal_32.c
8655+++ b/arch/powerpc/kernel/signal_32.c
8656@@ -1004,7 +1004,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8657 /* Save user registers on the stack */
8658 frame = &rt_sf->uc.uc_mcontext;
8659 addr = frame;
8660- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8661+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8662 sigret = 0;
8663 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8664 } else {
8665diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8666index 448245f..b9bae83 100644
8667--- a/arch/powerpc/kernel/signal_64.c
8668+++ b/arch/powerpc/kernel/signal_64.c
8669@@ -758,7 +758,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8670 #endif
8671
8672 /* Set up to return from userspace. */
8673- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8674+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8675 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8676 } else {
8677 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8678diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8679index 907a472..4ba206f 100644
8680--- a/arch/powerpc/kernel/traps.c
8681+++ b/arch/powerpc/kernel/traps.c
8682@@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8683 return flags;
8684 }
8685
8686+extern void gr_handle_kernel_exploit(void);
8687+
8688 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8689 int signr)
8690 {
8691@@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8692 panic("Fatal exception in interrupt");
8693 if (panic_on_oops)
8694 panic("Fatal exception");
8695+
8696+ gr_handle_kernel_exploit();
8697+
8698 do_exit(signr);
8699 }
8700
8701diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8702index 094e45c..d82b848 100644
8703--- a/arch/powerpc/kernel/vdso.c
8704+++ b/arch/powerpc/kernel/vdso.c
8705@@ -35,6 +35,7 @@
8706 #include <asm/vdso.h>
8707 #include <asm/vdso_datapage.h>
8708 #include <asm/setup.h>
8709+#include <asm/mman.h>
8710
8711 #undef DEBUG
8712
8713@@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8714 vdso_base = VDSO32_MBASE;
8715 #endif
8716
8717- current->mm->context.vdso_base = 0;
8718+ current->mm->context.vdso_base = ~0UL;
8719
8720 /* vDSO has a problem and was disabled, just don't "enable" it for the
8721 * process
8722@@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8723 vdso_base = get_unmapped_area(NULL, vdso_base,
8724 (vdso_pages << PAGE_SHIFT) +
8725 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8726- 0, 0);
8727+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8728 if (IS_ERR_VALUE(vdso_base)) {
8729 rc = vdso_base;
8730 goto fail_mmapsem;
8731diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
8732index 9ae9768..87c3448 100644
8733--- a/arch/powerpc/kvm/powerpc.c
8734+++ b/arch/powerpc/kvm/powerpc.c
8735@@ -1141,7 +1141,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
8736 }
8737 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
8738
8739-int kvm_arch_init(void *opaque)
8740+int kvm_arch_init(const void *opaque)
8741 {
8742 return 0;
8743 }
8744diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8745index 5eea6f3..5d10396 100644
8746--- a/arch/powerpc/lib/usercopy_64.c
8747+++ b/arch/powerpc/lib/usercopy_64.c
8748@@ -9,22 +9,6 @@
8749 #include <linux/module.h>
8750 #include <asm/uaccess.h>
8751
8752-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8753-{
8754- if (likely(access_ok(VERIFY_READ, from, n)))
8755- n = __copy_from_user(to, from, n);
8756- else
8757- memset(to, 0, n);
8758- return n;
8759-}
8760-
8761-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8762-{
8763- if (likely(access_ok(VERIFY_WRITE, to, n)))
8764- n = __copy_to_user(to, from, n);
8765- return n;
8766-}
8767-
8768 unsigned long copy_in_user(void __user *to, const void __user *from,
8769 unsigned long n)
8770 {
8771@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8772 return n;
8773 }
8774
8775-EXPORT_SYMBOL(copy_from_user);
8776-EXPORT_SYMBOL(copy_to_user);
8777 EXPORT_SYMBOL(copy_in_user);
8778
8779diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8780index 51ab9e7..7d3c78b 100644
8781--- a/arch/powerpc/mm/fault.c
8782+++ b/arch/powerpc/mm/fault.c
8783@@ -33,6 +33,10 @@
8784 #include <linux/magic.h>
8785 #include <linux/ratelimit.h>
8786 #include <linux/context_tracking.h>
8787+#include <linux/slab.h>
8788+#include <linux/pagemap.h>
8789+#include <linux/compiler.h>
8790+#include <linux/unistd.h>
8791
8792 #include <asm/firmware.h>
8793 #include <asm/page.h>
8794@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8795 }
8796 #endif
8797
8798+#ifdef CONFIG_PAX_PAGEEXEC
8799+/*
8800+ * PaX: decide what to do with offenders (regs->nip = fault address)
8801+ *
8802+ * returns 1 when task should be killed
8803+ */
8804+static int pax_handle_fetch_fault(struct pt_regs *regs)
8805+{
8806+ return 1;
8807+}
8808+
8809+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8810+{
8811+ unsigned long i;
8812+
8813+ printk(KERN_ERR "PAX: bytes at PC: ");
8814+ for (i = 0; i < 5; i++) {
8815+ unsigned int c;
8816+ if (get_user(c, (unsigned int __user *)pc+i))
8817+ printk(KERN_CONT "???????? ");
8818+ else
8819+ printk(KERN_CONT "%08x ", c);
8820+ }
8821+ printk("\n");
8822+}
8823+#endif
8824+
8825 /*
8826 * Check whether the instruction at regs->nip is a store using
8827 * an update addressing form which will update r1.
8828@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8829 * indicate errors in DSISR but can validly be set in SRR1.
8830 */
8831 if (trap == 0x400)
8832- error_code &= 0x48200000;
8833+ error_code &= 0x58200000;
8834 else
8835 is_write = error_code & DSISR_ISSTORE;
8836 #else
8837@@ -378,7 +409,7 @@ good_area:
8838 * "undefined". Of those that can be set, this is the only
8839 * one which seems bad.
8840 */
8841- if (error_code & 0x10000000)
8842+ if (error_code & DSISR_GUARDED)
8843 /* Guarded storage error. */
8844 goto bad_area;
8845 #endif /* CONFIG_8xx */
8846@@ -393,7 +424,7 @@ good_area:
8847 * processors use the same I/D cache coherency mechanism
8848 * as embedded.
8849 */
8850- if (error_code & DSISR_PROTFAULT)
8851+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8852 goto bad_area;
8853 #endif /* CONFIG_PPC_STD_MMU */
8854
8855@@ -483,6 +514,23 @@ bad_area:
8856 bad_area_nosemaphore:
8857 /* User mode accesses cause a SIGSEGV */
8858 if (user_mode(regs)) {
8859+
8860+#ifdef CONFIG_PAX_PAGEEXEC
8861+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8862+#ifdef CONFIG_PPC_STD_MMU
8863+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8864+#else
8865+ if (is_exec && regs->nip == address) {
8866+#endif
8867+ switch (pax_handle_fetch_fault(regs)) {
8868+ }
8869+
8870+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8871+ do_group_exit(SIGKILL);
8872+ }
8873+ }
8874+#endif
8875+
8876 _exception(SIGSEGV, regs, code, address);
8877 goto bail;
8878 }
8879diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8880index cb8bdbe..cde4bc7 100644
8881--- a/arch/powerpc/mm/mmap.c
8882+++ b/arch/powerpc/mm/mmap.c
8883@@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
8884 return sysctl_legacy_va_layout;
8885 }
8886
8887-static unsigned long mmap_rnd(void)
8888+static unsigned long mmap_rnd(struct mm_struct *mm)
8889 {
8890 unsigned long rnd = 0;
8891
8892+#ifdef CONFIG_PAX_RANDMMAP
8893+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8894+#endif
8895+
8896 if (current->flags & PF_RANDOMIZE) {
8897 /* 8MB for 32bit, 1GB for 64bit */
8898 if (is_32bit_task())
8899@@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
8900 return rnd << PAGE_SHIFT;
8901 }
8902
8903-static inline unsigned long mmap_base(void)
8904+static inline unsigned long mmap_base(struct mm_struct *mm)
8905 {
8906 unsigned long gap = rlimit(RLIMIT_STACK);
8907
8908@@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
8909 else if (gap > MAX_GAP)
8910 gap = MAX_GAP;
8911
8912- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
8913+ return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
8914 }
8915
8916 /*
8917@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8918 */
8919 if (mmap_is_legacy()) {
8920 mm->mmap_base = TASK_UNMAPPED_BASE;
8921+
8922+#ifdef CONFIG_PAX_RANDMMAP
8923+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8924+ mm->mmap_base += mm->delta_mmap;
8925+#endif
8926+
8927 mm->get_unmapped_area = arch_get_unmapped_area;
8928 } else {
8929- mm->mmap_base = mmap_base();
8930+ mm->mmap_base = mmap_base(mm);
8931+
8932+#ifdef CONFIG_PAX_RANDMMAP
8933+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8934+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8935+#endif
8936+
8937 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8938 }
8939 }
8940diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8941index 7ce9cf3..a964087 100644
8942--- a/arch/powerpc/mm/slice.c
8943+++ b/arch/powerpc/mm/slice.c
8944@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8945 if ((mm->task_size - len) < addr)
8946 return 0;
8947 vma = find_vma(mm, addr);
8948- return (!vma || (addr + len) <= vma->vm_start);
8949+ return check_heap_stack_gap(vma, addr, len, 0);
8950 }
8951
8952 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8953@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8954 info.align_offset = 0;
8955
8956 addr = TASK_UNMAPPED_BASE;
8957+
8958+#ifdef CONFIG_PAX_RANDMMAP
8959+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8960+ addr += mm->delta_mmap;
8961+#endif
8962+
8963 while (addr < TASK_SIZE) {
8964 info.low_limit = addr;
8965 if (!slice_scan_available(addr, available, 1, &addr))
8966@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8967 if (fixed && addr > (mm->task_size - len))
8968 return -EINVAL;
8969
8970+#ifdef CONFIG_PAX_RANDMMAP
8971+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8972+ addr = 0;
8973+#endif
8974+
8975 /* If hint, make sure it matches our alignment restrictions */
8976 if (!fixed && addr) {
8977 addr = _ALIGN_UP(addr, 1ul << pshift);
8978diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8979index 4278acf..67fd0e6 100644
8980--- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8981+++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8982@@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
8983 }
8984
8985 static struct pci_ops scc_pciex_pci_ops = {
8986- scc_pciex_read_config,
8987- scc_pciex_write_config,
8988+ .read = scc_pciex_read_config,
8989+ .write = scc_pciex_write_config,
8990 };
8991
8992 static void pciex_clear_intr_all(unsigned int __iomem *base)
8993diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8994index 9098692..3d54cd1 100644
8995--- a/arch/powerpc/platforms/cell/spufs/file.c
8996+++ b/arch/powerpc/platforms/cell/spufs/file.c
8997@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8998 return VM_FAULT_NOPAGE;
8999 }
9000
9001-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9002+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9003 unsigned long address,
9004- void *buf, int len, int write)
9005+ void *buf, size_t len, int write)
9006 {
9007 struct spu_context *ctx = vma->vm_file->private_data;
9008 unsigned long offset = address - vma->vm_start;
9009diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9010index fa9aaf7..3f5d836 100644
9011--- a/arch/s390/include/asm/atomic.h
9012+++ b/arch/s390/include/asm/atomic.h
9013@@ -398,6 +398,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9014 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9015 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9016
9017+#define atomic64_read_unchecked(v) atomic64_read(v)
9018+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9019+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9020+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9021+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9022+#define atomic64_inc_unchecked(v) atomic64_inc(v)
9023+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9024+#define atomic64_dec_unchecked(v) atomic64_dec(v)
9025+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9026+
9027 #define smp_mb__before_atomic_dec() smp_mb()
9028 #define smp_mb__after_atomic_dec() smp_mb()
9029 #define smp_mb__before_atomic_inc() smp_mb()
9030diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9031index 4d7ccac..d03d0ad 100644
9032--- a/arch/s390/include/asm/cache.h
9033+++ b/arch/s390/include/asm/cache.h
9034@@ -9,8 +9,10 @@
9035 #ifndef __ARCH_S390_CACHE_H
9036 #define __ARCH_S390_CACHE_H
9037
9038-#define L1_CACHE_BYTES 256
9039+#include <linux/const.h>
9040+
9041 #define L1_CACHE_SHIFT 8
9042+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9043 #define NET_SKB_PAD 32
9044
9045 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9046diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9047index 78f4f87..598ce39 100644
9048--- a/arch/s390/include/asm/elf.h
9049+++ b/arch/s390/include/asm/elf.h
9050@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9051 the loader. We need to make sure that it is out of the way of the program
9052 that it will "exec", and that there is sufficient room for the brk. */
9053
9054-extern unsigned long randomize_et_dyn(unsigned long base);
9055-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9056+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9057+
9058+#ifdef CONFIG_PAX_ASLR
9059+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9060+
9061+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9062+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9063+#endif
9064
9065 /* This yields a mask that user programs can use to figure out what
9066 instruction set this CPU supports. */
9067@@ -222,9 +228,6 @@ struct linux_binprm;
9068 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9069 int arch_setup_additional_pages(struct linux_binprm *, int);
9070
9071-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9072-#define arch_randomize_brk arch_randomize_brk
9073-
9074 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9075
9076 #endif
9077diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9078index c4a93d6..4d2a9b4 100644
9079--- a/arch/s390/include/asm/exec.h
9080+++ b/arch/s390/include/asm/exec.h
9081@@ -7,6 +7,6 @@
9082 #ifndef __ASM_EXEC_H
9083 #define __ASM_EXEC_H
9084
9085-extern unsigned long arch_align_stack(unsigned long sp);
9086+#define arch_align_stack(x) ((x) & ~0xfUL)
9087
9088 #endif /* __ASM_EXEC_H */
9089diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9090index 79330af..254cf37 100644
9091--- a/arch/s390/include/asm/uaccess.h
9092+++ b/arch/s390/include/asm/uaccess.h
9093@@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9094 __range_ok((unsigned long)(addr), (size)); \
9095 })
9096
9097+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9098 #define access_ok(type, addr, size) __access_ok(addr, size)
9099
9100 /*
9101@@ -245,6 +246,10 @@ static inline unsigned long __must_check
9102 copy_to_user(void __user *to, const void *from, unsigned long n)
9103 {
9104 might_fault();
9105+
9106+ if ((long)n < 0)
9107+ return n;
9108+
9109 return __copy_to_user(to, from, n);
9110 }
9111
9112@@ -268,6 +273,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
9113 static inline unsigned long __must_check
9114 __copy_from_user(void *to, const void __user *from, unsigned long n)
9115 {
9116+ if ((long)n < 0)
9117+ return n;
9118+
9119 return uaccess.copy_from_user(n, from, to);
9120 }
9121
9122@@ -296,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9123 static inline unsigned long __must_check
9124 copy_from_user(void *to, const void __user *from, unsigned long n)
9125 {
9126- unsigned int sz = __compiletime_object_size(to);
9127+ size_t sz = __compiletime_object_size(to);
9128
9129 might_fault();
9130- if (unlikely(sz != -1 && sz < n)) {
9131+
9132+ if ((long)n < 0)
9133+ return n;
9134+
9135+ if (unlikely(sz != (size_t)-1 && sz < n)) {
9136 copy_from_user_overflow();
9137 return n;
9138 }
9139diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9140index b89b591..fd9609d 100644
9141--- a/arch/s390/kernel/module.c
9142+++ b/arch/s390/kernel/module.c
9143@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9144
9145 /* Increase core size by size of got & plt and set start
9146 offsets for got and plt. */
9147- me->core_size = ALIGN(me->core_size, 4);
9148- me->arch.got_offset = me->core_size;
9149- me->core_size += me->arch.got_size;
9150- me->arch.plt_offset = me->core_size;
9151- me->core_size += me->arch.plt_size;
9152+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
9153+ me->arch.got_offset = me->core_size_rw;
9154+ me->core_size_rw += me->arch.got_size;
9155+ me->arch.plt_offset = me->core_size_rx;
9156+ me->core_size_rx += me->arch.plt_size;
9157 return 0;
9158 }
9159
9160@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9161 if (info->got_initialized == 0) {
9162 Elf_Addr *gotent;
9163
9164- gotent = me->module_core + me->arch.got_offset +
9165+ gotent = me->module_core_rw + me->arch.got_offset +
9166 info->got_offset;
9167 *gotent = val;
9168 info->got_initialized = 1;
9169@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9170 rc = apply_rela_bits(loc, val, 0, 64, 0);
9171 else if (r_type == R_390_GOTENT ||
9172 r_type == R_390_GOTPLTENT) {
9173- val += (Elf_Addr) me->module_core - loc;
9174+ val += (Elf_Addr) me->module_core_rw - loc;
9175 rc = apply_rela_bits(loc, val, 1, 32, 1);
9176 }
9177 break;
9178@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9179 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9180 if (info->plt_initialized == 0) {
9181 unsigned int *ip;
9182- ip = me->module_core + me->arch.plt_offset +
9183+ ip = me->module_core_rx + me->arch.plt_offset +
9184 info->plt_offset;
9185 #ifndef CONFIG_64BIT
9186 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9187@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9188 val - loc + 0xffffUL < 0x1ffffeUL) ||
9189 (r_type == R_390_PLT32DBL &&
9190 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9191- val = (Elf_Addr) me->module_core +
9192+ val = (Elf_Addr) me->module_core_rx +
9193 me->arch.plt_offset +
9194 info->plt_offset;
9195 val += rela->r_addend - loc;
9196@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9197 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9198 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9199 val = val + rela->r_addend -
9200- ((Elf_Addr) me->module_core + me->arch.got_offset);
9201+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9202 if (r_type == R_390_GOTOFF16)
9203 rc = apply_rela_bits(loc, val, 0, 16, 0);
9204 else if (r_type == R_390_GOTOFF32)
9205@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9206 break;
9207 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9208 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9209- val = (Elf_Addr) me->module_core + me->arch.got_offset +
9210+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9211 rela->r_addend - loc;
9212 if (r_type == R_390_GOTPC)
9213 rc = apply_rela_bits(loc, val, 1, 32, 0);
9214diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9215index 7ed0d4e..1dfc145 100644
9216--- a/arch/s390/kernel/process.c
9217+++ b/arch/s390/kernel/process.c
9218@@ -242,39 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9219 }
9220 return 0;
9221 }
9222-
9223-unsigned long arch_align_stack(unsigned long sp)
9224-{
9225- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9226- sp -= get_random_int() & ~PAGE_MASK;
9227- return sp & ~0xf;
9228-}
9229-
9230-static inline unsigned long brk_rnd(void)
9231-{
9232- /* 8MB for 32bit, 1GB for 64bit */
9233- if (is_32bit_task())
9234- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9235- else
9236- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9237-}
9238-
9239-unsigned long arch_randomize_brk(struct mm_struct *mm)
9240-{
9241- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
9242-
9243- if (ret < mm->brk)
9244- return mm->brk;
9245- return ret;
9246-}
9247-
9248-unsigned long randomize_et_dyn(unsigned long base)
9249-{
9250- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
9251-
9252- if (!(current->flags & PF_RANDOMIZE))
9253- return base;
9254- if (ret < base)
9255- return base;
9256- return ret;
9257-}
9258diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9259index 9b436c2..54fbf0a 100644
9260--- a/arch/s390/mm/mmap.c
9261+++ b/arch/s390/mm/mmap.c
9262@@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9263 */
9264 if (mmap_is_legacy()) {
9265 mm->mmap_base = mmap_base_legacy();
9266+
9267+#ifdef CONFIG_PAX_RANDMMAP
9268+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9269+ mm->mmap_base += mm->delta_mmap;
9270+#endif
9271+
9272 mm->get_unmapped_area = arch_get_unmapped_area;
9273 } else {
9274 mm->mmap_base = mmap_base();
9275+
9276+#ifdef CONFIG_PAX_RANDMMAP
9277+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9278+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9279+#endif
9280+
9281 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9282 }
9283 }
9284@@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9285 */
9286 if (mmap_is_legacy()) {
9287 mm->mmap_base = mmap_base_legacy();
9288+
9289+#ifdef CONFIG_PAX_RANDMMAP
9290+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9291+ mm->mmap_base += mm->delta_mmap;
9292+#endif
9293+
9294 mm->get_unmapped_area = s390_get_unmapped_area;
9295 } else {
9296 mm->mmap_base = mmap_base();
9297+
9298+#ifdef CONFIG_PAX_RANDMMAP
9299+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9300+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9301+#endif
9302+
9303 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9304 }
9305 }
9306diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9307index ae3d59f..f65f075 100644
9308--- a/arch/score/include/asm/cache.h
9309+++ b/arch/score/include/asm/cache.h
9310@@ -1,7 +1,9 @@
9311 #ifndef _ASM_SCORE_CACHE_H
9312 #define _ASM_SCORE_CACHE_H
9313
9314+#include <linux/const.h>
9315+
9316 #define L1_CACHE_SHIFT 4
9317-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9318+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9319
9320 #endif /* _ASM_SCORE_CACHE_H */
9321diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9322index f9f3cd5..58ff438 100644
9323--- a/arch/score/include/asm/exec.h
9324+++ b/arch/score/include/asm/exec.h
9325@@ -1,6 +1,6 @@
9326 #ifndef _ASM_SCORE_EXEC_H
9327 #define _ASM_SCORE_EXEC_H
9328
9329-extern unsigned long arch_align_stack(unsigned long sp);
9330+#define arch_align_stack(x) (x)
9331
9332 #endif /* _ASM_SCORE_EXEC_H */
9333diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9334index a1519ad3..e8ac1ff 100644
9335--- a/arch/score/kernel/process.c
9336+++ b/arch/score/kernel/process.c
9337@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9338
9339 return task_pt_regs(task)->cp0_epc;
9340 }
9341-
9342-unsigned long arch_align_stack(unsigned long sp)
9343-{
9344- return sp;
9345-}
9346diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9347index ef9e555..331bd29 100644
9348--- a/arch/sh/include/asm/cache.h
9349+++ b/arch/sh/include/asm/cache.h
9350@@ -9,10 +9,11 @@
9351 #define __ASM_SH_CACHE_H
9352 #ifdef __KERNEL__
9353
9354+#include <linux/const.h>
9355 #include <linux/init.h>
9356 #include <cpu/cache.h>
9357
9358-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9359+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9360
9361 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9362
9363diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9364index 6777177..cb5e44f 100644
9365--- a/arch/sh/mm/mmap.c
9366+++ b/arch/sh/mm/mmap.c
9367@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9368 struct mm_struct *mm = current->mm;
9369 struct vm_area_struct *vma;
9370 int do_colour_align;
9371+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9372 struct vm_unmapped_area_info info;
9373
9374 if (flags & MAP_FIXED) {
9375@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9376 if (filp || (flags & MAP_SHARED))
9377 do_colour_align = 1;
9378
9379+#ifdef CONFIG_PAX_RANDMMAP
9380+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9381+#endif
9382+
9383 if (addr) {
9384 if (do_colour_align)
9385 addr = COLOUR_ALIGN(addr, pgoff);
9386@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9387 addr = PAGE_ALIGN(addr);
9388
9389 vma = find_vma(mm, addr);
9390- if (TASK_SIZE - len >= addr &&
9391- (!vma || addr + len <= vma->vm_start))
9392+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9393 return addr;
9394 }
9395
9396 info.flags = 0;
9397 info.length = len;
9398- info.low_limit = TASK_UNMAPPED_BASE;
9399+ info.low_limit = mm->mmap_base;
9400 info.high_limit = TASK_SIZE;
9401 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9402 info.align_offset = pgoff << PAGE_SHIFT;
9403@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9404 struct mm_struct *mm = current->mm;
9405 unsigned long addr = addr0;
9406 int do_colour_align;
9407+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9408 struct vm_unmapped_area_info info;
9409
9410 if (flags & MAP_FIXED) {
9411@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9412 if (filp || (flags & MAP_SHARED))
9413 do_colour_align = 1;
9414
9415+#ifdef CONFIG_PAX_RANDMMAP
9416+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9417+#endif
9418+
9419 /* requesting a specific address */
9420 if (addr) {
9421 if (do_colour_align)
9422@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9423 addr = PAGE_ALIGN(addr);
9424
9425 vma = find_vma(mm, addr);
9426- if (TASK_SIZE - len >= addr &&
9427- (!vma || addr + len <= vma->vm_start))
9428+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9429 return addr;
9430 }
9431
9432@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9433 VM_BUG_ON(addr != -ENOMEM);
9434 info.flags = 0;
9435 info.low_limit = TASK_UNMAPPED_BASE;
9436+
9437+#ifdef CONFIG_PAX_RANDMMAP
9438+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9439+ info.low_limit += mm->delta_mmap;
9440+#endif
9441+
9442 info.high_limit = TASK_SIZE;
9443 addr = vm_unmapped_area(&info);
9444 }
9445diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9446index be56a24..443328f 100644
9447--- a/arch/sparc/include/asm/atomic_64.h
9448+++ b/arch/sparc/include/asm/atomic_64.h
9449@@ -14,18 +14,40 @@
9450 #define ATOMIC64_INIT(i) { (i) }
9451
9452 #define atomic_read(v) (*(volatile int *)&(v)->counter)
9453+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9454+{
9455+ return v->counter;
9456+}
9457 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
9458+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9459+{
9460+ return v->counter;
9461+}
9462
9463 #define atomic_set(v, i) (((v)->counter) = i)
9464+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9465+{
9466+ v->counter = i;
9467+}
9468 #define atomic64_set(v, i) (((v)->counter) = i)
9469+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9470+{
9471+ v->counter = i;
9472+}
9473
9474 extern void atomic_add(int, atomic_t *);
9475+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9476 extern void atomic64_add(long, atomic64_t *);
9477+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9478 extern void atomic_sub(int, atomic_t *);
9479+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9480 extern void atomic64_sub(long, atomic64_t *);
9481+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9482
9483 extern int atomic_add_ret(int, atomic_t *);
9484+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9485 extern long atomic64_add_ret(long, atomic64_t *);
9486+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9487 extern int atomic_sub_ret(int, atomic_t *);
9488 extern long atomic64_sub_ret(long, atomic64_t *);
9489
9490@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9491 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9492
9493 #define atomic_inc_return(v) atomic_add_ret(1, v)
9494+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9495+{
9496+ return atomic_add_ret_unchecked(1, v);
9497+}
9498 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9499+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9500+{
9501+ return atomic64_add_ret_unchecked(1, v);
9502+}
9503
9504 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9505 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9506
9507 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9508+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9509+{
9510+ return atomic_add_ret_unchecked(i, v);
9511+}
9512 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9513+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9514+{
9515+ return atomic64_add_ret_unchecked(i, v);
9516+}
9517
9518 /*
9519 * atomic_inc_and_test - increment and test
9520@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9521 * other cases.
9522 */
9523 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9524+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9525+{
9526+ return atomic_inc_return_unchecked(v) == 0;
9527+}
9528 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9529
9530 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9531@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9532 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9533
9534 #define atomic_inc(v) atomic_add(1, v)
9535+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9536+{
9537+ atomic_add_unchecked(1, v);
9538+}
9539 #define atomic64_inc(v) atomic64_add(1, v)
9540+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9541+{
9542+ atomic64_add_unchecked(1, v);
9543+}
9544
9545 #define atomic_dec(v) atomic_sub(1, v)
9546+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9547+{
9548+ atomic_sub_unchecked(1, v);
9549+}
9550 #define atomic64_dec(v) atomic64_sub(1, v)
9551+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9552+{
9553+ atomic64_sub_unchecked(1, v);
9554+}
9555
9556 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9557 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9558
9559 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9560+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9561+{
9562+ return cmpxchg(&v->counter, old, new);
9563+}
9564 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9565+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9566+{
9567+ return xchg(&v->counter, new);
9568+}
9569
9570 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9571 {
9572- int c, old;
9573+ int c, old, new;
9574 c = atomic_read(v);
9575 for (;;) {
9576- if (unlikely(c == (u)))
9577+ if (unlikely(c == u))
9578 break;
9579- old = atomic_cmpxchg((v), c, c + (a));
9580+
9581+ asm volatile("addcc %2, %0, %0\n"
9582+
9583+#ifdef CONFIG_PAX_REFCOUNT
9584+ "tvs %%icc, 6\n"
9585+#endif
9586+
9587+ : "=r" (new)
9588+ : "0" (c), "ir" (a)
9589+ : "cc");
9590+
9591+ old = atomic_cmpxchg(v, c, new);
9592 if (likely(old == c))
9593 break;
9594 c = old;
9595@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9596 #define atomic64_cmpxchg(v, o, n) \
9597 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9598 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9599+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9600+{
9601+ return xchg(&v->counter, new);
9602+}
9603
9604 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9605 {
9606- long c, old;
9607+ long c, old, new;
9608 c = atomic64_read(v);
9609 for (;;) {
9610- if (unlikely(c == (u)))
9611+ if (unlikely(c == u))
9612 break;
9613- old = atomic64_cmpxchg((v), c, c + (a));
9614+
9615+ asm volatile("addcc %2, %0, %0\n"
9616+
9617+#ifdef CONFIG_PAX_REFCOUNT
9618+ "tvs %%xcc, 6\n"
9619+#endif
9620+
9621+ : "=r" (new)
9622+ : "0" (c), "ir" (a)
9623+ : "cc");
9624+
9625+ old = atomic64_cmpxchg(v, c, new);
9626 if (likely(old == c))
9627 break;
9628 c = old;
9629 }
9630- return c != (u);
9631+ return c != u;
9632 }
9633
9634 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9635diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9636index 5bb6991..5c2132e 100644
9637--- a/arch/sparc/include/asm/cache.h
9638+++ b/arch/sparc/include/asm/cache.h
9639@@ -7,10 +7,12 @@
9640 #ifndef _SPARC_CACHE_H
9641 #define _SPARC_CACHE_H
9642
9643+#include <linux/const.h>
9644+
9645 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9646
9647 #define L1_CACHE_SHIFT 5
9648-#define L1_CACHE_BYTES 32
9649+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9650
9651 #ifdef CONFIG_SPARC32
9652 #define SMP_CACHE_BYTES_SHIFT 5
9653diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9654index a24e41f..47677ff 100644
9655--- a/arch/sparc/include/asm/elf_32.h
9656+++ b/arch/sparc/include/asm/elf_32.h
9657@@ -114,6 +114,13 @@ typedef struct {
9658
9659 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9660
9661+#ifdef CONFIG_PAX_ASLR
9662+#define PAX_ELF_ET_DYN_BASE 0x10000UL
9663+
9664+#define PAX_DELTA_MMAP_LEN 16
9665+#define PAX_DELTA_STACK_LEN 16
9666+#endif
9667+
9668 /* This yields a mask that user programs can use to figure out what
9669 instruction set this cpu supports. This can NOT be done in userspace
9670 on Sparc. */
9671diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9672index 370ca1e..d4f4a98 100644
9673--- a/arch/sparc/include/asm/elf_64.h
9674+++ b/arch/sparc/include/asm/elf_64.h
9675@@ -189,6 +189,13 @@ typedef struct {
9676 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9677 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9678
9679+#ifdef CONFIG_PAX_ASLR
9680+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9681+
9682+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9683+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9684+#endif
9685+
9686 extern unsigned long sparc64_elf_hwcap;
9687 #define ELF_HWCAP sparc64_elf_hwcap
9688
9689diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9690index 9b1c36d..209298b 100644
9691--- a/arch/sparc/include/asm/pgalloc_32.h
9692+++ b/arch/sparc/include/asm/pgalloc_32.h
9693@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9694 }
9695
9696 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9697+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9698
9699 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9700 unsigned long address)
9701diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9702index bcfe063..b333142 100644
9703--- a/arch/sparc/include/asm/pgalloc_64.h
9704+++ b/arch/sparc/include/asm/pgalloc_64.h
9705@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9706 }
9707
9708 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9709+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9710
9711 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9712 {
9713diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
9714index 59ba6f6..4518128 100644
9715--- a/arch/sparc/include/asm/pgtable.h
9716+++ b/arch/sparc/include/asm/pgtable.h
9717@@ -5,4 +5,8 @@
9718 #else
9719 #include <asm/pgtable_32.h>
9720 #endif
9721+
9722+#define ktla_ktva(addr) (addr)
9723+#define ktva_ktla(addr) (addr)
9724+
9725 #endif
9726diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9727index 502f632..da1917f 100644
9728--- a/arch/sparc/include/asm/pgtable_32.h
9729+++ b/arch/sparc/include/asm/pgtable_32.h
9730@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9731 #define PAGE_SHARED SRMMU_PAGE_SHARED
9732 #define PAGE_COPY SRMMU_PAGE_COPY
9733 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9734+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9735+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9736+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9737 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9738
9739 /* Top-level page directory - dummy used by init-mm.
9740@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9741
9742 /* xwr */
9743 #define __P000 PAGE_NONE
9744-#define __P001 PAGE_READONLY
9745-#define __P010 PAGE_COPY
9746-#define __P011 PAGE_COPY
9747+#define __P001 PAGE_READONLY_NOEXEC
9748+#define __P010 PAGE_COPY_NOEXEC
9749+#define __P011 PAGE_COPY_NOEXEC
9750 #define __P100 PAGE_READONLY
9751 #define __P101 PAGE_READONLY
9752 #define __P110 PAGE_COPY
9753 #define __P111 PAGE_COPY
9754
9755 #define __S000 PAGE_NONE
9756-#define __S001 PAGE_READONLY
9757-#define __S010 PAGE_SHARED
9758-#define __S011 PAGE_SHARED
9759+#define __S001 PAGE_READONLY_NOEXEC
9760+#define __S010 PAGE_SHARED_NOEXEC
9761+#define __S011 PAGE_SHARED_NOEXEC
9762 #define __S100 PAGE_READONLY
9763 #define __S101 PAGE_READONLY
9764 #define __S110 PAGE_SHARED
9765diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9766index 79da178..c2eede8 100644
9767--- a/arch/sparc/include/asm/pgtsrmmu.h
9768+++ b/arch/sparc/include/asm/pgtsrmmu.h
9769@@ -115,6 +115,11 @@
9770 SRMMU_EXEC | SRMMU_REF)
9771 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9772 SRMMU_EXEC | SRMMU_REF)
9773+
9774+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9775+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9776+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9777+
9778 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9779 SRMMU_DIRTY | SRMMU_REF)
9780
9781diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9782index 9689176..63c18ea 100644
9783--- a/arch/sparc/include/asm/spinlock_64.h
9784+++ b/arch/sparc/include/asm/spinlock_64.h
9785@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9786
9787 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9788
9789-static void inline arch_read_lock(arch_rwlock_t *lock)
9790+static inline void arch_read_lock(arch_rwlock_t *lock)
9791 {
9792 unsigned long tmp1, tmp2;
9793
9794 __asm__ __volatile__ (
9795 "1: ldsw [%2], %0\n"
9796 " brlz,pn %0, 2f\n"
9797-"4: add %0, 1, %1\n"
9798+"4: addcc %0, 1, %1\n"
9799+
9800+#ifdef CONFIG_PAX_REFCOUNT
9801+" tvs %%icc, 6\n"
9802+#endif
9803+
9804 " cas [%2], %0, %1\n"
9805 " cmp %0, %1\n"
9806 " bne,pn %%icc, 1b\n"
9807@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9808 " .previous"
9809 : "=&r" (tmp1), "=&r" (tmp2)
9810 : "r" (lock)
9811- : "memory");
9812+ : "memory", "cc");
9813 }
9814
9815-static int inline arch_read_trylock(arch_rwlock_t *lock)
9816+static inline int arch_read_trylock(arch_rwlock_t *lock)
9817 {
9818 int tmp1, tmp2;
9819
9820@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9821 "1: ldsw [%2], %0\n"
9822 " brlz,a,pn %0, 2f\n"
9823 " mov 0, %0\n"
9824-" add %0, 1, %1\n"
9825+" addcc %0, 1, %1\n"
9826+
9827+#ifdef CONFIG_PAX_REFCOUNT
9828+" tvs %%icc, 6\n"
9829+#endif
9830+
9831 " cas [%2], %0, %1\n"
9832 " cmp %0, %1\n"
9833 " bne,pn %%icc, 1b\n"
9834@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9835 return tmp1;
9836 }
9837
9838-static void inline arch_read_unlock(arch_rwlock_t *lock)
9839+static inline void arch_read_unlock(arch_rwlock_t *lock)
9840 {
9841 unsigned long tmp1, tmp2;
9842
9843 __asm__ __volatile__(
9844 "1: lduw [%2], %0\n"
9845-" sub %0, 1, %1\n"
9846+" subcc %0, 1, %1\n"
9847+
9848+#ifdef CONFIG_PAX_REFCOUNT
9849+" tvs %%icc, 6\n"
9850+#endif
9851+
9852 " cas [%2], %0, %1\n"
9853 " cmp %0, %1\n"
9854 " bne,pn %%xcc, 1b\n"
9855@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9856 : "memory");
9857 }
9858
9859-static void inline arch_write_lock(arch_rwlock_t *lock)
9860+static inline void arch_write_lock(arch_rwlock_t *lock)
9861 {
9862 unsigned long mask, tmp1, tmp2;
9863
9864@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9865 : "memory");
9866 }
9867
9868-static void inline arch_write_unlock(arch_rwlock_t *lock)
9869+static inline void arch_write_unlock(arch_rwlock_t *lock)
9870 {
9871 __asm__ __volatile__(
9872 " stw %%g0, [%0]"
9873@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9874 : "memory");
9875 }
9876
9877-static int inline arch_write_trylock(arch_rwlock_t *lock)
9878+static inline int arch_write_trylock(arch_rwlock_t *lock)
9879 {
9880 unsigned long mask, tmp1, tmp2, result;
9881
9882diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9883index 96efa7a..16858bf 100644
9884--- a/arch/sparc/include/asm/thread_info_32.h
9885+++ b/arch/sparc/include/asm/thread_info_32.h
9886@@ -49,6 +49,8 @@ struct thread_info {
9887 unsigned long w_saved;
9888
9889 struct restart_block restart_block;
9890+
9891+ unsigned long lowest_stack;
9892 };
9893
9894 /*
9895diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9896index a5f01ac..703b554 100644
9897--- a/arch/sparc/include/asm/thread_info_64.h
9898+++ b/arch/sparc/include/asm/thread_info_64.h
9899@@ -63,6 +63,8 @@ struct thread_info {
9900 struct pt_regs *kern_una_regs;
9901 unsigned int kern_una_insn;
9902
9903+ unsigned long lowest_stack;
9904+
9905 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9906 };
9907
9908@@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
9909 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
9910 /* flag bit 4 is available */
9911 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9912-/* flag bit 6 is available */
9913+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
9914 #define TIF_32BIT 7 /* 32-bit binary */
9915 #define TIF_NOHZ 8 /* in adaptive nohz mode */
9916 #define TIF_SECCOMP 9 /* secure computing */
9917 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9918 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9919+
9920 /* NOTE: Thread flags >= 12 should be ones we have no interest
9921 * in using in assembly, else we can't use the mask as
9922 * an immediate value in instructions such as andcc.
9923@@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9924 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9925 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9926 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9927+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9928
9929 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9930 _TIF_DO_NOTIFY_RESUME_MASK | \
9931 _TIF_NEED_RESCHED)
9932 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9933
9934+#define _TIF_WORK_SYSCALL \
9935+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9936+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
9937+
9938+
9939 /*
9940 * Thread-synchronous status.
9941 *
9942diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9943index 0167d26..767bb0c 100644
9944--- a/arch/sparc/include/asm/uaccess.h
9945+++ b/arch/sparc/include/asm/uaccess.h
9946@@ -1,5 +1,6 @@
9947 #ifndef ___ASM_SPARC_UACCESS_H
9948 #define ___ASM_SPARC_UACCESS_H
9949+
9950 #if defined(__sparc__) && defined(__arch64__)
9951 #include <asm/uaccess_64.h>
9952 #else
9953diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9954index 53a28dd..50c38c3 100644
9955--- a/arch/sparc/include/asm/uaccess_32.h
9956+++ b/arch/sparc/include/asm/uaccess_32.h
9957@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9958
9959 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9960 {
9961- if (n && __access_ok((unsigned long) to, n))
9962+ if ((long)n < 0)
9963+ return n;
9964+
9965+ if (n && __access_ok((unsigned long) to, n)) {
9966+ if (!__builtin_constant_p(n))
9967+ check_object_size(from, n, true);
9968 return __copy_user(to, (__force void __user *) from, n);
9969- else
9970+ } else
9971 return n;
9972 }
9973
9974 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9975 {
9976+ if ((long)n < 0)
9977+ return n;
9978+
9979+ if (!__builtin_constant_p(n))
9980+ check_object_size(from, n, true);
9981+
9982 return __copy_user(to, (__force void __user *) from, n);
9983 }
9984
9985 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9986 {
9987- if (n && __access_ok((unsigned long) from, n))
9988+ if ((long)n < 0)
9989+ return n;
9990+
9991+ if (n && __access_ok((unsigned long) from, n)) {
9992+ if (!__builtin_constant_p(n))
9993+ check_object_size(to, n, false);
9994 return __copy_user((__force void __user *) to, from, n);
9995- else
9996+ } else
9997 return n;
9998 }
9999
10000 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10001 {
10002+ if ((long)n < 0)
10003+ return n;
10004+
10005 return __copy_user((__force void __user *) to, from, n);
10006 }
10007
10008diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10009index ad7e178..c9e7423 100644
10010--- a/arch/sparc/include/asm/uaccess_64.h
10011+++ b/arch/sparc/include/asm/uaccess_64.h
10012@@ -10,6 +10,7 @@
10013 #include <linux/compiler.h>
10014 #include <linux/string.h>
10015 #include <linux/thread_info.h>
10016+#include <linux/kernel.h>
10017 #include <asm/asi.h>
10018 #include <asm/spitfire.h>
10019 #include <asm-generic/uaccess-unaligned.h>
10020@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
10021 static inline unsigned long __must_check
10022 copy_from_user(void *to, const void __user *from, unsigned long size)
10023 {
10024- unsigned long ret = ___copy_from_user(to, from, size);
10025+ unsigned long ret;
10026
10027+ if ((long)size < 0 || size > INT_MAX)
10028+ return size;
10029+
10030+ if (!__builtin_constant_p(size))
10031+ check_object_size(to, size, false);
10032+
10033+ ret = ___copy_from_user(to, from, size);
10034 if (unlikely(ret))
10035 ret = copy_from_user_fixup(to, from, size);
10036
10037@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
10038 static inline unsigned long __must_check
10039 copy_to_user(void __user *to, const void *from, unsigned long size)
10040 {
10041- unsigned long ret = ___copy_to_user(to, from, size);
10042+ unsigned long ret;
10043
10044+ if ((long)size < 0 || size > INT_MAX)
10045+ return size;
10046+
10047+ if (!__builtin_constant_p(size))
10048+ check_object_size(from, size, true);
10049+
10050+ ret = ___copy_to_user(to, from, size);
10051 if (unlikely(ret))
10052 ret = copy_to_user_fixup(to, from, size);
10053 return ret;
10054diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10055index d15cc17..d0ae796 100644
10056--- a/arch/sparc/kernel/Makefile
10057+++ b/arch/sparc/kernel/Makefile
10058@@ -4,7 +4,7 @@
10059 #
10060
10061 asflags-y := -ansi
10062-ccflags-y := -Werror
10063+#ccflags-y := -Werror
10064
10065 extra-y := head_$(BITS).o
10066
10067diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10068index fdd819d..5af08c8 100644
10069--- a/arch/sparc/kernel/process_32.c
10070+++ b/arch/sparc/kernel/process_32.c
10071@@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
10072
10073 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10074 r->psr, r->pc, r->npc, r->y, print_tainted());
10075- printk("PC: <%pS>\n", (void *) r->pc);
10076+ printk("PC: <%pA>\n", (void *) r->pc);
10077 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10078 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10079 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10080 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10081 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10082 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10083- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10084+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10085
10086 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10087 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10088@@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10089 rw = (struct reg_window32 *) fp;
10090 pc = rw->ins[7];
10091 printk("[%08lx : ", pc);
10092- printk("%pS ] ", (void *) pc);
10093+ printk("%pA ] ", (void *) pc);
10094 fp = rw->ins[6];
10095 } while (++count < 16);
10096 printk("\n");
10097diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10098index 32a280e..84fc6a9 100644
10099--- a/arch/sparc/kernel/process_64.c
10100+++ b/arch/sparc/kernel/process_64.c
10101@@ -159,7 +159,7 @@ static void show_regwindow(struct pt_regs *regs)
10102 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10103 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10104 if (regs->tstate & TSTATE_PRIV)
10105- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10106+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10107 }
10108
10109 void show_regs(struct pt_regs *regs)
10110@@ -168,7 +168,7 @@ void show_regs(struct pt_regs *regs)
10111
10112 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10113 regs->tpc, regs->tnpc, regs->y, print_tainted());
10114- printk("TPC: <%pS>\n", (void *) regs->tpc);
10115+ printk("TPC: <%pA>\n", (void *) regs->tpc);
10116 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10117 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10118 regs->u_regs[3]);
10119@@ -181,7 +181,7 @@ void show_regs(struct pt_regs *regs)
10120 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10121 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10122 regs->u_regs[15]);
10123- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10124+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10125 show_regwindow(regs);
10126 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10127 }
10128@@ -270,7 +270,7 @@ void arch_trigger_all_cpu_backtrace(void)
10129 ((tp && tp->task) ? tp->task->pid : -1));
10130
10131 if (gp->tstate & TSTATE_PRIV) {
10132- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10133+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10134 (void *) gp->tpc,
10135 (void *) gp->o7,
10136 (void *) gp->i7,
10137diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10138index 79cc0d1..ec62734 100644
10139--- a/arch/sparc/kernel/prom_common.c
10140+++ b/arch/sparc/kernel/prom_common.c
10141@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10142
10143 unsigned int prom_early_allocated __initdata;
10144
10145-static struct of_pdt_ops prom_sparc_ops __initdata = {
10146+static struct of_pdt_ops prom_sparc_ops __initconst = {
10147 .nextprop = prom_common_nextprop,
10148 .getproplen = prom_getproplen,
10149 .getproperty = prom_getproperty,
10150diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10151index c13c9f2..d572c34 100644
10152--- a/arch/sparc/kernel/ptrace_64.c
10153+++ b/arch/sparc/kernel/ptrace_64.c
10154@@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10155 return ret;
10156 }
10157
10158+#ifdef CONFIG_GRKERNSEC_SETXID
10159+extern void gr_delayed_cred_worker(void);
10160+#endif
10161+
10162 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10163 {
10164 int ret = 0;
10165@@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10166 if (test_thread_flag(TIF_NOHZ))
10167 user_exit();
10168
10169+#ifdef CONFIG_GRKERNSEC_SETXID
10170+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10171+ gr_delayed_cred_worker();
10172+#endif
10173+
10174 if (test_thread_flag(TIF_SYSCALL_TRACE))
10175 ret = tracehook_report_syscall_entry(regs);
10176
10177@@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10178 if (test_thread_flag(TIF_NOHZ))
10179 user_exit();
10180
10181+#ifdef CONFIG_GRKERNSEC_SETXID
10182+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10183+ gr_delayed_cred_worker();
10184+#endif
10185+
10186 audit_syscall_exit(regs);
10187
10188 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10189diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10190index b085311..6f885f7 100644
10191--- a/arch/sparc/kernel/smp_64.c
10192+++ b/arch/sparc/kernel/smp_64.c
10193@@ -870,8 +870,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
10194 extern unsigned long xcall_flush_dcache_page_spitfire;
10195
10196 #ifdef CONFIG_DEBUG_DCFLUSH
10197-extern atomic_t dcpage_flushes;
10198-extern atomic_t dcpage_flushes_xcall;
10199+extern atomic_unchecked_t dcpage_flushes;
10200+extern atomic_unchecked_t dcpage_flushes_xcall;
10201 #endif
10202
10203 static inline void __local_flush_dcache_page(struct page *page)
10204@@ -895,7 +895,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10205 return;
10206
10207 #ifdef CONFIG_DEBUG_DCFLUSH
10208- atomic_inc(&dcpage_flushes);
10209+ atomic_inc_unchecked(&dcpage_flushes);
10210 #endif
10211
10212 this_cpu = get_cpu();
10213@@ -919,7 +919,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10214 xcall_deliver(data0, __pa(pg_addr),
10215 (u64) pg_addr, cpumask_of(cpu));
10216 #ifdef CONFIG_DEBUG_DCFLUSH
10217- atomic_inc(&dcpage_flushes_xcall);
10218+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10219 #endif
10220 }
10221 }
10222@@ -938,7 +938,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10223 preempt_disable();
10224
10225 #ifdef CONFIG_DEBUG_DCFLUSH
10226- atomic_inc(&dcpage_flushes);
10227+ atomic_inc_unchecked(&dcpage_flushes);
10228 #endif
10229 data0 = 0;
10230 pg_addr = page_address(page);
10231@@ -955,7 +955,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10232 xcall_deliver(data0, __pa(pg_addr),
10233 (u64) pg_addr, cpu_online_mask);
10234 #ifdef CONFIG_DEBUG_DCFLUSH
10235- atomic_inc(&dcpage_flushes_xcall);
10236+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10237 #endif
10238 }
10239 __local_flush_dcache_page(page);
10240diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10241index 3a8d184..49498a8 100644
10242--- a/arch/sparc/kernel/sys_sparc_32.c
10243+++ b/arch/sparc/kernel/sys_sparc_32.c
10244@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10245 if (len > TASK_SIZE - PAGE_SIZE)
10246 return -ENOMEM;
10247 if (!addr)
10248- addr = TASK_UNMAPPED_BASE;
10249+ addr = current->mm->mmap_base;
10250
10251 info.flags = 0;
10252 info.length = len;
10253diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10254index beb0b5a..5a153f7 100644
10255--- a/arch/sparc/kernel/sys_sparc_64.c
10256+++ b/arch/sparc/kernel/sys_sparc_64.c
10257@@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10258 struct vm_area_struct * vma;
10259 unsigned long task_size = TASK_SIZE;
10260 int do_color_align;
10261+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10262 struct vm_unmapped_area_info info;
10263
10264 if (flags & MAP_FIXED) {
10265 /* We do not accept a shared mapping if it would violate
10266 * cache aliasing constraints.
10267 */
10268- if ((flags & MAP_SHARED) &&
10269+ if ((filp || (flags & MAP_SHARED)) &&
10270 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10271 return -EINVAL;
10272 return addr;
10273@@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10274 if (filp || (flags & MAP_SHARED))
10275 do_color_align = 1;
10276
10277+#ifdef CONFIG_PAX_RANDMMAP
10278+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10279+#endif
10280+
10281 if (addr) {
10282 if (do_color_align)
10283 addr = COLOR_ALIGN(addr, pgoff);
10284@@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10285 addr = PAGE_ALIGN(addr);
10286
10287 vma = find_vma(mm, addr);
10288- if (task_size - len >= addr &&
10289- (!vma || addr + len <= vma->vm_start))
10290+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10291 return addr;
10292 }
10293
10294 info.flags = 0;
10295 info.length = len;
10296- info.low_limit = TASK_UNMAPPED_BASE;
10297+ info.low_limit = mm->mmap_base;
10298 info.high_limit = min(task_size, VA_EXCLUDE_START);
10299 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10300 info.align_offset = pgoff << PAGE_SHIFT;
10301+ info.threadstack_offset = offset;
10302 addr = vm_unmapped_area(&info);
10303
10304 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10305 VM_BUG_ON(addr != -ENOMEM);
10306 info.low_limit = VA_EXCLUDE_END;
10307+
10308+#ifdef CONFIG_PAX_RANDMMAP
10309+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10310+ info.low_limit += mm->delta_mmap;
10311+#endif
10312+
10313 info.high_limit = task_size;
10314 addr = vm_unmapped_area(&info);
10315 }
10316@@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10317 unsigned long task_size = STACK_TOP32;
10318 unsigned long addr = addr0;
10319 int do_color_align;
10320+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10321 struct vm_unmapped_area_info info;
10322
10323 /* This should only ever run for 32-bit processes. */
10324@@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10325 /* We do not accept a shared mapping if it would violate
10326 * cache aliasing constraints.
10327 */
10328- if ((flags & MAP_SHARED) &&
10329+ if ((filp || (flags & MAP_SHARED)) &&
10330 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10331 return -EINVAL;
10332 return addr;
10333@@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10334 if (filp || (flags & MAP_SHARED))
10335 do_color_align = 1;
10336
10337+#ifdef CONFIG_PAX_RANDMMAP
10338+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10339+#endif
10340+
10341 /* requesting a specific address */
10342 if (addr) {
10343 if (do_color_align)
10344@@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10345 addr = PAGE_ALIGN(addr);
10346
10347 vma = find_vma(mm, addr);
10348- if (task_size - len >= addr &&
10349- (!vma || addr + len <= vma->vm_start))
10350+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10351 return addr;
10352 }
10353
10354@@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10355 info.high_limit = mm->mmap_base;
10356 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10357 info.align_offset = pgoff << PAGE_SHIFT;
10358+ info.threadstack_offset = offset;
10359 addr = vm_unmapped_area(&info);
10360
10361 /*
10362@@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10363 VM_BUG_ON(addr != -ENOMEM);
10364 info.flags = 0;
10365 info.low_limit = TASK_UNMAPPED_BASE;
10366+
10367+#ifdef CONFIG_PAX_RANDMMAP
10368+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10369+ info.low_limit += mm->delta_mmap;
10370+#endif
10371+
10372 info.high_limit = STACK_TOP32;
10373 addr = vm_unmapped_area(&info);
10374 }
10375@@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10376 EXPORT_SYMBOL(get_fb_unmapped_area);
10377
10378 /* Essentially the same as PowerPC. */
10379-static unsigned long mmap_rnd(void)
10380+static unsigned long mmap_rnd(struct mm_struct *mm)
10381 {
10382 unsigned long rnd = 0UL;
10383
10384+#ifdef CONFIG_PAX_RANDMMAP
10385+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10386+#endif
10387+
10388 if (current->flags & PF_RANDOMIZE) {
10389 unsigned long val = get_random_int();
10390 if (test_thread_flag(TIF_32BIT))
10391@@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
10392
10393 void arch_pick_mmap_layout(struct mm_struct *mm)
10394 {
10395- unsigned long random_factor = mmap_rnd();
10396+ unsigned long random_factor = mmap_rnd(mm);
10397 unsigned long gap;
10398
10399 /*
10400@@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10401 gap == RLIM_INFINITY ||
10402 sysctl_legacy_va_layout) {
10403 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10404+
10405+#ifdef CONFIG_PAX_RANDMMAP
10406+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10407+ mm->mmap_base += mm->delta_mmap;
10408+#endif
10409+
10410 mm->get_unmapped_area = arch_get_unmapped_area;
10411 } else {
10412 /* We know it's 32-bit */
10413@@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10414 gap = (task_size / 6 * 5);
10415
10416 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10417+
10418+#ifdef CONFIG_PAX_RANDMMAP
10419+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10420+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10421+#endif
10422+
10423 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10424 }
10425 }
10426diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10427index 87729ff..d87fb1f 100644
10428--- a/arch/sparc/kernel/syscalls.S
10429+++ b/arch/sparc/kernel/syscalls.S
10430@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10431 #endif
10432 .align 32
10433 1: ldx [%g6 + TI_FLAGS], %l5
10434- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10435+ andcc %l5, _TIF_WORK_SYSCALL, %g0
10436 be,pt %icc, rtrap
10437 nop
10438 call syscall_trace_leave
10439@@ -184,12 +184,13 @@ linux_sparc_syscall32:
10440
10441 srl %i3, 0, %o3 ! IEU0
10442 srl %i2, 0, %o2 ! IEU0 Group
10443- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10444+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10445 bne,pn %icc, linux_syscall_trace32 ! CTI
10446 mov %i0, %l5 ! IEU1
10447 5: call %l7 ! CTI Group brk forced
10448 srl %i5, 0, %o5 ! IEU1
10449- ba,a,pt %xcc, 3f
10450+ ba,pt %xcc, 3f
10451+ sra %o0, 0, %o0
10452
10453 /* Linux native system calls enter here... */
10454 .align 32
10455@@ -207,7 +208,7 @@ linux_sparc_syscall:
10456
10457 mov %i3, %o3 ! IEU1
10458 mov %i4, %o4 ! IEU0 Group
10459- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10460+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10461 bne,pn %icc, linux_syscall_trace ! CTI Group
10462 mov %i0, %l5 ! IEU0
10463 2: call %l7 ! CTI Group brk forced
10464@@ -217,13 +218,12 @@ linux_sparc_syscall:
10465 3: stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
10466 ret_sys_call:
10467 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %g3
10468- sra %o0, 0, %o0
10469 mov %ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2
10470 sllx %g2, 32, %g2
10471
10472 cmp %o0, -ERESTART_RESTARTBLOCK
10473 bgeu,pn %xcc, 1f
10474- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10475+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10476 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10477
10478 2:
10479diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10480index 6629829..036032d 100644
10481--- a/arch/sparc/kernel/traps_32.c
10482+++ b/arch/sparc/kernel/traps_32.c
10483@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10484 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10485 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10486
10487+extern void gr_handle_kernel_exploit(void);
10488+
10489 void die_if_kernel(char *str, struct pt_regs *regs)
10490 {
10491 static int die_counter;
10492@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10493 count++ < 30 &&
10494 (((unsigned long) rw) >= PAGE_OFFSET) &&
10495 !(((unsigned long) rw) & 0x7)) {
10496- printk("Caller[%08lx]: %pS\n", rw->ins[7],
10497+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
10498 (void *) rw->ins[7]);
10499 rw = (struct reg_window32 *)rw->ins[6];
10500 }
10501 }
10502 printk("Instruction DUMP:");
10503 instruction_dump ((unsigned long *) regs->pc);
10504- if(regs->psr & PSR_PS)
10505+ if(regs->psr & PSR_PS) {
10506+ gr_handle_kernel_exploit();
10507 do_exit(SIGKILL);
10508+ }
10509 do_exit(SIGSEGV);
10510 }
10511
10512diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10513index 4ced92f..965eeed 100644
10514--- a/arch/sparc/kernel/traps_64.c
10515+++ b/arch/sparc/kernel/traps_64.c
10516@@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10517 i + 1,
10518 p->trapstack[i].tstate, p->trapstack[i].tpc,
10519 p->trapstack[i].tnpc, p->trapstack[i].tt);
10520- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10521+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10522 }
10523 }
10524
10525@@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10526
10527 lvl -= 0x100;
10528 if (regs->tstate & TSTATE_PRIV) {
10529+
10530+#ifdef CONFIG_PAX_REFCOUNT
10531+ if (lvl == 6)
10532+ pax_report_refcount_overflow(regs);
10533+#endif
10534+
10535 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10536 die_if_kernel(buffer, regs);
10537 }
10538@@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10539 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10540 {
10541 char buffer[32];
10542-
10543+
10544 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10545 0, lvl, SIGTRAP) == NOTIFY_STOP)
10546 return;
10547
10548+#ifdef CONFIG_PAX_REFCOUNT
10549+ if (lvl == 6)
10550+ pax_report_refcount_overflow(regs);
10551+#endif
10552+
10553 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10554
10555 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10556@@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10557 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10558 printk("%s" "ERROR(%d): ",
10559 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10560- printk("TPC<%pS>\n", (void *) regs->tpc);
10561+ printk("TPC<%pA>\n", (void *) regs->tpc);
10562 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10563 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10564 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10565@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10566 smp_processor_id(),
10567 (type & 0x1) ? 'I' : 'D',
10568 regs->tpc);
10569- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10570+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10571 panic("Irrecoverable Cheetah+ parity error.");
10572 }
10573
10574@@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10575 smp_processor_id(),
10576 (type & 0x1) ? 'I' : 'D',
10577 regs->tpc);
10578- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10579+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10580 }
10581
10582 struct sun4v_error_entry {
10583@@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10584 /*0x38*/u64 reserved_5;
10585 };
10586
10587-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10588-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10589+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10590+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10591
10592 static const char *sun4v_err_type_to_str(u8 type)
10593 {
10594@@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10595 }
10596
10597 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10598- int cpu, const char *pfx, atomic_t *ocnt)
10599+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10600 {
10601 u64 *raw_ptr = (u64 *) ent;
10602 u32 attrs;
10603@@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10604
10605 show_regs(regs);
10606
10607- if ((cnt = atomic_read(ocnt)) != 0) {
10608- atomic_set(ocnt, 0);
10609+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10610+ atomic_set_unchecked(ocnt, 0);
10611 wmb();
10612 printk("%s: Queue overflowed %d times.\n",
10613 pfx, cnt);
10614@@ -2046,7 +2057,7 @@ out:
10615 */
10616 void sun4v_resum_overflow(struct pt_regs *regs)
10617 {
10618- atomic_inc(&sun4v_resum_oflow_cnt);
10619+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10620 }
10621
10622 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10623@@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10624 /* XXX Actually even this can make not that much sense. Perhaps
10625 * XXX we should just pull the plug and panic directly from here?
10626 */
10627- atomic_inc(&sun4v_nonresum_oflow_cnt);
10628+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10629 }
10630
10631 unsigned long sun4v_err_itlb_vaddr;
10632@@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10633
10634 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10635 regs->tpc, tl);
10636- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10637+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10638 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10639- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10640+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10641 (void *) regs->u_regs[UREG_I7]);
10642 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10643 "pte[%lx] error[%lx]\n",
10644@@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10645
10646 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10647 regs->tpc, tl);
10648- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10649+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10650 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10651- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10652+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10653 (void *) regs->u_regs[UREG_I7]);
10654 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10655 "pte[%lx] error[%lx]\n",
10656@@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10657 fp = (unsigned long)sf->fp + STACK_BIAS;
10658 }
10659
10660- printk(" [%016lx] %pS\n", pc, (void *) pc);
10661+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10662 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10663 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10664 int index = tsk->curr_ret_stack;
10665 if (tsk->ret_stack && index >= graph) {
10666 pc = tsk->ret_stack[index - graph].ret;
10667- printk(" [%016lx] %pS\n", pc, (void *) pc);
10668+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10669 graph++;
10670 }
10671 }
10672@@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10673 return (struct reg_window *) (fp + STACK_BIAS);
10674 }
10675
10676+extern void gr_handle_kernel_exploit(void);
10677+
10678 void die_if_kernel(char *str, struct pt_regs *regs)
10679 {
10680 static int die_counter;
10681@@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10682 while (rw &&
10683 count++ < 30 &&
10684 kstack_valid(tp, (unsigned long) rw)) {
10685- printk("Caller[%016lx]: %pS\n", rw->ins[7],
10686+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
10687 (void *) rw->ins[7]);
10688
10689 rw = kernel_stack_up(rw);
10690@@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10691 }
10692 user_instruction_dump ((unsigned int __user *) regs->tpc);
10693 }
10694- if (regs->tstate & TSTATE_PRIV)
10695+ if (regs->tstate & TSTATE_PRIV) {
10696+ gr_handle_kernel_exploit();
10697 do_exit(SIGKILL);
10698+ }
10699 do_exit(SIGSEGV);
10700 }
10701 EXPORT_SYMBOL(die_if_kernel);
10702diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10703index 3c1a7cb..73e1923 100644
10704--- a/arch/sparc/kernel/unaligned_64.c
10705+++ b/arch/sparc/kernel/unaligned_64.c
10706@@ -289,7 +289,7 @@ static void log_unaligned(struct pt_regs *regs)
10707 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10708
10709 if (__ratelimit(&ratelimit)) {
10710- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10711+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10712 regs->tpc, (void *) regs->tpc);
10713 }
10714 }
10715diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10716index dbe119b..089c7c1 100644
10717--- a/arch/sparc/lib/Makefile
10718+++ b/arch/sparc/lib/Makefile
10719@@ -2,7 +2,7 @@
10720 #
10721
10722 asflags-y := -ansi -DST_DIV0=0x02
10723-ccflags-y := -Werror
10724+#ccflags-y := -Werror
10725
10726 lib-$(CONFIG_SPARC32) += ashrdi3.o
10727 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10728diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10729index 85c233d..68500e0 100644
10730--- a/arch/sparc/lib/atomic_64.S
10731+++ b/arch/sparc/lib/atomic_64.S
10732@@ -17,7 +17,12 @@
10733 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10734 BACKOFF_SETUP(%o2)
10735 1: lduw [%o1], %g1
10736- add %g1, %o0, %g7
10737+ addcc %g1, %o0, %g7
10738+
10739+#ifdef CONFIG_PAX_REFCOUNT
10740+ tvs %icc, 6
10741+#endif
10742+
10743 cas [%o1], %g1, %g7
10744 cmp %g1, %g7
10745 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10746@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10747 2: BACKOFF_SPIN(%o2, %o3, 1b)
10748 ENDPROC(atomic_add)
10749
10750+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10751+ BACKOFF_SETUP(%o2)
10752+1: lduw [%o1], %g1
10753+ add %g1, %o0, %g7
10754+ cas [%o1], %g1, %g7
10755+ cmp %g1, %g7
10756+ bne,pn %icc, 2f
10757+ nop
10758+ retl
10759+ nop
10760+2: BACKOFF_SPIN(%o2, %o3, 1b)
10761+ENDPROC(atomic_add_unchecked)
10762+
10763 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10764 BACKOFF_SETUP(%o2)
10765 1: lduw [%o1], %g1
10766- sub %g1, %o0, %g7
10767+ subcc %g1, %o0, %g7
10768+
10769+#ifdef CONFIG_PAX_REFCOUNT
10770+ tvs %icc, 6
10771+#endif
10772+
10773 cas [%o1], %g1, %g7
10774 cmp %g1, %g7
10775 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10776@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10777 2: BACKOFF_SPIN(%o2, %o3, 1b)
10778 ENDPROC(atomic_sub)
10779
10780+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10781+ BACKOFF_SETUP(%o2)
10782+1: lduw [%o1], %g1
10783+ sub %g1, %o0, %g7
10784+ cas [%o1], %g1, %g7
10785+ cmp %g1, %g7
10786+ bne,pn %icc, 2f
10787+ nop
10788+ retl
10789+ nop
10790+2: BACKOFF_SPIN(%o2, %o3, 1b)
10791+ENDPROC(atomic_sub_unchecked)
10792+
10793 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10794 BACKOFF_SETUP(%o2)
10795 1: lduw [%o1], %g1
10796- add %g1, %o0, %g7
10797+ addcc %g1, %o0, %g7
10798+
10799+#ifdef CONFIG_PAX_REFCOUNT
10800+ tvs %icc, 6
10801+#endif
10802+
10803 cas [%o1], %g1, %g7
10804 cmp %g1, %g7
10805 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10806@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10807 2: BACKOFF_SPIN(%o2, %o3, 1b)
10808 ENDPROC(atomic_add_ret)
10809
10810+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10811+ BACKOFF_SETUP(%o2)
10812+1: lduw [%o1], %g1
10813+ addcc %g1, %o0, %g7
10814+ cas [%o1], %g1, %g7
10815+ cmp %g1, %g7
10816+ bne,pn %icc, 2f
10817+ add %g7, %o0, %g7
10818+ sra %g7, 0, %o0
10819+ retl
10820+ nop
10821+2: BACKOFF_SPIN(%o2, %o3, 1b)
10822+ENDPROC(atomic_add_ret_unchecked)
10823+
10824 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10825 BACKOFF_SETUP(%o2)
10826 1: lduw [%o1], %g1
10827- sub %g1, %o0, %g7
10828+ subcc %g1, %o0, %g7
10829+
10830+#ifdef CONFIG_PAX_REFCOUNT
10831+ tvs %icc, 6
10832+#endif
10833+
10834 cas [%o1], %g1, %g7
10835 cmp %g1, %g7
10836 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10837@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10838 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10839 BACKOFF_SETUP(%o2)
10840 1: ldx [%o1], %g1
10841- add %g1, %o0, %g7
10842+ addcc %g1, %o0, %g7
10843+
10844+#ifdef CONFIG_PAX_REFCOUNT
10845+ tvs %xcc, 6
10846+#endif
10847+
10848 casx [%o1], %g1, %g7
10849 cmp %g1, %g7
10850 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10851@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10852 2: BACKOFF_SPIN(%o2, %o3, 1b)
10853 ENDPROC(atomic64_add)
10854
10855+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10856+ BACKOFF_SETUP(%o2)
10857+1: ldx [%o1], %g1
10858+ addcc %g1, %o0, %g7
10859+ casx [%o1], %g1, %g7
10860+ cmp %g1, %g7
10861+ bne,pn %xcc, 2f
10862+ nop
10863+ retl
10864+ nop
10865+2: BACKOFF_SPIN(%o2, %o3, 1b)
10866+ENDPROC(atomic64_add_unchecked)
10867+
10868 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10869 BACKOFF_SETUP(%o2)
10870 1: ldx [%o1], %g1
10871- sub %g1, %o0, %g7
10872+ subcc %g1, %o0, %g7
10873+
10874+#ifdef CONFIG_PAX_REFCOUNT
10875+ tvs %xcc, 6
10876+#endif
10877+
10878 casx [%o1], %g1, %g7
10879 cmp %g1, %g7
10880 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10881@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10882 2: BACKOFF_SPIN(%o2, %o3, 1b)
10883 ENDPROC(atomic64_sub)
10884
10885+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10886+ BACKOFF_SETUP(%o2)
10887+1: ldx [%o1], %g1
10888+ subcc %g1, %o0, %g7
10889+ casx [%o1], %g1, %g7
10890+ cmp %g1, %g7
10891+ bne,pn %xcc, 2f
10892+ nop
10893+ retl
10894+ nop
10895+2: BACKOFF_SPIN(%o2, %o3, 1b)
10896+ENDPROC(atomic64_sub_unchecked)
10897+
10898 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10899 BACKOFF_SETUP(%o2)
10900 1: ldx [%o1], %g1
10901- add %g1, %o0, %g7
10902+ addcc %g1, %o0, %g7
10903+
10904+#ifdef CONFIG_PAX_REFCOUNT
10905+ tvs %xcc, 6
10906+#endif
10907+
10908 casx [%o1], %g1, %g7
10909 cmp %g1, %g7
10910 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10911@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10912 2: BACKOFF_SPIN(%o2, %o3, 1b)
10913 ENDPROC(atomic64_add_ret)
10914
10915+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10916+ BACKOFF_SETUP(%o2)
10917+1: ldx [%o1], %g1
10918+ addcc %g1, %o0, %g7
10919+ casx [%o1], %g1, %g7
10920+ cmp %g1, %g7
10921+ bne,pn %xcc, 2f
10922+ add %g7, %o0, %g7
10923+ mov %g7, %o0
10924+ retl
10925+ nop
10926+2: BACKOFF_SPIN(%o2, %o3, 1b)
10927+ENDPROC(atomic64_add_ret_unchecked)
10928+
10929 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10930 BACKOFF_SETUP(%o2)
10931 1: ldx [%o1], %g1
10932- sub %g1, %o0, %g7
10933+ subcc %g1, %o0, %g7
10934+
10935+#ifdef CONFIG_PAX_REFCOUNT
10936+ tvs %xcc, 6
10937+#endif
10938+
10939 casx [%o1], %g1, %g7
10940 cmp %g1, %g7
10941 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10942diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10943index 323335b..ed85ea2 100644
10944--- a/arch/sparc/lib/ksyms.c
10945+++ b/arch/sparc/lib/ksyms.c
10946@@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
10947
10948 /* Atomic counter implementation. */
10949 EXPORT_SYMBOL(atomic_add);
10950+EXPORT_SYMBOL(atomic_add_unchecked);
10951 EXPORT_SYMBOL(atomic_add_ret);
10952+EXPORT_SYMBOL(atomic_add_ret_unchecked);
10953 EXPORT_SYMBOL(atomic_sub);
10954+EXPORT_SYMBOL(atomic_sub_unchecked);
10955 EXPORT_SYMBOL(atomic_sub_ret);
10956 EXPORT_SYMBOL(atomic64_add);
10957+EXPORT_SYMBOL(atomic64_add_unchecked);
10958 EXPORT_SYMBOL(atomic64_add_ret);
10959+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10960 EXPORT_SYMBOL(atomic64_sub);
10961+EXPORT_SYMBOL(atomic64_sub_unchecked);
10962 EXPORT_SYMBOL(atomic64_sub_ret);
10963 EXPORT_SYMBOL(atomic64_dec_if_positive);
10964
10965diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10966index 30c3ecc..736f015 100644
10967--- a/arch/sparc/mm/Makefile
10968+++ b/arch/sparc/mm/Makefile
10969@@ -2,7 +2,7 @@
10970 #
10971
10972 asflags-y := -ansi
10973-ccflags-y := -Werror
10974+#ccflags-y := -Werror
10975
10976 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10977 obj-y += fault_$(BITS).o
10978diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10979index 59dbd46..1dd7f5e 100644
10980--- a/arch/sparc/mm/fault_32.c
10981+++ b/arch/sparc/mm/fault_32.c
10982@@ -21,6 +21,9 @@
10983 #include <linux/perf_event.h>
10984 #include <linux/interrupt.h>
10985 #include <linux/kdebug.h>
10986+#include <linux/slab.h>
10987+#include <linux/pagemap.h>
10988+#include <linux/compiler.h>
10989
10990 #include <asm/page.h>
10991 #include <asm/pgtable.h>
10992@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10993 return safe_compute_effective_address(regs, insn);
10994 }
10995
10996+#ifdef CONFIG_PAX_PAGEEXEC
10997+#ifdef CONFIG_PAX_DLRESOLVE
10998+static void pax_emuplt_close(struct vm_area_struct *vma)
10999+{
11000+ vma->vm_mm->call_dl_resolve = 0UL;
11001+}
11002+
11003+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11004+{
11005+ unsigned int *kaddr;
11006+
11007+ vmf->page = alloc_page(GFP_HIGHUSER);
11008+ if (!vmf->page)
11009+ return VM_FAULT_OOM;
11010+
11011+ kaddr = kmap(vmf->page);
11012+ memset(kaddr, 0, PAGE_SIZE);
11013+ kaddr[0] = 0x9DE3BFA8U; /* save */
11014+ flush_dcache_page(vmf->page);
11015+ kunmap(vmf->page);
11016+ return VM_FAULT_MAJOR;
11017+}
11018+
11019+static const struct vm_operations_struct pax_vm_ops = {
11020+ .close = pax_emuplt_close,
11021+ .fault = pax_emuplt_fault
11022+};
11023+
11024+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11025+{
11026+ int ret;
11027+
11028+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11029+ vma->vm_mm = current->mm;
11030+ vma->vm_start = addr;
11031+ vma->vm_end = addr + PAGE_SIZE;
11032+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11033+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11034+ vma->vm_ops = &pax_vm_ops;
11035+
11036+ ret = insert_vm_struct(current->mm, vma);
11037+ if (ret)
11038+ return ret;
11039+
11040+ ++current->mm->total_vm;
11041+ return 0;
11042+}
11043+#endif
11044+
11045+/*
11046+ * PaX: decide what to do with offenders (regs->pc = fault address)
11047+ *
11048+ * returns 1 when task should be killed
11049+ * 2 when patched PLT trampoline was detected
11050+ * 3 when unpatched PLT trampoline was detected
11051+ */
11052+static int pax_handle_fetch_fault(struct pt_regs *regs)
11053+{
11054+
11055+#ifdef CONFIG_PAX_EMUPLT
11056+ int err;
11057+
11058+ do { /* PaX: patched PLT emulation #1 */
11059+ unsigned int sethi1, sethi2, jmpl;
11060+
11061+ err = get_user(sethi1, (unsigned int *)regs->pc);
11062+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11063+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11064+
11065+ if (err)
11066+ break;
11067+
11068+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11069+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11070+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11071+ {
11072+ unsigned int addr;
11073+
11074+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11075+ addr = regs->u_regs[UREG_G1];
11076+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11077+ regs->pc = addr;
11078+ regs->npc = addr+4;
11079+ return 2;
11080+ }
11081+ } while (0);
11082+
11083+ do { /* PaX: patched PLT emulation #2 */
11084+ unsigned int ba;
11085+
11086+ err = get_user(ba, (unsigned int *)regs->pc);
11087+
11088+ if (err)
11089+ break;
11090+
11091+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11092+ unsigned int addr;
11093+
11094+ if ((ba & 0xFFC00000U) == 0x30800000U)
11095+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11096+ else
11097+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11098+ regs->pc = addr;
11099+ regs->npc = addr+4;
11100+ return 2;
11101+ }
11102+ } while (0);
11103+
11104+ do { /* PaX: patched PLT emulation #3 */
11105+ unsigned int sethi, bajmpl, nop;
11106+
11107+ err = get_user(sethi, (unsigned int *)regs->pc);
11108+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11109+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11110+
11111+ if (err)
11112+ break;
11113+
11114+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11115+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11116+ nop == 0x01000000U)
11117+ {
11118+ unsigned int addr;
11119+
11120+ addr = (sethi & 0x003FFFFFU) << 10;
11121+ regs->u_regs[UREG_G1] = addr;
11122+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11123+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11124+ else
11125+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11126+ regs->pc = addr;
11127+ regs->npc = addr+4;
11128+ return 2;
11129+ }
11130+ } while (0);
11131+
11132+ do { /* PaX: unpatched PLT emulation step 1 */
11133+ unsigned int sethi, ba, nop;
11134+
11135+ err = get_user(sethi, (unsigned int *)regs->pc);
11136+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
11137+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11138+
11139+ if (err)
11140+ break;
11141+
11142+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11143+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11144+ nop == 0x01000000U)
11145+ {
11146+ unsigned int addr, save, call;
11147+
11148+ if ((ba & 0xFFC00000U) == 0x30800000U)
11149+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11150+ else
11151+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11152+
11153+ err = get_user(save, (unsigned int *)addr);
11154+ err |= get_user(call, (unsigned int *)(addr+4));
11155+ err |= get_user(nop, (unsigned int *)(addr+8));
11156+ if (err)
11157+ break;
11158+
11159+#ifdef CONFIG_PAX_DLRESOLVE
11160+ if (save == 0x9DE3BFA8U &&
11161+ (call & 0xC0000000U) == 0x40000000U &&
11162+ nop == 0x01000000U)
11163+ {
11164+ struct vm_area_struct *vma;
11165+ unsigned long call_dl_resolve;
11166+
11167+ down_read(&current->mm->mmap_sem);
11168+ call_dl_resolve = current->mm->call_dl_resolve;
11169+ up_read(&current->mm->mmap_sem);
11170+ if (likely(call_dl_resolve))
11171+ goto emulate;
11172+
11173+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11174+
11175+ down_write(&current->mm->mmap_sem);
11176+ if (current->mm->call_dl_resolve) {
11177+ call_dl_resolve = current->mm->call_dl_resolve;
11178+ up_write(&current->mm->mmap_sem);
11179+ if (vma)
11180+ kmem_cache_free(vm_area_cachep, vma);
11181+ goto emulate;
11182+ }
11183+
11184+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11185+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11186+ up_write(&current->mm->mmap_sem);
11187+ if (vma)
11188+ kmem_cache_free(vm_area_cachep, vma);
11189+ return 1;
11190+ }
11191+
11192+ if (pax_insert_vma(vma, call_dl_resolve)) {
11193+ up_write(&current->mm->mmap_sem);
11194+ kmem_cache_free(vm_area_cachep, vma);
11195+ return 1;
11196+ }
11197+
11198+ current->mm->call_dl_resolve = call_dl_resolve;
11199+ up_write(&current->mm->mmap_sem);
11200+
11201+emulate:
11202+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11203+ regs->pc = call_dl_resolve;
11204+ regs->npc = addr+4;
11205+ return 3;
11206+ }
11207+#endif
11208+
11209+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11210+ if ((save & 0xFFC00000U) == 0x05000000U &&
11211+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11212+ nop == 0x01000000U)
11213+ {
11214+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11215+ regs->u_regs[UREG_G2] = addr + 4;
11216+ addr = (save & 0x003FFFFFU) << 10;
11217+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11218+ regs->pc = addr;
11219+ regs->npc = addr+4;
11220+ return 3;
11221+ }
11222+ }
11223+ } while (0);
11224+
11225+ do { /* PaX: unpatched PLT emulation step 2 */
11226+ unsigned int save, call, nop;
11227+
11228+ err = get_user(save, (unsigned int *)(regs->pc-4));
11229+ err |= get_user(call, (unsigned int *)regs->pc);
11230+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
11231+ if (err)
11232+ break;
11233+
11234+ if (save == 0x9DE3BFA8U &&
11235+ (call & 0xC0000000U) == 0x40000000U &&
11236+ nop == 0x01000000U)
11237+ {
11238+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11239+
11240+ regs->u_regs[UREG_RETPC] = regs->pc;
11241+ regs->pc = dl_resolve;
11242+ regs->npc = dl_resolve+4;
11243+ return 3;
11244+ }
11245+ } while (0);
11246+#endif
11247+
11248+ return 1;
11249+}
11250+
11251+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11252+{
11253+ unsigned long i;
11254+
11255+ printk(KERN_ERR "PAX: bytes at PC: ");
11256+ for (i = 0; i < 8; i++) {
11257+ unsigned int c;
11258+ if (get_user(c, (unsigned int *)pc+i))
11259+ printk(KERN_CONT "???????? ");
11260+ else
11261+ printk(KERN_CONT "%08x ", c);
11262+ }
11263+ printk("\n");
11264+}
11265+#endif
11266+
11267 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11268 int text_fault)
11269 {
11270@@ -229,6 +503,24 @@ good_area:
11271 if (!(vma->vm_flags & VM_WRITE))
11272 goto bad_area;
11273 } else {
11274+
11275+#ifdef CONFIG_PAX_PAGEEXEC
11276+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11277+ up_read(&mm->mmap_sem);
11278+ switch (pax_handle_fetch_fault(regs)) {
11279+
11280+#ifdef CONFIG_PAX_EMUPLT
11281+ case 2:
11282+ case 3:
11283+ return;
11284+#endif
11285+
11286+ }
11287+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11288+ do_group_exit(SIGKILL);
11289+ }
11290+#endif
11291+
11292 /* Allow reads even for write-only mappings */
11293 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11294 goto bad_area;
11295diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11296index 69bb818..6ca35c8 100644
11297--- a/arch/sparc/mm/fault_64.c
11298+++ b/arch/sparc/mm/fault_64.c
11299@@ -22,6 +22,9 @@
11300 #include <linux/kdebug.h>
11301 #include <linux/percpu.h>
11302 #include <linux/context_tracking.h>
11303+#include <linux/slab.h>
11304+#include <linux/pagemap.h>
11305+#include <linux/compiler.h>
11306
11307 #include <asm/page.h>
11308 #include <asm/pgtable.h>
11309@@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11310 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11311 regs->tpc);
11312 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11313- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11314+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11315 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11316 dump_stack();
11317 unhandled_fault(regs->tpc, current, regs);
11318@@ -271,6 +274,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
11319 show_regs(regs);
11320 }
11321
11322+#ifdef CONFIG_PAX_PAGEEXEC
11323+#ifdef CONFIG_PAX_DLRESOLVE
11324+static void pax_emuplt_close(struct vm_area_struct *vma)
11325+{
11326+ vma->vm_mm->call_dl_resolve = 0UL;
11327+}
11328+
11329+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11330+{
11331+ unsigned int *kaddr;
11332+
11333+ vmf->page = alloc_page(GFP_HIGHUSER);
11334+ if (!vmf->page)
11335+ return VM_FAULT_OOM;
11336+
11337+ kaddr = kmap(vmf->page);
11338+ memset(kaddr, 0, PAGE_SIZE);
11339+ kaddr[0] = 0x9DE3BFA8U; /* save */
11340+ flush_dcache_page(vmf->page);
11341+ kunmap(vmf->page);
11342+ return VM_FAULT_MAJOR;
11343+}
11344+
11345+static const struct vm_operations_struct pax_vm_ops = {
11346+ .close = pax_emuplt_close,
11347+ .fault = pax_emuplt_fault
11348+};
11349+
11350+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11351+{
11352+ int ret;
11353+
11354+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11355+ vma->vm_mm = current->mm;
11356+ vma->vm_start = addr;
11357+ vma->vm_end = addr + PAGE_SIZE;
11358+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11359+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11360+ vma->vm_ops = &pax_vm_ops;
11361+
11362+ ret = insert_vm_struct(current->mm, vma);
11363+ if (ret)
11364+ return ret;
11365+
11366+ ++current->mm->total_vm;
11367+ return 0;
11368+}
11369+#endif
11370+
11371+/*
11372+ * PaX: decide what to do with offenders (regs->tpc = fault address)
11373+ *
11374+ * returns 1 when task should be killed
11375+ * 2 when patched PLT trampoline was detected
11376+ * 3 when unpatched PLT trampoline was detected
11377+ */
11378+static int pax_handle_fetch_fault(struct pt_regs *regs)
11379+{
11380+
11381+#ifdef CONFIG_PAX_EMUPLT
11382+ int err;
11383+
11384+ do { /* PaX: patched PLT emulation #1 */
11385+ unsigned int sethi1, sethi2, jmpl;
11386+
11387+ err = get_user(sethi1, (unsigned int *)regs->tpc);
11388+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11389+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11390+
11391+ if (err)
11392+ break;
11393+
11394+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11395+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11396+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11397+ {
11398+ unsigned long addr;
11399+
11400+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11401+ addr = regs->u_regs[UREG_G1];
11402+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11403+
11404+ if (test_thread_flag(TIF_32BIT))
11405+ addr &= 0xFFFFFFFFUL;
11406+
11407+ regs->tpc = addr;
11408+ regs->tnpc = addr+4;
11409+ return 2;
11410+ }
11411+ } while (0);
11412+
11413+ do { /* PaX: patched PLT emulation #2 */
11414+ unsigned int ba;
11415+
11416+ err = get_user(ba, (unsigned int *)regs->tpc);
11417+
11418+ if (err)
11419+ break;
11420+
11421+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11422+ unsigned long addr;
11423+
11424+ if ((ba & 0xFFC00000U) == 0x30800000U)
11425+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11426+ else
11427+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11428+
11429+ if (test_thread_flag(TIF_32BIT))
11430+ addr &= 0xFFFFFFFFUL;
11431+
11432+ regs->tpc = addr;
11433+ regs->tnpc = addr+4;
11434+ return 2;
11435+ }
11436+ } while (0);
11437+
11438+ do { /* PaX: patched PLT emulation #3 */
11439+ unsigned int sethi, bajmpl, nop;
11440+
11441+ err = get_user(sethi, (unsigned int *)regs->tpc);
11442+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11443+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11444+
11445+ if (err)
11446+ break;
11447+
11448+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11449+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11450+ nop == 0x01000000U)
11451+ {
11452+ unsigned long addr;
11453+
11454+ addr = (sethi & 0x003FFFFFU) << 10;
11455+ regs->u_regs[UREG_G1] = addr;
11456+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11457+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11458+ else
11459+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11460+
11461+ if (test_thread_flag(TIF_32BIT))
11462+ addr &= 0xFFFFFFFFUL;
11463+
11464+ regs->tpc = addr;
11465+ regs->tnpc = addr+4;
11466+ return 2;
11467+ }
11468+ } while (0);
11469+
11470+ do { /* PaX: patched PLT emulation #4 */
11471+ unsigned int sethi, mov1, call, mov2;
11472+
11473+ err = get_user(sethi, (unsigned int *)regs->tpc);
11474+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11475+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
11476+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11477+
11478+ if (err)
11479+ break;
11480+
11481+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11482+ mov1 == 0x8210000FU &&
11483+ (call & 0xC0000000U) == 0x40000000U &&
11484+ mov2 == 0x9E100001U)
11485+ {
11486+ unsigned long addr;
11487+
11488+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11489+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11490+
11491+ if (test_thread_flag(TIF_32BIT))
11492+ addr &= 0xFFFFFFFFUL;
11493+
11494+ regs->tpc = addr;
11495+ regs->tnpc = addr+4;
11496+ return 2;
11497+ }
11498+ } while (0);
11499+
11500+ do { /* PaX: patched PLT emulation #5 */
11501+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11502+
11503+ err = get_user(sethi, (unsigned int *)regs->tpc);
11504+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11505+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11506+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11507+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11508+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11509+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11510+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11511+
11512+ if (err)
11513+ break;
11514+
11515+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11516+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11517+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11518+ (or1 & 0xFFFFE000U) == 0x82106000U &&
11519+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11520+ sllx == 0x83287020U &&
11521+ jmpl == 0x81C04005U &&
11522+ nop == 0x01000000U)
11523+ {
11524+ unsigned long addr;
11525+
11526+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11527+ regs->u_regs[UREG_G1] <<= 32;
11528+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11529+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11530+ regs->tpc = addr;
11531+ regs->tnpc = addr+4;
11532+ return 2;
11533+ }
11534+ } while (0);
11535+
11536+ do { /* PaX: patched PLT emulation #6 */
11537+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11538+
11539+ err = get_user(sethi, (unsigned int *)regs->tpc);
11540+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11541+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11542+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11543+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
11544+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11545+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11546+
11547+ if (err)
11548+ break;
11549+
11550+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11551+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11552+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11553+ sllx == 0x83287020U &&
11554+ (or & 0xFFFFE000U) == 0x8A116000U &&
11555+ jmpl == 0x81C04005U &&
11556+ nop == 0x01000000U)
11557+ {
11558+ unsigned long addr;
11559+
11560+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11561+ regs->u_regs[UREG_G1] <<= 32;
11562+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11563+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11564+ regs->tpc = addr;
11565+ regs->tnpc = addr+4;
11566+ return 2;
11567+ }
11568+ } while (0);
11569+
11570+ do { /* PaX: unpatched PLT emulation step 1 */
11571+ unsigned int sethi, ba, nop;
11572+
11573+ err = get_user(sethi, (unsigned int *)regs->tpc);
11574+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11575+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11576+
11577+ if (err)
11578+ break;
11579+
11580+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11581+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11582+ nop == 0x01000000U)
11583+ {
11584+ unsigned long addr;
11585+ unsigned int save, call;
11586+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11587+
11588+ if ((ba & 0xFFC00000U) == 0x30800000U)
11589+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11590+ else
11591+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11592+
11593+ if (test_thread_flag(TIF_32BIT))
11594+ addr &= 0xFFFFFFFFUL;
11595+
11596+ err = get_user(save, (unsigned int *)addr);
11597+ err |= get_user(call, (unsigned int *)(addr+4));
11598+ err |= get_user(nop, (unsigned int *)(addr+8));
11599+ if (err)
11600+ break;
11601+
11602+#ifdef CONFIG_PAX_DLRESOLVE
11603+ if (save == 0x9DE3BFA8U &&
11604+ (call & 0xC0000000U) == 0x40000000U &&
11605+ nop == 0x01000000U)
11606+ {
11607+ struct vm_area_struct *vma;
11608+ unsigned long call_dl_resolve;
11609+
11610+ down_read(&current->mm->mmap_sem);
11611+ call_dl_resolve = current->mm->call_dl_resolve;
11612+ up_read(&current->mm->mmap_sem);
11613+ if (likely(call_dl_resolve))
11614+ goto emulate;
11615+
11616+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11617+
11618+ down_write(&current->mm->mmap_sem);
11619+ if (current->mm->call_dl_resolve) {
11620+ call_dl_resolve = current->mm->call_dl_resolve;
11621+ up_write(&current->mm->mmap_sem);
11622+ if (vma)
11623+ kmem_cache_free(vm_area_cachep, vma);
11624+ goto emulate;
11625+ }
11626+
11627+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11628+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11629+ up_write(&current->mm->mmap_sem);
11630+ if (vma)
11631+ kmem_cache_free(vm_area_cachep, vma);
11632+ return 1;
11633+ }
11634+
11635+ if (pax_insert_vma(vma, call_dl_resolve)) {
11636+ up_write(&current->mm->mmap_sem);
11637+ kmem_cache_free(vm_area_cachep, vma);
11638+ return 1;
11639+ }
11640+
11641+ current->mm->call_dl_resolve = call_dl_resolve;
11642+ up_write(&current->mm->mmap_sem);
11643+
11644+emulate:
11645+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11646+ regs->tpc = call_dl_resolve;
11647+ regs->tnpc = addr+4;
11648+ return 3;
11649+ }
11650+#endif
11651+
11652+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11653+ if ((save & 0xFFC00000U) == 0x05000000U &&
11654+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11655+ nop == 0x01000000U)
11656+ {
11657+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11658+ regs->u_regs[UREG_G2] = addr + 4;
11659+ addr = (save & 0x003FFFFFU) << 10;
11660+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11661+
11662+ if (test_thread_flag(TIF_32BIT))
11663+ addr &= 0xFFFFFFFFUL;
11664+
11665+ regs->tpc = addr;
11666+ regs->tnpc = addr+4;
11667+ return 3;
11668+ }
11669+
11670+ /* PaX: 64-bit PLT stub */
11671+ err = get_user(sethi1, (unsigned int *)addr);
11672+ err |= get_user(sethi2, (unsigned int *)(addr+4));
11673+ err |= get_user(or1, (unsigned int *)(addr+8));
11674+ err |= get_user(or2, (unsigned int *)(addr+12));
11675+ err |= get_user(sllx, (unsigned int *)(addr+16));
11676+ err |= get_user(add, (unsigned int *)(addr+20));
11677+ err |= get_user(jmpl, (unsigned int *)(addr+24));
11678+ err |= get_user(nop, (unsigned int *)(addr+28));
11679+ if (err)
11680+ break;
11681+
11682+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11683+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11684+ (or1 & 0xFFFFE000U) == 0x88112000U &&
11685+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11686+ sllx == 0x89293020U &&
11687+ add == 0x8A010005U &&
11688+ jmpl == 0x89C14000U &&
11689+ nop == 0x01000000U)
11690+ {
11691+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11692+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11693+ regs->u_regs[UREG_G4] <<= 32;
11694+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11695+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11696+ regs->u_regs[UREG_G4] = addr + 24;
11697+ addr = regs->u_regs[UREG_G5];
11698+ regs->tpc = addr;
11699+ regs->tnpc = addr+4;
11700+ return 3;
11701+ }
11702+ }
11703+ } while (0);
11704+
11705+#ifdef CONFIG_PAX_DLRESOLVE
11706+ do { /* PaX: unpatched PLT emulation step 2 */
11707+ unsigned int save, call, nop;
11708+
11709+ err = get_user(save, (unsigned int *)(regs->tpc-4));
11710+ err |= get_user(call, (unsigned int *)regs->tpc);
11711+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11712+ if (err)
11713+ break;
11714+
11715+ if (save == 0x9DE3BFA8U &&
11716+ (call & 0xC0000000U) == 0x40000000U &&
11717+ nop == 0x01000000U)
11718+ {
11719+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11720+
11721+ if (test_thread_flag(TIF_32BIT))
11722+ dl_resolve &= 0xFFFFFFFFUL;
11723+
11724+ regs->u_regs[UREG_RETPC] = regs->tpc;
11725+ regs->tpc = dl_resolve;
11726+ regs->tnpc = dl_resolve+4;
11727+ return 3;
11728+ }
11729+ } while (0);
11730+#endif
11731+
11732+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11733+ unsigned int sethi, ba, nop;
11734+
11735+ err = get_user(sethi, (unsigned int *)regs->tpc);
11736+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11737+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11738+
11739+ if (err)
11740+ break;
11741+
11742+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11743+ (ba & 0xFFF00000U) == 0x30600000U &&
11744+ nop == 0x01000000U)
11745+ {
11746+ unsigned long addr;
11747+
11748+ addr = (sethi & 0x003FFFFFU) << 10;
11749+ regs->u_regs[UREG_G1] = addr;
11750+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11751+
11752+ if (test_thread_flag(TIF_32BIT))
11753+ addr &= 0xFFFFFFFFUL;
11754+
11755+ regs->tpc = addr;
11756+ regs->tnpc = addr+4;
11757+ return 2;
11758+ }
11759+ } while (0);
11760+
11761+#endif
11762+
11763+ return 1;
11764+}
11765+
11766+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11767+{
11768+ unsigned long i;
11769+
11770+ printk(KERN_ERR "PAX: bytes at PC: ");
11771+ for (i = 0; i < 8; i++) {
11772+ unsigned int c;
11773+ if (get_user(c, (unsigned int *)pc+i))
11774+ printk(KERN_CONT "???????? ");
11775+ else
11776+ printk(KERN_CONT "%08x ", c);
11777+ }
11778+ printk("\n");
11779+}
11780+#endif
11781+
11782 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11783 {
11784 enum ctx_state prev_state = exception_enter();
11785@@ -344,6 +807,29 @@ retry:
11786 if (!vma)
11787 goto bad_area;
11788
11789+#ifdef CONFIG_PAX_PAGEEXEC
11790+ /* PaX: detect ITLB misses on non-exec pages */
11791+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11792+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11793+ {
11794+ if (address != regs->tpc)
11795+ goto good_area;
11796+
11797+ up_read(&mm->mmap_sem);
11798+ switch (pax_handle_fetch_fault(regs)) {
11799+
11800+#ifdef CONFIG_PAX_EMUPLT
11801+ case 2:
11802+ case 3:
11803+ return;
11804+#endif
11805+
11806+ }
11807+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11808+ do_group_exit(SIGKILL);
11809+ }
11810+#endif
11811+
11812 /* Pure DTLB misses do not tell us whether the fault causing
11813 * load/store/atomic was a write or not, it only says that there
11814 * was no match. So in such a case we (carefully) read the
11815diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11816index 3096317..a7b7654 100644
11817--- a/arch/sparc/mm/hugetlbpage.c
11818+++ b/arch/sparc/mm/hugetlbpage.c
11819@@ -26,7 +26,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11820 unsigned long addr,
11821 unsigned long len,
11822 unsigned long pgoff,
11823- unsigned long flags)
11824+ unsigned long flags,
11825+ unsigned long offset)
11826 {
11827 unsigned long task_size = TASK_SIZE;
11828 struct vm_unmapped_area_info info;
11829@@ -36,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11830
11831 info.flags = 0;
11832 info.length = len;
11833- info.low_limit = TASK_UNMAPPED_BASE;
11834+ info.low_limit = mm->mmap_base;
11835 info.high_limit = min(task_size, VA_EXCLUDE_START);
11836 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11837 info.align_offset = 0;
11838+ info.threadstack_offset = offset;
11839 addr = vm_unmapped_area(&info);
11840
11841 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11842 VM_BUG_ON(addr != -ENOMEM);
11843 info.low_limit = VA_EXCLUDE_END;
11844+
11845+#ifdef CONFIG_PAX_RANDMMAP
11846+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11847+ info.low_limit += mm->delta_mmap;
11848+#endif
11849+
11850 info.high_limit = task_size;
11851 addr = vm_unmapped_area(&info);
11852 }
11853@@ -56,7 +64,8 @@ static unsigned long
11854 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11855 const unsigned long len,
11856 const unsigned long pgoff,
11857- const unsigned long flags)
11858+ const unsigned long flags,
11859+ const unsigned long offset)
11860 {
11861 struct mm_struct *mm = current->mm;
11862 unsigned long addr = addr0;
11863@@ -71,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11864 info.high_limit = mm->mmap_base;
11865 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11866 info.align_offset = 0;
11867+ info.threadstack_offset = offset;
11868 addr = vm_unmapped_area(&info);
11869
11870 /*
11871@@ -83,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11872 VM_BUG_ON(addr != -ENOMEM);
11873 info.flags = 0;
11874 info.low_limit = TASK_UNMAPPED_BASE;
11875+
11876+#ifdef CONFIG_PAX_RANDMMAP
11877+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11878+ info.low_limit += mm->delta_mmap;
11879+#endif
11880+
11881 info.high_limit = STACK_TOP32;
11882 addr = vm_unmapped_area(&info);
11883 }
11884@@ -97,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11885 struct mm_struct *mm = current->mm;
11886 struct vm_area_struct *vma;
11887 unsigned long task_size = TASK_SIZE;
11888+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11889
11890 if (test_thread_flag(TIF_32BIT))
11891 task_size = STACK_TOP32;
11892@@ -112,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11893 return addr;
11894 }
11895
11896+#ifdef CONFIG_PAX_RANDMMAP
11897+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11898+#endif
11899+
11900 if (addr) {
11901 addr = ALIGN(addr, HPAGE_SIZE);
11902 vma = find_vma(mm, addr);
11903- if (task_size - len >= addr &&
11904- (!vma || addr + len <= vma->vm_start))
11905+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11906 return addr;
11907 }
11908 if (mm->get_unmapped_area == arch_get_unmapped_area)
11909 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11910- pgoff, flags);
11911+ pgoff, flags, offset);
11912 else
11913 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11914- pgoff, flags);
11915+ pgoff, flags, offset);
11916 }
11917
11918 pte_t *huge_pte_alloc(struct mm_struct *mm,
11919diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11920index 5322e53..f820c5e 100644
11921--- a/arch/sparc/mm/init_64.c
11922+++ b/arch/sparc/mm/init_64.c
11923@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11924 int num_kernel_image_mappings;
11925
11926 #ifdef CONFIG_DEBUG_DCFLUSH
11927-atomic_t dcpage_flushes = ATOMIC_INIT(0);
11928+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11929 #ifdef CONFIG_SMP
11930-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11931+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11932 #endif
11933 #endif
11934
11935@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11936 {
11937 BUG_ON(tlb_type == hypervisor);
11938 #ifdef CONFIG_DEBUG_DCFLUSH
11939- atomic_inc(&dcpage_flushes);
11940+ atomic_inc_unchecked(&dcpage_flushes);
11941 #endif
11942
11943 #ifdef DCACHE_ALIASING_POSSIBLE
11944@@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11945
11946 #ifdef CONFIG_DEBUG_DCFLUSH
11947 seq_printf(m, "DCPageFlushes\t: %d\n",
11948- atomic_read(&dcpage_flushes));
11949+ atomic_read_unchecked(&dcpage_flushes));
11950 #ifdef CONFIG_SMP
11951 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11952- atomic_read(&dcpage_flushes_xcall));
11953+ atomic_read_unchecked(&dcpage_flushes_xcall));
11954 #endif /* CONFIG_SMP */
11955 #endif /* CONFIG_DEBUG_DCFLUSH */
11956 }
11957diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
11958index b3692ce..e4517c9 100644
11959--- a/arch/tile/Kconfig
11960+++ b/arch/tile/Kconfig
11961@@ -184,6 +184,7 @@ source "kernel/Kconfig.hz"
11962
11963 config KEXEC
11964 bool "kexec system call"
11965+ depends on !GRKERNSEC_KMEM
11966 ---help---
11967 kexec is a system call that implements the ability to shutdown your
11968 current kernel, and to start another kernel. It is like a reboot
11969diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11970index ad220ee..2f537b3 100644
11971--- a/arch/tile/include/asm/atomic_64.h
11972+++ b/arch/tile/include/asm/atomic_64.h
11973@@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11974
11975 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11976
11977+#define atomic64_read_unchecked(v) atomic64_read(v)
11978+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11979+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11980+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11981+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11982+#define atomic64_inc_unchecked(v) atomic64_inc(v)
11983+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11984+#define atomic64_dec_unchecked(v) atomic64_dec(v)
11985+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11986+
11987 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11988 #define smp_mb__before_atomic_dec() smp_mb()
11989 #define smp_mb__after_atomic_dec() smp_mb()
11990diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11991index 6160761..00cac88 100644
11992--- a/arch/tile/include/asm/cache.h
11993+++ b/arch/tile/include/asm/cache.h
11994@@ -15,11 +15,12 @@
11995 #ifndef _ASM_TILE_CACHE_H
11996 #define _ASM_TILE_CACHE_H
11997
11998+#include <linux/const.h>
11999 #include <arch/chip.h>
12000
12001 /* bytes per L1 data cache line */
12002 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12003-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12004+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12005
12006 /* bytes per L2 cache line */
12007 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12008diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12009index b6cde32..c0cb736 100644
12010--- a/arch/tile/include/asm/uaccess.h
12011+++ b/arch/tile/include/asm/uaccess.h
12012@@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12013 const void __user *from,
12014 unsigned long n)
12015 {
12016- int sz = __compiletime_object_size(to);
12017+ size_t sz = __compiletime_object_size(to);
12018
12019- if (likely(sz == -1 || sz >= n))
12020+ if (likely(sz == (size_t)-1 || sz >= n))
12021 n = _copy_from_user(to, from, n);
12022 else
12023 copy_from_user_overflow();
12024diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12025index 0cb3bba..7338b2d 100644
12026--- a/arch/tile/mm/hugetlbpage.c
12027+++ b/arch/tile/mm/hugetlbpage.c
12028@@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12029 info.high_limit = TASK_SIZE;
12030 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12031 info.align_offset = 0;
12032+ info.threadstack_offset = 0;
12033 return vm_unmapped_area(&info);
12034 }
12035
12036@@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12037 info.high_limit = current->mm->mmap_base;
12038 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12039 info.align_offset = 0;
12040+ info.threadstack_offset = 0;
12041 addr = vm_unmapped_area(&info);
12042
12043 /*
12044diff --git a/arch/um/Makefile b/arch/um/Makefile
12045index 36e658a..71a5c5a 100644
12046--- a/arch/um/Makefile
12047+++ b/arch/um/Makefile
12048@@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12049 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12050 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12051
12052+ifdef CONSTIFY_PLUGIN
12053+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12054+endif
12055+
12056 #This will adjust *FLAGS accordingly to the platform.
12057 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12058
12059diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12060index 19e1bdd..3665b77 100644
12061--- a/arch/um/include/asm/cache.h
12062+++ b/arch/um/include/asm/cache.h
12063@@ -1,6 +1,7 @@
12064 #ifndef __UM_CACHE_H
12065 #define __UM_CACHE_H
12066
12067+#include <linux/const.h>
12068
12069 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12070 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12071@@ -12,6 +13,6 @@
12072 # define L1_CACHE_SHIFT 5
12073 #endif
12074
12075-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12076+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12077
12078 #endif
12079diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12080index 2e0a6b1..a64d0f5 100644
12081--- a/arch/um/include/asm/kmap_types.h
12082+++ b/arch/um/include/asm/kmap_types.h
12083@@ -8,6 +8,6 @@
12084
12085 /* No more #include "asm/arch/kmap_types.h" ! */
12086
12087-#define KM_TYPE_NR 14
12088+#define KM_TYPE_NR 15
12089
12090 #endif
12091diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12092index 5ff53d9..5850cdf 100644
12093--- a/arch/um/include/asm/page.h
12094+++ b/arch/um/include/asm/page.h
12095@@ -14,6 +14,9 @@
12096 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12097 #define PAGE_MASK (~(PAGE_SIZE-1))
12098
12099+#define ktla_ktva(addr) (addr)
12100+#define ktva_ktla(addr) (addr)
12101+
12102 #ifndef __ASSEMBLY__
12103
12104 struct page;
12105diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12106index 0032f92..cd151e0 100644
12107--- a/arch/um/include/asm/pgtable-3level.h
12108+++ b/arch/um/include/asm/pgtable-3level.h
12109@@ -58,6 +58,7 @@
12110 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12111 #define pud_populate(mm, pud, pmd) \
12112 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12113+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12114
12115 #ifdef CONFIG_64BIT
12116 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12117diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12118index eecc414..48adb87 100644
12119--- a/arch/um/kernel/process.c
12120+++ b/arch/um/kernel/process.c
12121@@ -356,22 +356,6 @@ int singlestepping(void * t)
12122 return 2;
12123 }
12124
12125-/*
12126- * Only x86 and x86_64 have an arch_align_stack().
12127- * All other arches have "#define arch_align_stack(x) (x)"
12128- * in their asm/system.h
12129- * As this is included in UML from asm-um/system-generic.h,
12130- * we can use it to behave as the subarch does.
12131- */
12132-#ifndef arch_align_stack
12133-unsigned long arch_align_stack(unsigned long sp)
12134-{
12135- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12136- sp -= get_random_int() % 8192;
12137- return sp & ~0xf;
12138-}
12139-#endif
12140-
12141 unsigned long get_wchan(struct task_struct *p)
12142 {
12143 unsigned long stack_page, sp, ip;
12144diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12145index ad8f795..2c7eec6 100644
12146--- a/arch/unicore32/include/asm/cache.h
12147+++ b/arch/unicore32/include/asm/cache.h
12148@@ -12,8 +12,10 @@
12149 #ifndef __UNICORE_CACHE_H__
12150 #define __UNICORE_CACHE_H__
12151
12152-#define L1_CACHE_SHIFT (5)
12153-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12154+#include <linux/const.h>
12155+
12156+#define L1_CACHE_SHIFT 5
12157+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12158
12159 /*
12160 * Memory returned by kmalloc() may be used for DMA, so we must make
12161diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12162index 0952ecd..9cf578c 100644
12163--- a/arch/x86/Kconfig
12164+++ b/arch/x86/Kconfig
12165@@ -249,7 +249,7 @@ config X86_HT
12166
12167 config X86_32_LAZY_GS
12168 def_bool y
12169- depends on X86_32 && !CC_STACKPROTECTOR
12170+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12171
12172 config ARCH_HWEIGHT_CFLAGS
12173 string
12174@@ -602,6 +602,7 @@ config SCHED_OMIT_FRAME_POINTER
12175
12176 menuconfig HYPERVISOR_GUEST
12177 bool "Linux guest support"
12178+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12179 ---help---
12180 Say Y here to enable options for running Linux under various hyper-
12181 visors. This option enables basic hypervisor detection and platform
12182@@ -1127,7 +1128,7 @@ choice
12183
12184 config NOHIGHMEM
12185 bool "off"
12186- depends on !X86_NUMAQ
12187+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12188 ---help---
12189 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12190 However, the address space of 32-bit x86 processors is only 4
12191@@ -1164,7 +1165,7 @@ config NOHIGHMEM
12192
12193 config HIGHMEM4G
12194 bool "4GB"
12195- depends on !X86_NUMAQ
12196+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12197 ---help---
12198 Select this if you have a 32-bit processor and between 1 and 4
12199 gigabytes of physical RAM.
12200@@ -1217,7 +1218,7 @@ config PAGE_OFFSET
12201 hex
12202 default 0xB0000000 if VMSPLIT_3G_OPT
12203 default 0x80000000 if VMSPLIT_2G
12204- default 0x78000000 if VMSPLIT_2G_OPT
12205+ default 0x70000000 if VMSPLIT_2G_OPT
12206 default 0x40000000 if VMSPLIT_1G
12207 default 0xC0000000
12208 depends on X86_32
12209@@ -1619,6 +1620,7 @@ config SECCOMP
12210
12211 config CC_STACKPROTECTOR
12212 bool "Enable -fstack-protector buffer overflow detection"
12213+ depends on X86_64 || !PAX_MEMORY_UDEREF
12214 ---help---
12215 This option turns on the -fstack-protector GCC feature. This
12216 feature puts, at the beginning of functions, a canary value on
12217@@ -1637,6 +1639,7 @@ source kernel/Kconfig.hz
12218
12219 config KEXEC
12220 bool "kexec system call"
12221+ depends on !GRKERNSEC_KMEM
12222 ---help---
12223 kexec is a system call that implements the ability to shutdown your
12224 current kernel, and to start another kernel. It is like a reboot
12225@@ -1738,6 +1741,8 @@ config X86_NEED_RELOCS
12226 config PHYSICAL_ALIGN
12227 hex "Alignment value to which kernel should be aligned"
12228 default "0x1000000"
12229+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12230+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12231 range 0x2000 0x1000000 if X86_32
12232 range 0x200000 0x1000000 if X86_64
12233 ---help---
12234@@ -1817,9 +1822,10 @@ config DEBUG_HOTPLUG_CPU0
12235 If unsure, say N.
12236
12237 config COMPAT_VDSO
12238- def_bool y
12239+ def_bool n
12240 prompt "Compat VDSO support"
12241 depends on X86_32 || IA32_EMULATION
12242+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12243 ---help---
12244 Map the 32-bit VDSO to the predictable old-style address too.
12245
12246diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12247index c026cca..14657ae 100644
12248--- a/arch/x86/Kconfig.cpu
12249+++ b/arch/x86/Kconfig.cpu
12250@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12251
12252 config X86_F00F_BUG
12253 def_bool y
12254- depends on M586MMX || M586TSC || M586 || M486
12255+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12256
12257 config X86_INVD_BUG
12258 def_bool y
12259@@ -327,7 +327,7 @@ config X86_INVD_BUG
12260
12261 config X86_ALIGNMENT_16
12262 def_bool y
12263- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12264+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12265
12266 config X86_INTEL_USERCOPY
12267 def_bool y
12268@@ -373,7 +373,7 @@ config X86_CMPXCHG64
12269 # generates cmov.
12270 config X86_CMOV
12271 def_bool y
12272- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12273+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12274
12275 config X86_MINIMUM_CPU_FAMILY
12276 int
12277diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12278index 0f3621e..282f24b 100644
12279--- a/arch/x86/Kconfig.debug
12280+++ b/arch/x86/Kconfig.debug
12281@@ -84,7 +84,7 @@ config X86_PTDUMP
12282 config DEBUG_RODATA
12283 bool "Write protect kernel read-only data structures"
12284 default y
12285- depends on DEBUG_KERNEL
12286+ depends on DEBUG_KERNEL && BROKEN
12287 ---help---
12288 Mark the kernel read-only data as write-protected in the pagetables,
12289 in order to catch accidental (and incorrect) writes to such const
12290@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
12291
12292 config DEBUG_SET_MODULE_RONX
12293 bool "Set loadable kernel module data as NX and text as RO"
12294- depends on MODULES
12295+ depends on MODULES && BROKEN
12296 ---help---
12297 This option helps catch unintended modifications to loadable
12298 kernel module's text and read-only data. It also prevents execution
12299diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12300index 57d0215..b4373fb 100644
12301--- a/arch/x86/Makefile
12302+++ b/arch/x86/Makefile
12303@@ -49,14 +49,12 @@ ifeq ($(CONFIG_X86_32),y)
12304 # CPU-specific tuning. Anything which can be shared with UML should go here.
12305 include $(srctree)/arch/x86/Makefile_32.cpu
12306 KBUILD_CFLAGS += $(cflags-y)
12307-
12308- # temporary until string.h is fixed
12309- KBUILD_CFLAGS += -ffreestanding
12310 else
12311 BITS := 64
12312 UTS_MACHINE := x86_64
12313 CHECKFLAGS += -D__x86_64__ -m64
12314
12315+ biarch := $(call cc-option,-m64)
12316 KBUILD_AFLAGS += -m64
12317 KBUILD_CFLAGS += -m64
12318
12319@@ -89,6 +87,9 @@ else
12320 KBUILD_CFLAGS += -maccumulate-outgoing-args
12321 endif
12322
12323+# temporary until string.h is fixed
12324+KBUILD_CFLAGS += -ffreestanding
12325+
12326 ifdef CONFIG_CC_STACKPROTECTOR
12327 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12328 ifeq ($(shell $(CONFIG_SHELL) $(cc_has_sp) $(CC) $(KBUILD_CPPFLAGS) $(biarch)),y)
12329@@ -247,3 +248,12 @@ define archhelp
12330 echo ' FDINITRD=file initrd for the booted kernel'
12331 echo ' kvmconfig - Enable additional options for guest kernel support'
12332 endef
12333+
12334+define OLD_LD
12335+
12336+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12337+*** Please upgrade your binutils to 2.18 or newer
12338+endef
12339+
12340+archprepare:
12341+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12342diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12343index d9c1195..a26ca0d 100644
12344--- a/arch/x86/boot/Makefile
12345+++ b/arch/x86/boot/Makefile
12346@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ \
12347 $(call cc-option, -fno-unit-at-a-time)) \
12348 $(call cc-option, -fno-stack-protector) \
12349 $(call cc-option, -mpreferred-stack-boundary=2)
12350+ifdef CONSTIFY_PLUGIN
12351+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12352+endif
12353 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12354 GCOV_PROFILE := n
12355
12356diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12357index 878e4b9..20537ab 100644
12358--- a/arch/x86/boot/bitops.h
12359+++ b/arch/x86/boot/bitops.h
12360@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12361 u8 v;
12362 const u32 *p = (const u32 *)addr;
12363
12364- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12365+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12366 return v;
12367 }
12368
12369@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12370
12371 static inline void set_bit(int nr, void *addr)
12372 {
12373- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12374+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12375 }
12376
12377 #endif /* BOOT_BITOPS_H */
12378diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12379index ef72bae..353a184 100644
12380--- a/arch/x86/boot/boot.h
12381+++ b/arch/x86/boot/boot.h
12382@@ -85,7 +85,7 @@ static inline void io_delay(void)
12383 static inline u16 ds(void)
12384 {
12385 u16 seg;
12386- asm("movw %%ds,%0" : "=rm" (seg));
12387+ asm volatile("movw %%ds,%0" : "=rm" (seg));
12388 return seg;
12389 }
12390
12391@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
12392 static inline int memcmp(const void *s1, const void *s2, size_t len)
12393 {
12394 u8 diff;
12395- asm("repe; cmpsb; setnz %0"
12396+ asm volatile("repe; cmpsb; setnz %0"
12397 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
12398 return diff;
12399 }
12400diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12401index c8a6792..2402765 100644
12402--- a/arch/x86/boot/compressed/Makefile
12403+++ b/arch/x86/boot/compressed/Makefile
12404@@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12405 KBUILD_CFLAGS += -mno-mmx -mno-sse
12406 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12407 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12408+ifdef CONSTIFY_PLUGIN
12409+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12410+endif
12411
12412 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12413 GCOV_PROFILE := n
12414diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12415index a53440e..c3dbf1e 100644
12416--- a/arch/x86/boot/compressed/efi_stub_32.S
12417+++ b/arch/x86/boot/compressed/efi_stub_32.S
12418@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12419 * parameter 2, ..., param n. To make things easy, we save the return
12420 * address of efi_call_phys in a global variable.
12421 */
12422- popl %ecx
12423- movl %ecx, saved_return_addr(%edx)
12424- /* get the function pointer into ECX*/
12425- popl %ecx
12426- movl %ecx, efi_rt_function_ptr(%edx)
12427+ popl saved_return_addr(%edx)
12428+ popl efi_rt_function_ptr(%edx)
12429
12430 /*
12431 * 3. Call the physical function.
12432 */
12433- call *%ecx
12434+ call *efi_rt_function_ptr(%edx)
12435
12436 /*
12437 * 4. Balance the stack. And because EAX contain the return value,
12438@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12439 1: popl %edx
12440 subl $1b, %edx
12441
12442- movl efi_rt_function_ptr(%edx), %ecx
12443- pushl %ecx
12444+ pushl efi_rt_function_ptr(%edx)
12445
12446 /*
12447 * 10. Push the saved return address onto the stack and return.
12448 */
12449- movl saved_return_addr(%edx), %ecx
12450- pushl %ecx
12451- ret
12452+ jmpl *saved_return_addr(%edx)
12453 ENDPROC(efi_call_phys)
12454 .previous
12455
12456diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12457index 5d6f689..9d06730 100644
12458--- a/arch/x86/boot/compressed/head_32.S
12459+++ b/arch/x86/boot/compressed/head_32.S
12460@@ -118,7 +118,7 @@ preferred_addr:
12461 notl %eax
12462 andl %eax, %ebx
12463 #else
12464- movl $LOAD_PHYSICAL_ADDR, %ebx
12465+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12466 #endif
12467
12468 /* Target address to relocate to for decompression */
12469diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12470index c337422..2c5be72 100644
12471--- a/arch/x86/boot/compressed/head_64.S
12472+++ b/arch/x86/boot/compressed/head_64.S
12473@@ -95,7 +95,7 @@ ENTRY(startup_32)
12474 notl %eax
12475 andl %eax, %ebx
12476 #else
12477- movl $LOAD_PHYSICAL_ADDR, %ebx
12478+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12479 #endif
12480
12481 /* Target address to relocate to for decompression */
12482@@ -270,7 +270,7 @@ preferred_addr:
12483 notq %rax
12484 andq %rax, %rbp
12485 #else
12486- movq $LOAD_PHYSICAL_ADDR, %rbp
12487+ movq $____LOAD_PHYSICAL_ADDR, %rbp
12488 #endif
12489
12490 /* Target address to relocate to for decompression */
12491@@ -362,8 +362,8 @@ gdt:
12492 .long gdt
12493 .word 0
12494 .quad 0x0000000000000000 /* NULL descriptor */
12495- .quad 0x00af9a000000ffff /* __KERNEL_CS */
12496- .quad 0x00cf92000000ffff /* __KERNEL_DS */
12497+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
12498+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
12499 .quad 0x0080890000000000 /* TS descriptor */
12500 .quad 0x0000000000000000 /* TS continued */
12501 gdt_end:
12502diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12503index 434f077..f20f3ff 100644
12504--- a/arch/x86/boot/compressed/misc.c
12505+++ b/arch/x86/boot/compressed/misc.c
12506@@ -224,7 +224,7 @@ void __putstr(const char *s)
12507
12508 void *memset(void *s, int c, size_t n)
12509 {
12510- int i;
12511+ size_t i;
12512 char *ss = s;
12513
12514 for (i = 0; i < n; i++)
12515@@ -283,7 +283,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12516 * Calculate the delta between where vmlinux was linked to load
12517 * and where it was actually loaded.
12518 */
12519- delta = min_addr - LOAD_PHYSICAL_ADDR;
12520+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12521 if (!delta) {
12522 debug_putstr("No relocation needed... ");
12523 return;
12524@@ -353,7 +353,7 @@ static void parse_elf(void *output)
12525 Elf32_Ehdr ehdr;
12526 Elf32_Phdr *phdrs, *phdr;
12527 #endif
12528- void *dest;
12529+ void *dest, *prev;
12530 int i;
12531
12532 memcpy(&ehdr, output, sizeof(ehdr));
12533@@ -380,13 +380,16 @@ static void parse_elf(void *output)
12534 case PT_LOAD:
12535 #ifdef CONFIG_RELOCATABLE
12536 dest = output;
12537- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12538+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12539 #else
12540 dest = (void *)(phdr->p_paddr);
12541 #endif
12542 memcpy(dest,
12543 output + phdr->p_offset,
12544 phdr->p_filesz);
12545+ if (i)
12546+ memset(prev, 0xff, dest - prev);
12547+ prev = dest + phdr->p_filesz;
12548 break;
12549 default: /* Ignore other PT_* */ break;
12550 }
12551@@ -432,7 +435,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
12552 error("Destination address too large");
12553 #endif
12554 #ifndef CONFIG_RELOCATABLE
12555- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12556+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12557 error("Wrong destination address");
12558 #endif
12559
12560diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12561index 4d3ff03..e4972ff 100644
12562--- a/arch/x86/boot/cpucheck.c
12563+++ b/arch/x86/boot/cpucheck.c
12564@@ -74,7 +74,7 @@ static int has_fpu(void)
12565 u16 fcw = -1, fsw = -1;
12566 u32 cr0;
12567
12568- asm("movl %%cr0,%0" : "=r" (cr0));
12569+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
12570 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
12571 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
12572 asm volatile("movl %0,%%cr0" : : "r" (cr0));
12573@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
12574 {
12575 u32 f0, f1;
12576
12577- asm("pushfl ; "
12578+ asm volatile("pushfl ; "
12579 "pushfl ; "
12580 "popl %0 ; "
12581 "movl %0,%1 ; "
12582@@ -115,7 +115,7 @@ static void get_flags(void)
12583 set_bit(X86_FEATURE_FPU, cpu.flags);
12584
12585 if (has_eflag(X86_EFLAGS_ID)) {
12586- asm("cpuid"
12587+ asm volatile("cpuid"
12588 : "=a" (max_intel_level),
12589 "=b" (cpu_vendor[0]),
12590 "=d" (cpu_vendor[1]),
12591@@ -124,7 +124,7 @@ static void get_flags(void)
12592
12593 if (max_intel_level >= 0x00000001 &&
12594 max_intel_level <= 0x0000ffff) {
12595- asm("cpuid"
12596+ asm volatile("cpuid"
12597 : "=a" (tfms),
12598 "=c" (cpu.flags[4]),
12599 "=d" (cpu.flags[0])
12600@@ -136,7 +136,7 @@ static void get_flags(void)
12601 cpu.model += ((tfms >> 16) & 0xf) << 4;
12602 }
12603
12604- asm("cpuid"
12605+ asm volatile("cpuid"
12606 : "=a" (max_amd_level)
12607 : "a" (0x80000000)
12608 : "ebx", "ecx", "edx");
12609@@ -144,7 +144,7 @@ static void get_flags(void)
12610 if (max_amd_level >= 0x80000001 &&
12611 max_amd_level <= 0x8000ffff) {
12612 u32 eax = 0x80000001;
12613- asm("cpuid"
12614+ asm volatile("cpuid"
12615 : "+a" (eax),
12616 "=c" (cpu.flags[6]),
12617 "=d" (cpu.flags[1])
12618@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12619 u32 ecx = MSR_K7_HWCR;
12620 u32 eax, edx;
12621
12622- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12623+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12624 eax &= ~(1 << 15);
12625- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12626+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12627
12628 get_flags(); /* Make sure it really did something */
12629 err = check_flags();
12630@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12631 u32 ecx = MSR_VIA_FCR;
12632 u32 eax, edx;
12633
12634- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12635+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12636 eax |= (1<<1)|(1<<7);
12637- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12638+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12639
12640 set_bit(X86_FEATURE_CX8, cpu.flags);
12641 err = check_flags();
12642@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12643 u32 eax, edx;
12644 u32 level = 1;
12645
12646- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12647- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12648- asm("cpuid"
12649+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12650+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12651+ asm volatile("cpuid"
12652 : "+a" (level), "=d" (cpu.flags[0])
12653 : : "ecx", "ebx");
12654- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12655+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12656
12657 err = check_flags();
12658 }
12659diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12660index 9ec06a1..2c25e79 100644
12661--- a/arch/x86/boot/header.S
12662+++ b/arch/x86/boot/header.S
12663@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12664 # single linked list of
12665 # struct setup_data
12666
12667-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12668+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12669
12670 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12671+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12672+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12673+#else
12674 #define VO_INIT_SIZE (VO__end - VO__text)
12675+#endif
12676 #if ZO_INIT_SIZE > VO_INIT_SIZE
12677 #define INIT_SIZE ZO_INIT_SIZE
12678 #else
12679diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12680index db75d07..8e6d0af 100644
12681--- a/arch/x86/boot/memory.c
12682+++ b/arch/x86/boot/memory.c
12683@@ -19,7 +19,7 @@
12684
12685 static int detect_memory_e820(void)
12686 {
12687- int count = 0;
12688+ unsigned int count = 0;
12689 struct biosregs ireg, oreg;
12690 struct e820entry *desc = boot_params.e820_map;
12691 static struct e820entry buf; /* static so it is zeroed */
12692diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12693index 11e8c6e..fdbb1ed 100644
12694--- a/arch/x86/boot/video-vesa.c
12695+++ b/arch/x86/boot/video-vesa.c
12696@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12697
12698 boot_params.screen_info.vesapm_seg = oreg.es;
12699 boot_params.screen_info.vesapm_off = oreg.di;
12700+ boot_params.screen_info.vesapm_size = oreg.cx;
12701 }
12702
12703 /*
12704diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12705index 43eda28..5ab5fdb 100644
12706--- a/arch/x86/boot/video.c
12707+++ b/arch/x86/boot/video.c
12708@@ -96,7 +96,7 @@ static void store_mode_params(void)
12709 static unsigned int get_entry(void)
12710 {
12711 char entry_buf[4];
12712- int i, len = 0;
12713+ unsigned int i, len = 0;
12714 int key;
12715 unsigned int v;
12716
12717diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12718index 9105655..41779c1 100644
12719--- a/arch/x86/crypto/aes-x86_64-asm_64.S
12720+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12721@@ -8,6 +8,8 @@
12722 * including this sentence is retained in full.
12723 */
12724
12725+#include <asm/alternative-asm.h>
12726+
12727 .extern crypto_ft_tab
12728 .extern crypto_it_tab
12729 .extern crypto_fl_tab
12730@@ -70,6 +72,8 @@
12731 je B192; \
12732 leaq 32(r9),r9;
12733
12734+#define ret pax_force_retaddr; ret
12735+
12736 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12737 movq r1,r2; \
12738 movq r3,r4; \
12739diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12740index 477e9d7..c92c7d8 100644
12741--- a/arch/x86/crypto/aesni-intel_asm.S
12742+++ b/arch/x86/crypto/aesni-intel_asm.S
12743@@ -31,6 +31,7 @@
12744
12745 #include <linux/linkage.h>
12746 #include <asm/inst.h>
12747+#include <asm/alternative-asm.h>
12748
12749 #ifdef __x86_64__
12750 .data
12751@@ -205,7 +206,7 @@ enc: .octa 0x2
12752 * num_initial_blocks = b mod 4
12753 * encrypt the initial num_initial_blocks blocks and apply ghash on
12754 * the ciphertext
12755-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12756+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12757 * are clobbered
12758 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12759 */
12760@@ -214,8 +215,8 @@ enc: .octa 0x2
12761 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12762 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12763 mov arg7, %r10 # %r10 = AAD
12764- mov arg8, %r12 # %r12 = aadLen
12765- mov %r12, %r11
12766+ mov arg8, %r15 # %r15 = aadLen
12767+ mov %r15, %r11
12768 pxor %xmm\i, %xmm\i
12769 _get_AAD_loop\num_initial_blocks\operation:
12770 movd (%r10), \TMP1
12771@@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12772 psrldq $4, %xmm\i
12773 pxor \TMP1, %xmm\i
12774 add $4, %r10
12775- sub $4, %r12
12776+ sub $4, %r15
12777 jne _get_AAD_loop\num_initial_blocks\operation
12778 cmp $16, %r11
12779 je _get_AAD_loop2_done\num_initial_blocks\operation
12780- mov $16, %r12
12781+ mov $16, %r15
12782 _get_AAD_loop2\num_initial_blocks\operation:
12783 psrldq $4, %xmm\i
12784- sub $4, %r12
12785- cmp %r11, %r12
12786+ sub $4, %r15
12787+ cmp %r11, %r15
12788 jne _get_AAD_loop2\num_initial_blocks\operation
12789 _get_AAD_loop2_done\num_initial_blocks\operation:
12790 movdqa SHUF_MASK(%rip), %xmm14
12791@@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12792 * num_initial_blocks = b mod 4
12793 * encrypt the initial num_initial_blocks blocks and apply ghash on
12794 * the ciphertext
12795-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12796+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12797 * are clobbered
12798 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12799 */
12800@@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12801 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12802 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12803 mov arg7, %r10 # %r10 = AAD
12804- mov arg8, %r12 # %r12 = aadLen
12805- mov %r12, %r11
12806+ mov arg8, %r15 # %r15 = aadLen
12807+ mov %r15, %r11
12808 pxor %xmm\i, %xmm\i
12809 _get_AAD_loop\num_initial_blocks\operation:
12810 movd (%r10), \TMP1
12811@@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12812 psrldq $4, %xmm\i
12813 pxor \TMP1, %xmm\i
12814 add $4, %r10
12815- sub $4, %r12
12816+ sub $4, %r15
12817 jne _get_AAD_loop\num_initial_blocks\operation
12818 cmp $16, %r11
12819 je _get_AAD_loop2_done\num_initial_blocks\operation
12820- mov $16, %r12
12821+ mov $16, %r15
12822 _get_AAD_loop2\num_initial_blocks\operation:
12823 psrldq $4, %xmm\i
12824- sub $4, %r12
12825- cmp %r11, %r12
12826+ sub $4, %r15
12827+ cmp %r11, %r15
12828 jne _get_AAD_loop2\num_initial_blocks\operation
12829 _get_AAD_loop2_done\num_initial_blocks\operation:
12830 movdqa SHUF_MASK(%rip), %xmm14
12831@@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12832 *
12833 *****************************************************************************/
12834 ENTRY(aesni_gcm_dec)
12835- push %r12
12836+ push %r15
12837 push %r13
12838 push %r14
12839 mov %rsp, %r14
12840@@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12841 */
12842 sub $VARIABLE_OFFSET, %rsp
12843 and $~63, %rsp # align rsp to 64 bytes
12844- mov %arg6, %r12
12845- movdqu (%r12), %xmm13 # %xmm13 = HashKey
12846+ mov %arg6, %r15
12847+ movdqu (%r15), %xmm13 # %xmm13 = HashKey
12848 movdqa SHUF_MASK(%rip), %xmm2
12849 PSHUFB_XMM %xmm2, %xmm13
12850
12851@@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12852 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12853 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12854 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12855- mov %r13, %r12
12856- and $(3<<4), %r12
12857+ mov %r13, %r15
12858+ and $(3<<4), %r15
12859 jz _initial_num_blocks_is_0_decrypt
12860- cmp $(2<<4), %r12
12861+ cmp $(2<<4), %r15
12862 jb _initial_num_blocks_is_1_decrypt
12863 je _initial_num_blocks_is_2_decrypt
12864 _initial_num_blocks_is_3_decrypt:
12865@@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12866 sub $16, %r11
12867 add %r13, %r11
12868 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12869- lea SHIFT_MASK+16(%rip), %r12
12870- sub %r13, %r12
12871+ lea SHIFT_MASK+16(%rip), %r15
12872+ sub %r13, %r15
12873 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12874 # (%r13 is the number of bytes in plaintext mod 16)
12875- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12876+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12877 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12878
12879 movdqa %xmm1, %xmm2
12880 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12881- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12882+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12883 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12884 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12885 pand %xmm1, %xmm2
12886@@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12887 sub $1, %r13
12888 jne _less_than_8_bytes_left_decrypt
12889 _multiple_of_16_bytes_decrypt:
12890- mov arg8, %r12 # %r13 = aadLen (number of bytes)
12891- shl $3, %r12 # convert into number of bits
12892- movd %r12d, %xmm15 # len(A) in %xmm15
12893+ mov arg8, %r15 # %r13 = aadLen (number of bytes)
12894+ shl $3, %r15 # convert into number of bits
12895+ movd %r15d, %xmm15 # len(A) in %xmm15
12896 shl $3, %arg4 # len(C) in bits (*128)
12897 MOVQ_R64_XMM %arg4, %xmm1
12898 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12899@@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12900 mov %r14, %rsp
12901 pop %r14
12902 pop %r13
12903- pop %r12
12904+ pop %r15
12905+ pax_force_retaddr
12906 ret
12907 ENDPROC(aesni_gcm_dec)
12908
12909@@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12910 * poly = x^128 + x^127 + x^126 + x^121 + 1
12911 ***************************************************************************/
12912 ENTRY(aesni_gcm_enc)
12913- push %r12
12914+ push %r15
12915 push %r13
12916 push %r14
12917 mov %rsp, %r14
12918@@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
12919 #
12920 sub $VARIABLE_OFFSET, %rsp
12921 and $~63, %rsp
12922- mov %arg6, %r12
12923- movdqu (%r12), %xmm13
12924+ mov %arg6, %r15
12925+ movdqu (%r15), %xmm13
12926 movdqa SHUF_MASK(%rip), %xmm2
12927 PSHUFB_XMM %xmm2, %xmm13
12928
12929@@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
12930 movdqa %xmm13, HashKey(%rsp)
12931 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
12932 and $-16, %r13
12933- mov %r13, %r12
12934+ mov %r13, %r15
12935
12936 # Encrypt first few blocks
12937
12938- and $(3<<4), %r12
12939+ and $(3<<4), %r15
12940 jz _initial_num_blocks_is_0_encrypt
12941- cmp $(2<<4), %r12
12942+ cmp $(2<<4), %r15
12943 jb _initial_num_blocks_is_1_encrypt
12944 je _initial_num_blocks_is_2_encrypt
12945 _initial_num_blocks_is_3_encrypt:
12946@@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
12947 sub $16, %r11
12948 add %r13, %r11
12949 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
12950- lea SHIFT_MASK+16(%rip), %r12
12951- sub %r13, %r12
12952+ lea SHIFT_MASK+16(%rip), %r15
12953+ sub %r13, %r15
12954 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
12955 # (%r13 is the number of bytes in plaintext mod 16)
12956- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12957+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12958 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
12959 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
12960- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12961+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12962 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
12963 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
12964 movdqa SHUF_MASK(%rip), %xmm10
12965@@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
12966 sub $1, %r13
12967 jne _less_than_8_bytes_left_encrypt
12968 _multiple_of_16_bytes_encrypt:
12969- mov arg8, %r12 # %r12 = addLen (number of bytes)
12970- shl $3, %r12
12971- movd %r12d, %xmm15 # len(A) in %xmm15
12972+ mov arg8, %r15 # %r15 = addLen (number of bytes)
12973+ shl $3, %r15
12974+ movd %r15d, %xmm15 # len(A) in %xmm15
12975 shl $3, %arg4 # len(C) in bits (*128)
12976 MOVQ_R64_XMM %arg4, %xmm1
12977 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12978@@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
12979 mov %r14, %rsp
12980 pop %r14
12981 pop %r13
12982- pop %r12
12983+ pop %r15
12984+ pax_force_retaddr
12985 ret
12986 ENDPROC(aesni_gcm_enc)
12987
12988@@ -1722,6 +1725,7 @@ _key_expansion_256a:
12989 pxor %xmm1, %xmm0
12990 movaps %xmm0, (TKEYP)
12991 add $0x10, TKEYP
12992+ pax_force_retaddr
12993 ret
12994 ENDPROC(_key_expansion_128)
12995 ENDPROC(_key_expansion_256a)
12996@@ -1748,6 +1752,7 @@ _key_expansion_192a:
12997 shufps $0b01001110, %xmm2, %xmm1
12998 movaps %xmm1, 0x10(TKEYP)
12999 add $0x20, TKEYP
13000+ pax_force_retaddr
13001 ret
13002 ENDPROC(_key_expansion_192a)
13003
13004@@ -1768,6 +1773,7 @@ _key_expansion_192b:
13005
13006 movaps %xmm0, (TKEYP)
13007 add $0x10, TKEYP
13008+ pax_force_retaddr
13009 ret
13010 ENDPROC(_key_expansion_192b)
13011
13012@@ -1781,6 +1787,7 @@ _key_expansion_256b:
13013 pxor %xmm1, %xmm2
13014 movaps %xmm2, (TKEYP)
13015 add $0x10, TKEYP
13016+ pax_force_retaddr
13017 ret
13018 ENDPROC(_key_expansion_256b)
13019
13020@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13021 #ifndef __x86_64__
13022 popl KEYP
13023 #endif
13024+ pax_force_retaddr
13025 ret
13026 ENDPROC(aesni_set_key)
13027
13028@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13029 popl KLEN
13030 popl KEYP
13031 #endif
13032+ pax_force_retaddr
13033 ret
13034 ENDPROC(aesni_enc)
13035
13036@@ -1974,6 +1983,7 @@ _aesni_enc1:
13037 AESENC KEY STATE
13038 movaps 0x70(TKEYP), KEY
13039 AESENCLAST KEY STATE
13040+ pax_force_retaddr
13041 ret
13042 ENDPROC(_aesni_enc1)
13043
13044@@ -2083,6 +2093,7 @@ _aesni_enc4:
13045 AESENCLAST KEY STATE2
13046 AESENCLAST KEY STATE3
13047 AESENCLAST KEY STATE4
13048+ pax_force_retaddr
13049 ret
13050 ENDPROC(_aesni_enc4)
13051
13052@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13053 popl KLEN
13054 popl KEYP
13055 #endif
13056+ pax_force_retaddr
13057 ret
13058 ENDPROC(aesni_dec)
13059
13060@@ -2164,6 +2176,7 @@ _aesni_dec1:
13061 AESDEC KEY STATE
13062 movaps 0x70(TKEYP), KEY
13063 AESDECLAST KEY STATE
13064+ pax_force_retaddr
13065 ret
13066 ENDPROC(_aesni_dec1)
13067
13068@@ -2273,6 +2286,7 @@ _aesni_dec4:
13069 AESDECLAST KEY STATE2
13070 AESDECLAST KEY STATE3
13071 AESDECLAST KEY STATE4
13072+ pax_force_retaddr
13073 ret
13074 ENDPROC(_aesni_dec4)
13075
13076@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13077 popl KEYP
13078 popl LEN
13079 #endif
13080+ pax_force_retaddr
13081 ret
13082 ENDPROC(aesni_ecb_enc)
13083
13084@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13085 popl KEYP
13086 popl LEN
13087 #endif
13088+ pax_force_retaddr
13089 ret
13090 ENDPROC(aesni_ecb_dec)
13091
13092@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13093 popl LEN
13094 popl IVP
13095 #endif
13096+ pax_force_retaddr
13097 ret
13098 ENDPROC(aesni_cbc_enc)
13099
13100@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13101 popl LEN
13102 popl IVP
13103 #endif
13104+ pax_force_retaddr
13105 ret
13106 ENDPROC(aesni_cbc_dec)
13107
13108@@ -2550,6 +2568,7 @@ _aesni_inc_init:
13109 mov $1, TCTR_LOW
13110 MOVQ_R64_XMM TCTR_LOW INC
13111 MOVQ_R64_XMM CTR TCTR_LOW
13112+ pax_force_retaddr
13113 ret
13114 ENDPROC(_aesni_inc_init)
13115
13116@@ -2579,6 +2598,7 @@ _aesni_inc:
13117 .Linc_low:
13118 movaps CTR, IV
13119 PSHUFB_XMM BSWAP_MASK IV
13120+ pax_force_retaddr
13121 ret
13122 ENDPROC(_aesni_inc)
13123
13124@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13125 .Lctr_enc_ret:
13126 movups IV, (IVP)
13127 .Lctr_enc_just_ret:
13128+ pax_force_retaddr
13129 ret
13130 ENDPROC(aesni_ctr_enc)
13131
13132@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13133 pxor INC, STATE4
13134 movdqu STATE4, 0x70(OUTP)
13135
13136+ pax_force_retaddr
13137 ret
13138 ENDPROC(aesni_xts_crypt8)
13139
13140diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13141index 246c670..466e2d6 100644
13142--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13143+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13144@@ -21,6 +21,7 @@
13145 */
13146
13147 #include <linux/linkage.h>
13148+#include <asm/alternative-asm.h>
13149
13150 .file "blowfish-x86_64-asm.S"
13151 .text
13152@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13153 jnz .L__enc_xor;
13154
13155 write_block();
13156+ pax_force_retaddr
13157 ret;
13158 .L__enc_xor:
13159 xor_block();
13160+ pax_force_retaddr
13161 ret;
13162 ENDPROC(__blowfish_enc_blk)
13163
13164@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13165
13166 movq %r11, %rbp;
13167
13168+ pax_force_retaddr
13169 ret;
13170 ENDPROC(blowfish_dec_blk)
13171
13172@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13173
13174 popq %rbx;
13175 popq %rbp;
13176+ pax_force_retaddr
13177 ret;
13178
13179 .L__enc_xor4:
13180@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13181
13182 popq %rbx;
13183 popq %rbp;
13184+ pax_force_retaddr
13185 ret;
13186 ENDPROC(__blowfish_enc_blk_4way)
13187
13188@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13189 popq %rbx;
13190 popq %rbp;
13191
13192+ pax_force_retaddr
13193 ret;
13194 ENDPROC(blowfish_dec_blk_4way)
13195diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13196index ce71f92..1dce7ec 100644
13197--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13198+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13199@@ -16,6 +16,7 @@
13200 */
13201
13202 #include <linux/linkage.h>
13203+#include <asm/alternative-asm.h>
13204
13205 #define CAMELLIA_TABLE_BYTE_LEN 272
13206
13207@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13208 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13209 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13210 %rcx, (%r9));
13211+ pax_force_retaddr
13212 ret;
13213 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13214
13215@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13216 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13217 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13218 %rax, (%r9));
13219+ pax_force_retaddr
13220 ret;
13221 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13222
13223@@ -780,6 +783,7 @@ __camellia_enc_blk16:
13224 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13225 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13226
13227+ pax_force_retaddr
13228 ret;
13229
13230 .align 8
13231@@ -865,6 +869,7 @@ __camellia_dec_blk16:
13232 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13233 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13234
13235+ pax_force_retaddr
13236 ret;
13237
13238 .align 8
13239@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13240 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13241 %xmm8, %rsi);
13242
13243+ pax_force_retaddr
13244 ret;
13245 ENDPROC(camellia_ecb_enc_16way)
13246
13247@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13248 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13249 %xmm8, %rsi);
13250
13251+ pax_force_retaddr
13252 ret;
13253 ENDPROC(camellia_ecb_dec_16way)
13254
13255@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13256 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13257 %xmm8, %rsi);
13258
13259+ pax_force_retaddr
13260 ret;
13261 ENDPROC(camellia_cbc_dec_16way)
13262
13263@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13264 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13265 %xmm8, %rsi);
13266
13267+ pax_force_retaddr
13268 ret;
13269 ENDPROC(camellia_ctr_16way)
13270
13271@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13272 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13273 %xmm8, %rsi);
13274
13275+ pax_force_retaddr
13276 ret;
13277 ENDPROC(camellia_xts_crypt_16way)
13278
13279diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13280index 0e0b886..5a3123c 100644
13281--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13282+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13283@@ -11,6 +11,7 @@
13284 */
13285
13286 #include <linux/linkage.h>
13287+#include <asm/alternative-asm.h>
13288
13289 #define CAMELLIA_TABLE_BYTE_LEN 272
13290
13291@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13292 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13293 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13294 %rcx, (%r9));
13295+ pax_force_retaddr
13296 ret;
13297 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13298
13299@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13300 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13301 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13302 %rax, (%r9));
13303+ pax_force_retaddr
13304 ret;
13305 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13306
13307@@ -820,6 +823,7 @@ __camellia_enc_blk32:
13308 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13309 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13310
13311+ pax_force_retaddr
13312 ret;
13313
13314 .align 8
13315@@ -905,6 +909,7 @@ __camellia_dec_blk32:
13316 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13317 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13318
13319+ pax_force_retaddr
13320 ret;
13321
13322 .align 8
13323@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13324
13325 vzeroupper;
13326
13327+ pax_force_retaddr
13328 ret;
13329 ENDPROC(camellia_ecb_enc_32way)
13330
13331@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13332
13333 vzeroupper;
13334
13335+ pax_force_retaddr
13336 ret;
13337 ENDPROC(camellia_ecb_dec_32way)
13338
13339@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13340
13341 vzeroupper;
13342
13343+ pax_force_retaddr
13344 ret;
13345 ENDPROC(camellia_cbc_dec_32way)
13346
13347@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13348
13349 vzeroupper;
13350
13351+ pax_force_retaddr
13352 ret;
13353 ENDPROC(camellia_ctr_32way)
13354
13355@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13356
13357 vzeroupper;
13358
13359+ pax_force_retaddr
13360 ret;
13361 ENDPROC(camellia_xts_crypt_32way)
13362
13363diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13364index 310319c..db3d7b5 100644
13365--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13366+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13367@@ -21,6 +21,7 @@
13368 */
13369
13370 #include <linux/linkage.h>
13371+#include <asm/alternative-asm.h>
13372
13373 .file "camellia-x86_64-asm_64.S"
13374 .text
13375@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13376 enc_outunpack(mov, RT1);
13377
13378 movq RRBP, %rbp;
13379+ pax_force_retaddr
13380 ret;
13381
13382 .L__enc_xor:
13383 enc_outunpack(xor, RT1);
13384
13385 movq RRBP, %rbp;
13386+ pax_force_retaddr
13387 ret;
13388 ENDPROC(__camellia_enc_blk)
13389
13390@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13391 dec_outunpack();
13392
13393 movq RRBP, %rbp;
13394+ pax_force_retaddr
13395 ret;
13396 ENDPROC(camellia_dec_blk)
13397
13398@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13399
13400 movq RRBP, %rbp;
13401 popq %rbx;
13402+ pax_force_retaddr
13403 ret;
13404
13405 .L__enc2_xor:
13406@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13407
13408 movq RRBP, %rbp;
13409 popq %rbx;
13410+ pax_force_retaddr
13411 ret;
13412 ENDPROC(__camellia_enc_blk_2way)
13413
13414@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13415
13416 movq RRBP, %rbp;
13417 movq RXOR, %rbx;
13418+ pax_force_retaddr
13419 ret;
13420 ENDPROC(camellia_dec_blk_2way)
13421diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13422index c35fd5d..2d8c7db 100644
13423--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13424+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13425@@ -24,6 +24,7 @@
13426 */
13427
13428 #include <linux/linkage.h>
13429+#include <asm/alternative-asm.h>
13430
13431 .file "cast5-avx-x86_64-asm_64.S"
13432
13433@@ -281,6 +282,7 @@ __cast5_enc_blk16:
13434 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13435 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13436
13437+ pax_force_retaddr
13438 ret;
13439 ENDPROC(__cast5_enc_blk16)
13440
13441@@ -352,6 +354,7 @@ __cast5_dec_blk16:
13442 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13443 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13444
13445+ pax_force_retaddr
13446 ret;
13447
13448 .L__skip_dec:
13449@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13450 vmovdqu RR4, (6*4*4)(%r11);
13451 vmovdqu RL4, (7*4*4)(%r11);
13452
13453+ pax_force_retaddr
13454 ret;
13455 ENDPROC(cast5_ecb_enc_16way)
13456
13457@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13458 vmovdqu RR4, (6*4*4)(%r11);
13459 vmovdqu RL4, (7*4*4)(%r11);
13460
13461+ pax_force_retaddr
13462 ret;
13463 ENDPROC(cast5_ecb_dec_16way)
13464
13465@@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13466 * %rdx: src
13467 */
13468
13469- pushq %r12;
13470+ pushq %r14;
13471
13472 movq %rsi, %r11;
13473- movq %rdx, %r12;
13474+ movq %rdx, %r14;
13475
13476 vmovdqu (0*16)(%rdx), RL1;
13477 vmovdqu (1*16)(%rdx), RR1;
13478@@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13479 call __cast5_dec_blk16;
13480
13481 /* xor with src */
13482- vmovq (%r12), RX;
13483+ vmovq (%r14), RX;
13484 vpshufd $0x4f, RX, RX;
13485 vpxor RX, RR1, RR1;
13486- vpxor 0*16+8(%r12), RL1, RL1;
13487- vpxor 1*16+8(%r12), RR2, RR2;
13488- vpxor 2*16+8(%r12), RL2, RL2;
13489- vpxor 3*16+8(%r12), RR3, RR3;
13490- vpxor 4*16+8(%r12), RL3, RL3;
13491- vpxor 5*16+8(%r12), RR4, RR4;
13492- vpxor 6*16+8(%r12), RL4, RL4;
13493+ vpxor 0*16+8(%r14), RL1, RL1;
13494+ vpxor 1*16+8(%r14), RR2, RR2;
13495+ vpxor 2*16+8(%r14), RL2, RL2;
13496+ vpxor 3*16+8(%r14), RR3, RR3;
13497+ vpxor 4*16+8(%r14), RL3, RL3;
13498+ vpxor 5*16+8(%r14), RR4, RR4;
13499+ vpxor 6*16+8(%r14), RL4, RL4;
13500
13501 vmovdqu RR1, (0*16)(%r11);
13502 vmovdqu RL1, (1*16)(%r11);
13503@@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13504 vmovdqu RR4, (6*16)(%r11);
13505 vmovdqu RL4, (7*16)(%r11);
13506
13507- popq %r12;
13508+ popq %r14;
13509
13510+ pax_force_retaddr
13511 ret;
13512 ENDPROC(cast5_cbc_dec_16way)
13513
13514@@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13515 * %rcx: iv (big endian, 64bit)
13516 */
13517
13518- pushq %r12;
13519+ pushq %r14;
13520
13521 movq %rsi, %r11;
13522- movq %rdx, %r12;
13523+ movq %rdx, %r14;
13524
13525 vpcmpeqd RTMP, RTMP, RTMP;
13526 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13527@@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13528 call __cast5_enc_blk16;
13529
13530 /* dst = src ^ iv */
13531- vpxor (0*16)(%r12), RR1, RR1;
13532- vpxor (1*16)(%r12), RL1, RL1;
13533- vpxor (2*16)(%r12), RR2, RR2;
13534- vpxor (3*16)(%r12), RL2, RL2;
13535- vpxor (4*16)(%r12), RR3, RR3;
13536- vpxor (5*16)(%r12), RL3, RL3;
13537- vpxor (6*16)(%r12), RR4, RR4;
13538- vpxor (7*16)(%r12), RL4, RL4;
13539+ vpxor (0*16)(%r14), RR1, RR1;
13540+ vpxor (1*16)(%r14), RL1, RL1;
13541+ vpxor (2*16)(%r14), RR2, RR2;
13542+ vpxor (3*16)(%r14), RL2, RL2;
13543+ vpxor (4*16)(%r14), RR3, RR3;
13544+ vpxor (5*16)(%r14), RL3, RL3;
13545+ vpxor (6*16)(%r14), RR4, RR4;
13546+ vpxor (7*16)(%r14), RL4, RL4;
13547 vmovdqu RR1, (0*16)(%r11);
13548 vmovdqu RL1, (1*16)(%r11);
13549 vmovdqu RR2, (2*16)(%r11);
13550@@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13551 vmovdqu RR4, (6*16)(%r11);
13552 vmovdqu RL4, (7*16)(%r11);
13553
13554- popq %r12;
13555+ popq %r14;
13556
13557+ pax_force_retaddr
13558 ret;
13559 ENDPROC(cast5_ctr_16way)
13560diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13561index e3531f8..e123f35 100644
13562--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13563+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13564@@ -24,6 +24,7 @@
13565 */
13566
13567 #include <linux/linkage.h>
13568+#include <asm/alternative-asm.h>
13569 #include "glue_helper-asm-avx.S"
13570
13571 .file "cast6-avx-x86_64-asm_64.S"
13572@@ -295,6 +296,7 @@ __cast6_enc_blk8:
13573 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13574 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13575
13576+ pax_force_retaddr
13577 ret;
13578 ENDPROC(__cast6_enc_blk8)
13579
13580@@ -340,6 +342,7 @@ __cast6_dec_blk8:
13581 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13582 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13583
13584+ pax_force_retaddr
13585 ret;
13586 ENDPROC(__cast6_dec_blk8)
13587
13588@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13589
13590 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13591
13592+ pax_force_retaddr
13593 ret;
13594 ENDPROC(cast6_ecb_enc_8way)
13595
13596@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13597
13598 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13599
13600+ pax_force_retaddr
13601 ret;
13602 ENDPROC(cast6_ecb_dec_8way)
13603
13604@@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13605 * %rdx: src
13606 */
13607
13608- pushq %r12;
13609+ pushq %r14;
13610
13611 movq %rsi, %r11;
13612- movq %rdx, %r12;
13613+ movq %rdx, %r14;
13614
13615 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13616
13617 call __cast6_dec_blk8;
13618
13619- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13620+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13621
13622- popq %r12;
13623+ popq %r14;
13624
13625+ pax_force_retaddr
13626 ret;
13627 ENDPROC(cast6_cbc_dec_8way)
13628
13629@@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13630 * %rcx: iv (little endian, 128bit)
13631 */
13632
13633- pushq %r12;
13634+ pushq %r14;
13635
13636 movq %rsi, %r11;
13637- movq %rdx, %r12;
13638+ movq %rdx, %r14;
13639
13640 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13641 RD2, RX, RKR, RKM);
13642
13643 call __cast6_enc_blk8;
13644
13645- store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13646+ store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13647
13648- popq %r12;
13649+ popq %r14;
13650
13651+ pax_force_retaddr
13652 ret;
13653 ENDPROC(cast6_ctr_8way)
13654
13655@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13656 /* dst <= regs xor IVs(in dst) */
13657 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13658
13659+ pax_force_retaddr
13660 ret;
13661 ENDPROC(cast6_xts_enc_8way)
13662
13663@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13664 /* dst <= regs xor IVs(in dst) */
13665 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13666
13667+ pax_force_retaddr
13668 ret;
13669 ENDPROC(cast6_xts_dec_8way)
13670diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13671index dbc4339..de6e120 100644
13672--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13673+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13674@@ -45,6 +45,7 @@
13675
13676 #include <asm/inst.h>
13677 #include <linux/linkage.h>
13678+#include <asm/alternative-asm.h>
13679
13680 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13681
13682@@ -312,6 +313,7 @@ do_return:
13683 popq %rsi
13684 popq %rdi
13685 popq %rbx
13686+ pax_force_retaddr
13687 ret
13688
13689 ################################################################
13690diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13691index 586f41a..d02851e 100644
13692--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13693+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13694@@ -18,6 +18,7 @@
13695
13696 #include <linux/linkage.h>
13697 #include <asm/inst.h>
13698+#include <asm/alternative-asm.h>
13699
13700 .data
13701
13702@@ -93,6 +94,7 @@ __clmul_gf128mul_ble:
13703 psrlq $1, T2
13704 pxor T2, T1
13705 pxor T1, DATA
13706+ pax_force_retaddr
13707 ret
13708 ENDPROC(__clmul_gf128mul_ble)
13709
13710@@ -105,6 +107,7 @@ ENTRY(clmul_ghash_mul)
13711 call __clmul_gf128mul_ble
13712 PSHUFB_XMM BSWAP DATA
13713 movups DATA, (%rdi)
13714+ pax_force_retaddr
13715 ret
13716 ENDPROC(clmul_ghash_mul)
13717
13718@@ -132,6 +135,7 @@ ENTRY(clmul_ghash_update)
13719 PSHUFB_XMM BSWAP DATA
13720 movups DATA, (%rdi)
13721 .Lupdate_just_ret:
13722+ pax_force_retaddr
13723 ret
13724 ENDPROC(clmul_ghash_update)
13725
13726@@ -157,5 +161,6 @@ ENTRY(clmul_ghash_setkey)
13727 pand .Lpoly, %xmm1
13728 pxor %xmm1, %xmm0
13729 movups %xmm0, (%rdi)
13730+ pax_force_retaddr
13731 ret
13732 ENDPROC(clmul_ghash_setkey)
13733diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13734index 9279e0b..c4b3d2c 100644
13735--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13736+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13737@@ -1,4 +1,5 @@
13738 #include <linux/linkage.h>
13739+#include <asm/alternative-asm.h>
13740
13741 # enter salsa20_encrypt_bytes
13742 ENTRY(salsa20_encrypt_bytes)
13743@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13744 add %r11,%rsp
13745 mov %rdi,%rax
13746 mov %rsi,%rdx
13747+ pax_force_retaddr
13748 ret
13749 # bytesatleast65:
13750 ._bytesatleast65:
13751@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13752 add %r11,%rsp
13753 mov %rdi,%rax
13754 mov %rsi,%rdx
13755+ pax_force_retaddr
13756 ret
13757 ENDPROC(salsa20_keysetup)
13758
13759@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13760 add %r11,%rsp
13761 mov %rdi,%rax
13762 mov %rsi,%rdx
13763+ pax_force_retaddr
13764 ret
13765 ENDPROC(salsa20_ivsetup)
13766diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13767index 2f202f4..d9164d6 100644
13768--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13769+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13770@@ -24,6 +24,7 @@
13771 */
13772
13773 #include <linux/linkage.h>
13774+#include <asm/alternative-asm.h>
13775 #include "glue_helper-asm-avx.S"
13776
13777 .file "serpent-avx-x86_64-asm_64.S"
13778@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13779 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13780 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13781
13782+ pax_force_retaddr
13783 ret;
13784 ENDPROC(__serpent_enc_blk8_avx)
13785
13786@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13787 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13788 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13789
13790+ pax_force_retaddr
13791 ret;
13792 ENDPROC(__serpent_dec_blk8_avx)
13793
13794@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13795
13796 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13797
13798+ pax_force_retaddr
13799 ret;
13800 ENDPROC(serpent_ecb_enc_8way_avx)
13801
13802@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13803
13804 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13805
13806+ pax_force_retaddr
13807 ret;
13808 ENDPROC(serpent_ecb_dec_8way_avx)
13809
13810@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13811
13812 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13813
13814+ pax_force_retaddr
13815 ret;
13816 ENDPROC(serpent_cbc_dec_8way_avx)
13817
13818@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13819
13820 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13821
13822+ pax_force_retaddr
13823 ret;
13824 ENDPROC(serpent_ctr_8way_avx)
13825
13826@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13827 /* dst <= regs xor IVs(in dst) */
13828 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13829
13830+ pax_force_retaddr
13831 ret;
13832 ENDPROC(serpent_xts_enc_8way_avx)
13833
13834@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13835 /* dst <= regs xor IVs(in dst) */
13836 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13837
13838+ pax_force_retaddr
13839 ret;
13840 ENDPROC(serpent_xts_dec_8way_avx)
13841diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13842index b222085..abd483c 100644
13843--- a/arch/x86/crypto/serpent-avx2-asm_64.S
13844+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13845@@ -15,6 +15,7 @@
13846 */
13847
13848 #include <linux/linkage.h>
13849+#include <asm/alternative-asm.h>
13850 #include "glue_helper-asm-avx2.S"
13851
13852 .file "serpent-avx2-asm_64.S"
13853@@ -610,6 +611,7 @@ __serpent_enc_blk16:
13854 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13855 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13856
13857+ pax_force_retaddr
13858 ret;
13859 ENDPROC(__serpent_enc_blk16)
13860
13861@@ -664,6 +666,7 @@ __serpent_dec_blk16:
13862 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13863 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13864
13865+ pax_force_retaddr
13866 ret;
13867 ENDPROC(__serpent_dec_blk16)
13868
13869@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13870
13871 vzeroupper;
13872
13873+ pax_force_retaddr
13874 ret;
13875 ENDPROC(serpent_ecb_enc_16way)
13876
13877@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13878
13879 vzeroupper;
13880
13881+ pax_force_retaddr
13882 ret;
13883 ENDPROC(serpent_ecb_dec_16way)
13884
13885@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13886
13887 vzeroupper;
13888
13889+ pax_force_retaddr
13890 ret;
13891 ENDPROC(serpent_cbc_dec_16way)
13892
13893@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13894
13895 vzeroupper;
13896
13897+ pax_force_retaddr
13898 ret;
13899 ENDPROC(serpent_ctr_16way)
13900
13901@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13902
13903 vzeroupper;
13904
13905+ pax_force_retaddr
13906 ret;
13907 ENDPROC(serpent_xts_enc_16way)
13908
13909@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13910
13911 vzeroupper;
13912
13913+ pax_force_retaddr
13914 ret;
13915 ENDPROC(serpent_xts_dec_16way)
13916diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13917index acc066c..1559cc4 100644
13918--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13919+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13920@@ -25,6 +25,7 @@
13921 */
13922
13923 #include <linux/linkage.h>
13924+#include <asm/alternative-asm.h>
13925
13926 .file "serpent-sse2-x86_64-asm_64.S"
13927 .text
13928@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13929 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13930 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13931
13932+ pax_force_retaddr
13933 ret;
13934
13935 .L__enc_xor8:
13936 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13937 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13938
13939+ pax_force_retaddr
13940 ret;
13941 ENDPROC(__serpent_enc_blk_8way)
13942
13943@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13944 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13945 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13946
13947+ pax_force_retaddr
13948 ret;
13949 ENDPROC(serpent_dec_blk_8way)
13950diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
13951index a410950..9dfe7ad 100644
13952--- a/arch/x86/crypto/sha1_ssse3_asm.S
13953+++ b/arch/x86/crypto/sha1_ssse3_asm.S
13954@@ -29,6 +29,7 @@
13955 */
13956
13957 #include <linux/linkage.h>
13958+#include <asm/alternative-asm.h>
13959
13960 #define CTX %rdi // arg1
13961 #define BUF %rsi // arg2
13962@@ -75,9 +76,9 @@
13963
13964 push %rbx
13965 push %rbp
13966- push %r12
13967+ push %r14
13968
13969- mov %rsp, %r12
13970+ mov %rsp, %r14
13971 sub $64, %rsp # allocate workspace
13972 and $~15, %rsp # align stack
13973
13974@@ -99,11 +100,12 @@
13975 xor %rax, %rax
13976 rep stosq
13977
13978- mov %r12, %rsp # deallocate workspace
13979+ mov %r14, %rsp # deallocate workspace
13980
13981- pop %r12
13982+ pop %r14
13983 pop %rbp
13984 pop %rbx
13985+ pax_force_retaddr
13986 ret
13987
13988 ENDPROC(\name)
13989diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
13990index 642f156..51a513c 100644
13991--- a/arch/x86/crypto/sha256-avx-asm.S
13992+++ b/arch/x86/crypto/sha256-avx-asm.S
13993@@ -49,6 +49,7 @@
13994
13995 #ifdef CONFIG_AS_AVX
13996 #include <linux/linkage.h>
13997+#include <asm/alternative-asm.h>
13998
13999 ## assume buffers not aligned
14000 #define VMOVDQ vmovdqu
14001@@ -460,6 +461,7 @@ done_hash:
14002 popq %r13
14003 popq %rbp
14004 popq %rbx
14005+ pax_force_retaddr
14006 ret
14007 ENDPROC(sha256_transform_avx)
14008
14009diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14010index 9e86944..3795e6a 100644
14011--- a/arch/x86/crypto/sha256-avx2-asm.S
14012+++ b/arch/x86/crypto/sha256-avx2-asm.S
14013@@ -50,6 +50,7 @@
14014
14015 #ifdef CONFIG_AS_AVX2
14016 #include <linux/linkage.h>
14017+#include <asm/alternative-asm.h>
14018
14019 ## assume buffers not aligned
14020 #define VMOVDQ vmovdqu
14021@@ -720,6 +721,7 @@ done_hash:
14022 popq %r12
14023 popq %rbp
14024 popq %rbx
14025+ pax_force_retaddr
14026 ret
14027 ENDPROC(sha256_transform_rorx)
14028
14029diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14030index f833b74..8c62a9e 100644
14031--- a/arch/x86/crypto/sha256-ssse3-asm.S
14032+++ b/arch/x86/crypto/sha256-ssse3-asm.S
14033@@ -47,6 +47,7 @@
14034 ########################################################################
14035
14036 #include <linux/linkage.h>
14037+#include <asm/alternative-asm.h>
14038
14039 ## assume buffers not aligned
14040 #define MOVDQ movdqu
14041@@ -471,6 +472,7 @@ done_hash:
14042 popq %rbp
14043 popq %rbx
14044
14045+ pax_force_retaddr
14046 ret
14047 ENDPROC(sha256_transform_ssse3)
14048
14049diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14050index 974dde9..a823ff9 100644
14051--- a/arch/x86/crypto/sha512-avx-asm.S
14052+++ b/arch/x86/crypto/sha512-avx-asm.S
14053@@ -49,6 +49,7 @@
14054
14055 #ifdef CONFIG_AS_AVX
14056 #include <linux/linkage.h>
14057+#include <asm/alternative-asm.h>
14058
14059 .text
14060
14061@@ -364,6 +365,7 @@ updateblock:
14062 mov frame_RSPSAVE(%rsp), %rsp
14063
14064 nowork:
14065+ pax_force_retaddr
14066 ret
14067 ENDPROC(sha512_transform_avx)
14068
14069diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14070index 568b961..ed20c37 100644
14071--- a/arch/x86/crypto/sha512-avx2-asm.S
14072+++ b/arch/x86/crypto/sha512-avx2-asm.S
14073@@ -51,6 +51,7 @@
14074
14075 #ifdef CONFIG_AS_AVX2
14076 #include <linux/linkage.h>
14077+#include <asm/alternative-asm.h>
14078
14079 .text
14080
14081@@ -678,6 +679,7 @@ done_hash:
14082
14083 # Restore Stack Pointer
14084 mov frame_RSPSAVE(%rsp), %rsp
14085+ pax_force_retaddr
14086 ret
14087 ENDPROC(sha512_transform_rorx)
14088
14089diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14090index fb56855..6edd768 100644
14091--- a/arch/x86/crypto/sha512-ssse3-asm.S
14092+++ b/arch/x86/crypto/sha512-ssse3-asm.S
14093@@ -48,6 +48,7 @@
14094 ########################################################################
14095
14096 #include <linux/linkage.h>
14097+#include <asm/alternative-asm.h>
14098
14099 .text
14100
14101@@ -363,6 +364,7 @@ updateblock:
14102 mov frame_RSPSAVE(%rsp), %rsp
14103
14104 nowork:
14105+ pax_force_retaddr
14106 ret
14107 ENDPROC(sha512_transform_ssse3)
14108
14109diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14110index 0505813..b067311 100644
14111--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14112+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14113@@ -24,6 +24,7 @@
14114 */
14115
14116 #include <linux/linkage.h>
14117+#include <asm/alternative-asm.h>
14118 #include "glue_helper-asm-avx.S"
14119
14120 .file "twofish-avx-x86_64-asm_64.S"
14121@@ -284,6 +285,7 @@ __twofish_enc_blk8:
14122 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14123 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14124
14125+ pax_force_retaddr
14126 ret;
14127 ENDPROC(__twofish_enc_blk8)
14128
14129@@ -324,6 +326,7 @@ __twofish_dec_blk8:
14130 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14131 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14132
14133+ pax_force_retaddr
14134 ret;
14135 ENDPROC(__twofish_dec_blk8)
14136
14137@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14138
14139 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14140
14141+ pax_force_retaddr
14142 ret;
14143 ENDPROC(twofish_ecb_enc_8way)
14144
14145@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14146
14147 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14148
14149+ pax_force_retaddr
14150 ret;
14151 ENDPROC(twofish_ecb_dec_8way)
14152
14153@@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14154 * %rdx: src
14155 */
14156
14157- pushq %r12;
14158+ pushq %r14;
14159
14160 movq %rsi, %r11;
14161- movq %rdx, %r12;
14162+ movq %rdx, %r14;
14163
14164 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14165
14166 call __twofish_dec_blk8;
14167
14168- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14169+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14170
14171- popq %r12;
14172+ popq %r14;
14173
14174+ pax_force_retaddr
14175 ret;
14176 ENDPROC(twofish_cbc_dec_8way)
14177
14178@@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14179 * %rcx: iv (little endian, 128bit)
14180 */
14181
14182- pushq %r12;
14183+ pushq %r14;
14184
14185 movq %rsi, %r11;
14186- movq %rdx, %r12;
14187+ movq %rdx, %r14;
14188
14189 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14190 RD2, RX0, RX1, RY0);
14191
14192 call __twofish_enc_blk8;
14193
14194- store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14195+ store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14196
14197- popq %r12;
14198+ popq %r14;
14199
14200+ pax_force_retaddr
14201 ret;
14202 ENDPROC(twofish_ctr_8way)
14203
14204@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14205 /* dst <= regs xor IVs(in dst) */
14206 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14207
14208+ pax_force_retaddr
14209 ret;
14210 ENDPROC(twofish_xts_enc_8way)
14211
14212@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14213 /* dst <= regs xor IVs(in dst) */
14214 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14215
14216+ pax_force_retaddr
14217 ret;
14218 ENDPROC(twofish_xts_dec_8way)
14219diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14220index 1c3b7ce..02f578d 100644
14221--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14222+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14223@@ -21,6 +21,7 @@
14224 */
14225
14226 #include <linux/linkage.h>
14227+#include <asm/alternative-asm.h>
14228
14229 .file "twofish-x86_64-asm-3way.S"
14230 .text
14231@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14232 popq %r13;
14233 popq %r14;
14234 popq %r15;
14235+ pax_force_retaddr
14236 ret;
14237
14238 .L__enc_xor3:
14239@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14240 popq %r13;
14241 popq %r14;
14242 popq %r15;
14243+ pax_force_retaddr
14244 ret;
14245 ENDPROC(__twofish_enc_blk_3way)
14246
14247@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14248 popq %r13;
14249 popq %r14;
14250 popq %r15;
14251+ pax_force_retaddr
14252 ret;
14253 ENDPROC(twofish_dec_blk_3way)
14254diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14255index a039d21..524b8b2 100644
14256--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14257+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14258@@ -22,6 +22,7 @@
14259
14260 #include <linux/linkage.h>
14261 #include <asm/asm-offsets.h>
14262+#include <asm/alternative-asm.h>
14263
14264 #define a_offset 0
14265 #define b_offset 4
14266@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14267
14268 popq R1
14269 movq $1,%rax
14270+ pax_force_retaddr
14271 ret
14272 ENDPROC(twofish_enc_blk)
14273
14274@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14275
14276 popq R1
14277 movq $1,%rax
14278+ pax_force_retaddr
14279 ret
14280 ENDPROC(twofish_dec_blk)
14281diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14282index d21ff89..6da8e6e 100644
14283--- a/arch/x86/ia32/ia32_aout.c
14284+++ b/arch/x86/ia32/ia32_aout.c
14285@@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14286 unsigned long dump_start, dump_size;
14287 struct user32 dump;
14288
14289+ memset(&dump, 0, sizeof(dump));
14290+
14291 fs = get_fs();
14292 set_fs(KERNEL_DS);
14293 has_dumped = 1;
14294diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14295index 2206757..85cbcfa 100644
14296--- a/arch/x86/ia32/ia32_signal.c
14297+++ b/arch/x86/ia32/ia32_signal.c
14298@@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14299 if (__get_user(set.sig[0], &frame->sc.oldmask)
14300 || (_COMPAT_NSIG_WORDS > 1
14301 && __copy_from_user((((char *) &set.sig) + 4),
14302- &frame->extramask,
14303+ frame->extramask,
14304 sizeof(frame->extramask))))
14305 goto badframe;
14306
14307@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14308 sp -= frame_size;
14309 /* Align the stack pointer according to the i386 ABI,
14310 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14311- sp = ((sp + 4) & -16ul) - 4;
14312+ sp = ((sp - 12) & -16ul) - 4;
14313 return (void __user *) sp;
14314 }
14315
14316@@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14317 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14318 sigreturn);
14319 else
14320- restorer = &frame->retcode;
14321+ restorer = frame->retcode;
14322 }
14323
14324 put_user_try {
14325@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14326 * These are actually not used anymore, but left because some
14327 * gdb versions depend on them as a marker.
14328 */
14329- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14330+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14331 } put_user_catch(err);
14332
14333 if (err)
14334@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14335 0xb8,
14336 __NR_ia32_rt_sigreturn,
14337 0x80cd,
14338- 0,
14339+ 0
14340 };
14341
14342 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14343@@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14344
14345 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14346 restorer = ksig->ka.sa.sa_restorer;
14347+ else if (current->mm->context.vdso)
14348+ /* Return stub is in 32bit vsyscall page */
14349+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14350 else
14351- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14352- rt_sigreturn);
14353+ restorer = frame->retcode;
14354 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14355
14356 /*
14357 * Not actually used anymore, but left because some gdb
14358 * versions need it.
14359 */
14360- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14361+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14362 } put_user_catch(err);
14363
14364 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14365diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14366index 4299eb0..c0687a7 100644
14367--- a/arch/x86/ia32/ia32entry.S
14368+++ b/arch/x86/ia32/ia32entry.S
14369@@ -15,8 +15,10 @@
14370 #include <asm/irqflags.h>
14371 #include <asm/asm.h>
14372 #include <asm/smap.h>
14373+#include <asm/pgtable.h>
14374 #include <linux/linkage.h>
14375 #include <linux/err.h>
14376+#include <asm/alternative-asm.h>
14377
14378 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14379 #include <linux/elf-em.h>
14380@@ -62,12 +64,12 @@
14381 */
14382 .macro LOAD_ARGS32 offset, _r9=0
14383 .if \_r9
14384- movl \offset+16(%rsp),%r9d
14385+ movl \offset+R9(%rsp),%r9d
14386 .endif
14387- movl \offset+40(%rsp),%ecx
14388- movl \offset+48(%rsp),%edx
14389- movl \offset+56(%rsp),%esi
14390- movl \offset+64(%rsp),%edi
14391+ movl \offset+RCX(%rsp),%ecx
14392+ movl \offset+RDX(%rsp),%edx
14393+ movl \offset+RSI(%rsp),%esi
14394+ movl \offset+RDI(%rsp),%edi
14395 movl %eax,%eax /* zero extension */
14396 .endm
14397
14398@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14399 ENDPROC(native_irq_enable_sysexit)
14400 #endif
14401
14402+ .macro pax_enter_kernel_user
14403+ pax_set_fptr_mask
14404+#ifdef CONFIG_PAX_MEMORY_UDEREF
14405+ call pax_enter_kernel_user
14406+#endif
14407+ .endm
14408+
14409+ .macro pax_exit_kernel_user
14410+#ifdef CONFIG_PAX_MEMORY_UDEREF
14411+ call pax_exit_kernel_user
14412+#endif
14413+#ifdef CONFIG_PAX_RANDKSTACK
14414+ pushq %rax
14415+ pushq %r11
14416+ call pax_randomize_kstack
14417+ popq %r11
14418+ popq %rax
14419+#endif
14420+ .endm
14421+
14422+ .macro pax_erase_kstack
14423+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14424+ call pax_erase_kstack
14425+#endif
14426+ .endm
14427+
14428 /*
14429 * 32bit SYSENTER instruction entry.
14430 *
14431@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14432 CFI_REGISTER rsp,rbp
14433 SWAPGS_UNSAFE_STACK
14434 movq PER_CPU_VAR(kernel_stack), %rsp
14435- addq $(KERNEL_STACK_OFFSET),%rsp
14436- /*
14437- * No need to follow this irqs on/off section: the syscall
14438- * disabled irqs, here we enable it straight after entry:
14439- */
14440- ENABLE_INTERRUPTS(CLBR_NONE)
14441 movl %ebp,%ebp /* zero extension */
14442 pushq_cfi $__USER32_DS
14443 /*CFI_REL_OFFSET ss,0*/
14444@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14445 CFI_REL_OFFSET rsp,0
14446 pushfq_cfi
14447 /*CFI_REL_OFFSET rflags,0*/
14448- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14449- CFI_REGISTER rip,r10
14450+ orl $X86_EFLAGS_IF,(%rsp)
14451+ GET_THREAD_INFO(%r11)
14452+ movl TI_sysenter_return(%r11), %r11d
14453+ CFI_REGISTER rip,r11
14454 pushq_cfi $__USER32_CS
14455 /*CFI_REL_OFFSET cs,0*/
14456 movl %eax, %eax
14457- pushq_cfi %r10
14458+ pushq_cfi %r11
14459 CFI_REL_OFFSET rip,0
14460 pushq_cfi %rax
14461 cld
14462 SAVE_ARGS 0,1,0
14463+ pax_enter_kernel_user
14464+
14465+#ifdef CONFIG_PAX_RANDKSTACK
14466+ pax_erase_kstack
14467+#endif
14468+
14469+ /*
14470+ * No need to follow this irqs on/off section: the syscall
14471+ * disabled irqs, here we enable it straight after entry:
14472+ */
14473+ ENABLE_INTERRUPTS(CLBR_NONE)
14474 /* no need to do an access_ok check here because rbp has been
14475 32bit zero extended */
14476+
14477+#ifdef CONFIG_PAX_MEMORY_UDEREF
14478+ addq pax_user_shadow_base,%rbp
14479+ ASM_PAX_OPEN_USERLAND
14480+#endif
14481+
14482 ASM_STAC
14483 1: movl (%rbp),%ebp
14484 _ASM_EXTABLE(1b,ia32_badarg)
14485 ASM_CLAC
14486- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14487- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14488+
14489+#ifdef CONFIG_PAX_MEMORY_UDEREF
14490+ ASM_PAX_CLOSE_USERLAND
14491+#endif
14492+
14493+ GET_THREAD_INFO(%r11)
14494+ orl $TS_COMPAT,TI_status(%r11)
14495+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14496 CFI_REMEMBER_STATE
14497 jnz sysenter_tracesys
14498 cmpq $(IA32_NR_syscalls-1),%rax
14499@@ -162,15 +209,18 @@ sysenter_do_call:
14500 sysenter_dispatch:
14501 call *ia32_sys_call_table(,%rax,8)
14502 movq %rax,RAX-ARGOFFSET(%rsp)
14503+ GET_THREAD_INFO(%r11)
14504 DISABLE_INTERRUPTS(CLBR_NONE)
14505 TRACE_IRQS_OFF
14506- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14507+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14508 jnz sysexit_audit
14509 sysexit_from_sys_call:
14510- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14511+ pax_exit_kernel_user
14512+ pax_erase_kstack
14513+ andl $~TS_COMPAT,TI_status(%r11)
14514 /* clear IF, that popfq doesn't enable interrupts early */
14515- andl $~0x200,EFLAGS-R11(%rsp)
14516- movl RIP-R11(%rsp),%edx /* User %eip */
14517+ andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14518+ movl RIP(%rsp),%edx /* User %eip */
14519 CFI_REGISTER rip,rdx
14520 RESTORE_ARGS 0,24,0,0,0,0
14521 xorq %r8,%r8
14522@@ -193,6 +243,9 @@ sysexit_from_sys_call:
14523 movl %eax,%esi /* 2nd arg: syscall number */
14524 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14525 call __audit_syscall_entry
14526+
14527+ pax_erase_kstack
14528+
14529 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14530 cmpq $(IA32_NR_syscalls-1),%rax
14531 ja ia32_badsys
14532@@ -204,7 +257,7 @@ sysexit_from_sys_call:
14533 .endm
14534
14535 .macro auditsys_exit exit
14536- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14537+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14538 jnz ia32_ret_from_sys_call
14539 TRACE_IRQS_ON
14540 ENABLE_INTERRUPTS(CLBR_NONE)
14541@@ -215,11 +268,12 @@ sysexit_from_sys_call:
14542 1: setbe %al /* 1 if error, 0 if not */
14543 movzbl %al,%edi /* zero-extend that into %edi */
14544 call __audit_syscall_exit
14545+ GET_THREAD_INFO(%r11)
14546 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14547 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14548 DISABLE_INTERRUPTS(CLBR_NONE)
14549 TRACE_IRQS_OFF
14550- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14551+ testl %edi,TI_flags(%r11)
14552 jz \exit
14553 CLEAR_RREGS -ARGOFFSET
14554 jmp int_with_check
14555@@ -237,7 +291,7 @@ sysexit_audit:
14556
14557 sysenter_tracesys:
14558 #ifdef CONFIG_AUDITSYSCALL
14559- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14560+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14561 jz sysenter_auditsys
14562 #endif
14563 SAVE_REST
14564@@ -249,6 +303,9 @@ sysenter_tracesys:
14565 RESTORE_REST
14566 cmpq $(IA32_NR_syscalls-1),%rax
14567 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14568+
14569+ pax_erase_kstack
14570+
14571 jmp sysenter_do_call
14572 CFI_ENDPROC
14573 ENDPROC(ia32_sysenter_target)
14574@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14575 ENTRY(ia32_cstar_target)
14576 CFI_STARTPROC32 simple
14577 CFI_SIGNAL_FRAME
14578- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14579+ CFI_DEF_CFA rsp,0
14580 CFI_REGISTER rip,rcx
14581 /*CFI_REGISTER rflags,r11*/
14582 SWAPGS_UNSAFE_STACK
14583 movl %esp,%r8d
14584 CFI_REGISTER rsp,r8
14585 movq PER_CPU_VAR(kernel_stack),%rsp
14586+ SAVE_ARGS 8*6,0,0
14587+ pax_enter_kernel_user
14588+
14589+#ifdef CONFIG_PAX_RANDKSTACK
14590+ pax_erase_kstack
14591+#endif
14592+
14593 /*
14594 * No need to follow this irqs on/off section: the syscall
14595 * disabled irqs and here we enable it straight after entry:
14596 */
14597 ENABLE_INTERRUPTS(CLBR_NONE)
14598- SAVE_ARGS 8,0,0
14599 movl %eax,%eax /* zero extension */
14600 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14601 movq %rcx,RIP-ARGOFFSET(%rsp)
14602@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14603 /* no need to do an access_ok check here because r8 has been
14604 32bit zero extended */
14605 /* hardware stack frame is complete now */
14606+
14607+#ifdef CONFIG_PAX_MEMORY_UDEREF
14608+ ASM_PAX_OPEN_USERLAND
14609+ movq pax_user_shadow_base,%r8
14610+ addq RSP-ARGOFFSET(%rsp),%r8
14611+#endif
14612+
14613 ASM_STAC
14614 1: movl (%r8),%r9d
14615 _ASM_EXTABLE(1b,ia32_badarg)
14616 ASM_CLAC
14617- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14618- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14619+
14620+#ifdef CONFIG_PAX_MEMORY_UDEREF
14621+ ASM_PAX_CLOSE_USERLAND
14622+#endif
14623+
14624+ GET_THREAD_INFO(%r11)
14625+ orl $TS_COMPAT,TI_status(%r11)
14626+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14627 CFI_REMEMBER_STATE
14628 jnz cstar_tracesys
14629 cmpq $IA32_NR_syscalls-1,%rax
14630@@ -319,13 +395,16 @@ cstar_do_call:
14631 cstar_dispatch:
14632 call *ia32_sys_call_table(,%rax,8)
14633 movq %rax,RAX-ARGOFFSET(%rsp)
14634+ GET_THREAD_INFO(%r11)
14635 DISABLE_INTERRUPTS(CLBR_NONE)
14636 TRACE_IRQS_OFF
14637- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14638+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14639 jnz sysretl_audit
14640 sysretl_from_sys_call:
14641- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14642- RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14643+ pax_exit_kernel_user
14644+ pax_erase_kstack
14645+ andl $~TS_COMPAT,TI_status(%r11)
14646+ RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14647 movl RIP-ARGOFFSET(%rsp),%ecx
14648 CFI_REGISTER rip,rcx
14649 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14650@@ -352,7 +431,7 @@ sysretl_audit:
14651
14652 cstar_tracesys:
14653 #ifdef CONFIG_AUDITSYSCALL
14654- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14655+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14656 jz cstar_auditsys
14657 #endif
14658 xchgl %r9d,%ebp
14659@@ -366,11 +445,19 @@ cstar_tracesys:
14660 xchgl %ebp,%r9d
14661 cmpq $(IA32_NR_syscalls-1),%rax
14662 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14663+
14664+ pax_erase_kstack
14665+
14666 jmp cstar_do_call
14667 END(ia32_cstar_target)
14668
14669 ia32_badarg:
14670 ASM_CLAC
14671+
14672+#ifdef CONFIG_PAX_MEMORY_UDEREF
14673+ ASM_PAX_CLOSE_USERLAND
14674+#endif
14675+
14676 movq $-EFAULT,%rax
14677 jmp ia32_sysret
14678 CFI_ENDPROC
14679@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14680 CFI_REL_OFFSET rip,RIP-RIP
14681 PARAVIRT_ADJUST_EXCEPTION_FRAME
14682 SWAPGS
14683- /*
14684- * No need to follow this irqs on/off section: the syscall
14685- * disabled irqs and here we enable it straight after entry:
14686- */
14687- ENABLE_INTERRUPTS(CLBR_NONE)
14688 movl %eax,%eax
14689 pushq_cfi %rax
14690 cld
14691 /* note the registers are not zero extended to the sf.
14692 this could be a problem. */
14693 SAVE_ARGS 0,1,0
14694- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14695- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14696+ pax_enter_kernel_user
14697+
14698+#ifdef CONFIG_PAX_RANDKSTACK
14699+ pax_erase_kstack
14700+#endif
14701+
14702+ /*
14703+ * No need to follow this irqs on/off section: the syscall
14704+ * disabled irqs and here we enable it straight after entry:
14705+ */
14706+ ENABLE_INTERRUPTS(CLBR_NONE)
14707+ GET_THREAD_INFO(%r11)
14708+ orl $TS_COMPAT,TI_status(%r11)
14709+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14710 jnz ia32_tracesys
14711 cmpq $(IA32_NR_syscalls-1),%rax
14712 ja ia32_badsys
14713@@ -442,6 +536,9 @@ ia32_tracesys:
14714 RESTORE_REST
14715 cmpq $(IA32_NR_syscalls-1),%rax
14716 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14717+
14718+ pax_erase_kstack
14719+
14720 jmp ia32_do_call
14721 END(ia32_syscall)
14722
14723diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14724index 8e0ceec..af13504 100644
14725--- a/arch/x86/ia32/sys_ia32.c
14726+++ b/arch/x86/ia32/sys_ia32.c
14727@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14728 */
14729 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14730 {
14731- typeof(ubuf->st_uid) uid = 0;
14732- typeof(ubuf->st_gid) gid = 0;
14733+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
14734+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
14735 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14736 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14737 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14738diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14739index 372231c..51b537d 100644
14740--- a/arch/x86/include/asm/alternative-asm.h
14741+++ b/arch/x86/include/asm/alternative-asm.h
14742@@ -18,6 +18,45 @@
14743 .endm
14744 #endif
14745
14746+#ifdef KERNEXEC_PLUGIN
14747+ .macro pax_force_retaddr_bts rip=0
14748+ btsq $63,\rip(%rsp)
14749+ .endm
14750+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14751+ .macro pax_force_retaddr rip=0, reload=0
14752+ btsq $63,\rip(%rsp)
14753+ .endm
14754+ .macro pax_force_fptr ptr
14755+ btsq $63,\ptr
14756+ .endm
14757+ .macro pax_set_fptr_mask
14758+ .endm
14759+#endif
14760+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14761+ .macro pax_force_retaddr rip=0, reload=0
14762+ .if \reload
14763+ pax_set_fptr_mask
14764+ .endif
14765+ orq %r12,\rip(%rsp)
14766+ .endm
14767+ .macro pax_force_fptr ptr
14768+ orq %r12,\ptr
14769+ .endm
14770+ .macro pax_set_fptr_mask
14771+ movabs $0x8000000000000000,%r12
14772+ .endm
14773+#endif
14774+#else
14775+ .macro pax_force_retaddr rip=0, reload=0
14776+ .endm
14777+ .macro pax_force_fptr ptr
14778+ .endm
14779+ .macro pax_force_retaddr_bts rip=0
14780+ .endm
14781+ .macro pax_set_fptr_mask
14782+ .endm
14783+#endif
14784+
14785 .macro altinstruction_entry orig alt feature orig_len alt_len
14786 .long \orig - .
14787 .long \alt - .
14788diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14789index 0a3f9c9..c9d081d 100644
14790--- a/arch/x86/include/asm/alternative.h
14791+++ b/arch/x86/include/asm/alternative.h
14792@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14793 ".pushsection .discard,\"aw\",@progbits\n" \
14794 DISCARD_ENTRY(1) \
14795 ".popsection\n" \
14796- ".pushsection .altinstr_replacement, \"ax\"\n" \
14797+ ".pushsection .altinstr_replacement, \"a\"\n" \
14798 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14799 ".popsection"
14800
14801@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14802 DISCARD_ENTRY(1) \
14803 DISCARD_ENTRY(2) \
14804 ".popsection\n" \
14805- ".pushsection .altinstr_replacement, \"ax\"\n" \
14806+ ".pushsection .altinstr_replacement, \"a\"\n" \
14807 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14808 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14809 ".popsection"
14810diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14811index 1d2091a..f5074c1 100644
14812--- a/arch/x86/include/asm/apic.h
14813+++ b/arch/x86/include/asm/apic.h
14814@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14815
14816 #ifdef CONFIG_X86_LOCAL_APIC
14817
14818-extern unsigned int apic_verbosity;
14819+extern int apic_verbosity;
14820 extern int local_apic_timer_c2_ok;
14821
14822 extern int disable_apic;
14823diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14824index 20370c6..a2eb9b0 100644
14825--- a/arch/x86/include/asm/apm.h
14826+++ b/arch/x86/include/asm/apm.h
14827@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14828 __asm__ __volatile__(APM_DO_ZERO_SEGS
14829 "pushl %%edi\n\t"
14830 "pushl %%ebp\n\t"
14831- "lcall *%%cs:apm_bios_entry\n\t"
14832+ "lcall *%%ss:apm_bios_entry\n\t"
14833 "setc %%al\n\t"
14834 "popl %%ebp\n\t"
14835 "popl %%edi\n\t"
14836@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14837 __asm__ __volatile__(APM_DO_ZERO_SEGS
14838 "pushl %%edi\n\t"
14839 "pushl %%ebp\n\t"
14840- "lcall *%%cs:apm_bios_entry\n\t"
14841+ "lcall *%%ss:apm_bios_entry\n\t"
14842 "setc %%bl\n\t"
14843 "popl %%ebp\n\t"
14844 "popl %%edi\n\t"
14845diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14846index b17f4f4..9620151 100644
14847--- a/arch/x86/include/asm/atomic.h
14848+++ b/arch/x86/include/asm/atomic.h
14849@@ -23,7 +23,18 @@
14850 */
14851 static inline int atomic_read(const atomic_t *v)
14852 {
14853- return (*(volatile int *)&(v)->counter);
14854+ return (*(volatile const int *)&(v)->counter);
14855+}
14856+
14857+/**
14858+ * atomic_read_unchecked - read atomic variable
14859+ * @v: pointer of type atomic_unchecked_t
14860+ *
14861+ * Atomically reads the value of @v.
14862+ */
14863+static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
14864+{
14865+ return (*(volatile const int *)&(v)->counter);
14866 }
14867
14868 /**
14869@@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
14870 }
14871
14872 /**
14873+ * atomic_set_unchecked - set atomic variable
14874+ * @v: pointer of type atomic_unchecked_t
14875+ * @i: required value
14876+ *
14877+ * Atomically sets the value of @v to @i.
14878+ */
14879+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14880+{
14881+ v->counter = i;
14882+}
14883+
14884+/**
14885 * atomic_add - add integer to atomic variable
14886 * @i: integer value to add
14887 * @v: pointer of type atomic_t
14888@@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
14889 */
14890 static inline void atomic_add(int i, atomic_t *v)
14891 {
14892- asm volatile(LOCK_PREFIX "addl %1,%0"
14893+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14894+
14895+#ifdef CONFIG_PAX_REFCOUNT
14896+ "jno 0f\n"
14897+ LOCK_PREFIX "subl %1,%0\n"
14898+ "int $4\n0:\n"
14899+ _ASM_EXTABLE(0b, 0b)
14900+#endif
14901+
14902+ : "+m" (v->counter)
14903+ : "ir" (i));
14904+}
14905+
14906+/**
14907+ * atomic_add_unchecked - add integer to atomic variable
14908+ * @i: integer value to add
14909+ * @v: pointer of type atomic_unchecked_t
14910+ *
14911+ * Atomically adds @i to @v.
14912+ */
14913+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14914+{
14915+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14916 : "+m" (v->counter)
14917 : "ir" (i));
14918 }
14919@@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
14920 */
14921 static inline void atomic_sub(int i, atomic_t *v)
14922 {
14923- asm volatile(LOCK_PREFIX "subl %1,%0"
14924+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14925+
14926+#ifdef CONFIG_PAX_REFCOUNT
14927+ "jno 0f\n"
14928+ LOCK_PREFIX "addl %1,%0\n"
14929+ "int $4\n0:\n"
14930+ _ASM_EXTABLE(0b, 0b)
14931+#endif
14932+
14933+ : "+m" (v->counter)
14934+ : "ir" (i));
14935+}
14936+
14937+/**
14938+ * atomic_sub_unchecked - subtract integer from atomic variable
14939+ * @i: integer value to subtract
14940+ * @v: pointer of type atomic_unchecked_t
14941+ *
14942+ * Atomically subtracts @i from @v.
14943+ */
14944+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
14945+{
14946+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14947 : "+m" (v->counter)
14948 : "ir" (i));
14949 }
14950@@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
14951 */
14952 static inline int atomic_sub_and_test(int i, atomic_t *v)
14953 {
14954- GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
14955+ GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
14956 }
14957
14958 /**
14959@@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
14960 */
14961 static inline void atomic_inc(atomic_t *v)
14962 {
14963- asm volatile(LOCK_PREFIX "incl %0"
14964+ asm volatile(LOCK_PREFIX "incl %0\n"
14965+
14966+#ifdef CONFIG_PAX_REFCOUNT
14967+ "jno 0f\n"
14968+ LOCK_PREFIX "decl %0\n"
14969+ "int $4\n0:\n"
14970+ _ASM_EXTABLE(0b, 0b)
14971+#endif
14972+
14973+ : "+m" (v->counter));
14974+}
14975+
14976+/**
14977+ * atomic_inc_unchecked - increment atomic variable
14978+ * @v: pointer of type atomic_unchecked_t
14979+ *
14980+ * Atomically increments @v by 1.
14981+ */
14982+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
14983+{
14984+ asm volatile(LOCK_PREFIX "incl %0\n"
14985 : "+m" (v->counter));
14986 }
14987
14988@@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
14989 */
14990 static inline void atomic_dec(atomic_t *v)
14991 {
14992- asm volatile(LOCK_PREFIX "decl %0"
14993+ asm volatile(LOCK_PREFIX "decl %0\n"
14994+
14995+#ifdef CONFIG_PAX_REFCOUNT
14996+ "jno 0f\n"
14997+ LOCK_PREFIX "incl %0\n"
14998+ "int $4\n0:\n"
14999+ _ASM_EXTABLE(0b, 0b)
15000+#endif
15001+
15002+ : "+m" (v->counter));
15003+}
15004+
15005+/**
15006+ * atomic_dec_unchecked - decrement atomic variable
15007+ * @v: pointer of type atomic_unchecked_t
15008+ *
15009+ * Atomically decrements @v by 1.
15010+ */
15011+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15012+{
15013+ asm volatile(LOCK_PREFIX "decl %0\n"
15014 : "+m" (v->counter));
15015 }
15016
15017@@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
15018 */
15019 static inline int atomic_dec_and_test(atomic_t *v)
15020 {
15021- GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15022+ GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15023 }
15024
15025 /**
15026@@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15027 */
15028 static inline int atomic_inc_and_test(atomic_t *v)
15029 {
15030- GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15031+ GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15032+}
15033+
15034+/**
15035+ * atomic_inc_and_test_unchecked - increment and test
15036+ * @v: pointer of type atomic_unchecked_t
15037+ *
15038+ * Atomically increments @v by 1
15039+ * and returns true if the result is zero, or false for all
15040+ * other cases.
15041+ */
15042+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15043+{
15044+ GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15045 }
15046
15047 /**
15048@@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15049 */
15050 static inline int atomic_add_negative(int i, atomic_t *v)
15051 {
15052- GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15053+ GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15054 }
15055
15056 /**
15057@@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15058 */
15059 static inline int atomic_add_return(int i, atomic_t *v)
15060 {
15061+ return i + xadd_check_overflow(&v->counter, i);
15062+}
15063+
15064+/**
15065+ * atomic_add_return_unchecked - add integer and return
15066+ * @i: integer value to add
15067+ * @v: pointer of type atomic_unchecked_t
15068+ *
15069+ * Atomically adds @i to @v and returns @i + @v
15070+ */
15071+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15072+{
15073 return i + xadd(&v->counter, i);
15074 }
15075
15076@@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
15077 }
15078
15079 #define atomic_inc_return(v) (atomic_add_return(1, v))
15080+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15081+{
15082+ return atomic_add_return_unchecked(1, v);
15083+}
15084 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15085
15086-static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15087+static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15088+{
15089+ return cmpxchg(&v->counter, old, new);
15090+}
15091+
15092+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15093 {
15094 return cmpxchg(&v->counter, old, new);
15095 }
15096@@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15097 return xchg(&v->counter, new);
15098 }
15099
15100+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15101+{
15102+ return xchg(&v->counter, new);
15103+}
15104+
15105 /**
15106 * __atomic_add_unless - add unless the number is already a given value
15107 * @v: pointer of type atomic_t
15108@@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15109 * Atomically adds @a to @v, so long as @v was not already @u.
15110 * Returns the old value of @v.
15111 */
15112-static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15113+static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15114 {
15115- int c, old;
15116+ int c, old, new;
15117 c = atomic_read(v);
15118 for (;;) {
15119- if (unlikely(c == (u)))
15120+ if (unlikely(c == u))
15121 break;
15122- old = atomic_cmpxchg((v), c, c + (a));
15123+
15124+ asm volatile("addl %2,%0\n"
15125+
15126+#ifdef CONFIG_PAX_REFCOUNT
15127+ "jno 0f\n"
15128+ "subl %2,%0\n"
15129+ "int $4\n0:\n"
15130+ _ASM_EXTABLE(0b, 0b)
15131+#endif
15132+
15133+ : "=r" (new)
15134+ : "0" (c), "ir" (a));
15135+
15136+ old = atomic_cmpxchg(v, c, new);
15137 if (likely(old == c))
15138 break;
15139 c = old;
15140@@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15141 }
15142
15143 /**
15144+ * atomic_inc_not_zero_hint - increment if not null
15145+ * @v: pointer of type atomic_t
15146+ * @hint: probable value of the atomic before the increment
15147+ *
15148+ * This version of atomic_inc_not_zero() gives a hint of probable
15149+ * value of the atomic. This helps processor to not read the memory
15150+ * before doing the atomic read/modify/write cycle, lowering
15151+ * number of bus transactions on some arches.
15152+ *
15153+ * Returns: 0 if increment was not done, 1 otherwise.
15154+ */
15155+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15156+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15157+{
15158+ int val, c = hint, new;
15159+
15160+ /* sanity test, should be removed by compiler if hint is a constant */
15161+ if (!hint)
15162+ return __atomic_add_unless(v, 1, 0);
15163+
15164+ do {
15165+ asm volatile("incl %0\n"
15166+
15167+#ifdef CONFIG_PAX_REFCOUNT
15168+ "jno 0f\n"
15169+ "decl %0\n"
15170+ "int $4\n0:\n"
15171+ _ASM_EXTABLE(0b, 0b)
15172+#endif
15173+
15174+ : "=r" (new)
15175+ : "0" (c));
15176+
15177+ val = atomic_cmpxchg(v, c, new);
15178+ if (val == c)
15179+ return 1;
15180+ c = val;
15181+ } while (c);
15182+
15183+ return 0;
15184+}
15185+
15186+/**
15187 * atomic_inc_short - increment of a short integer
15188 * @v: pointer to type int
15189 *
15190@@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15191 #endif
15192
15193 /* These are x86-specific, used by some header files */
15194-#define atomic_clear_mask(mask, addr) \
15195- asm volatile(LOCK_PREFIX "andl %0,%1" \
15196- : : "r" (~(mask)), "m" (*(addr)) : "memory")
15197+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15198+{
15199+ asm volatile(LOCK_PREFIX "andl %1,%0"
15200+ : "+m" (v->counter)
15201+ : "r" (~(mask))
15202+ : "memory");
15203+}
15204
15205-#define atomic_set_mask(mask, addr) \
15206- asm volatile(LOCK_PREFIX "orl %0,%1" \
15207- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15208- : "memory")
15209+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15210+{
15211+ asm volatile(LOCK_PREFIX "andl %1,%0"
15212+ : "+m" (v->counter)
15213+ : "r" (~(mask))
15214+ : "memory");
15215+}
15216+
15217+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15218+{
15219+ asm volatile(LOCK_PREFIX "orl %1,%0"
15220+ : "+m" (v->counter)
15221+ : "r" (mask)
15222+ : "memory");
15223+}
15224+
15225+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15226+{
15227+ asm volatile(LOCK_PREFIX "orl %1,%0"
15228+ : "+m" (v->counter)
15229+ : "r" (mask)
15230+ : "memory");
15231+}
15232
15233 /* Atomic operations are already serializing on x86 */
15234 #define smp_mb__before_atomic_dec() barrier()
15235diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15236index b154de7..bf18a5a 100644
15237--- a/arch/x86/include/asm/atomic64_32.h
15238+++ b/arch/x86/include/asm/atomic64_32.h
15239@@ -12,6 +12,14 @@ typedef struct {
15240 u64 __aligned(8) counter;
15241 } atomic64_t;
15242
15243+#ifdef CONFIG_PAX_REFCOUNT
15244+typedef struct {
15245+ u64 __aligned(8) counter;
15246+} atomic64_unchecked_t;
15247+#else
15248+typedef atomic64_t atomic64_unchecked_t;
15249+#endif
15250+
15251 #define ATOMIC64_INIT(val) { (val) }
15252
15253 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15254@@ -37,21 +45,31 @@ typedef struct {
15255 ATOMIC64_DECL_ONE(sym##_386)
15256
15257 ATOMIC64_DECL_ONE(add_386);
15258+ATOMIC64_DECL_ONE(add_unchecked_386);
15259 ATOMIC64_DECL_ONE(sub_386);
15260+ATOMIC64_DECL_ONE(sub_unchecked_386);
15261 ATOMIC64_DECL_ONE(inc_386);
15262+ATOMIC64_DECL_ONE(inc_unchecked_386);
15263 ATOMIC64_DECL_ONE(dec_386);
15264+ATOMIC64_DECL_ONE(dec_unchecked_386);
15265 #endif
15266
15267 #define alternative_atomic64(f, out, in...) \
15268 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15269
15270 ATOMIC64_DECL(read);
15271+ATOMIC64_DECL(read_unchecked);
15272 ATOMIC64_DECL(set);
15273+ATOMIC64_DECL(set_unchecked);
15274 ATOMIC64_DECL(xchg);
15275 ATOMIC64_DECL(add_return);
15276+ATOMIC64_DECL(add_return_unchecked);
15277 ATOMIC64_DECL(sub_return);
15278+ATOMIC64_DECL(sub_return_unchecked);
15279 ATOMIC64_DECL(inc_return);
15280+ATOMIC64_DECL(inc_return_unchecked);
15281 ATOMIC64_DECL(dec_return);
15282+ATOMIC64_DECL(dec_return_unchecked);
15283 ATOMIC64_DECL(dec_if_positive);
15284 ATOMIC64_DECL(inc_not_zero);
15285 ATOMIC64_DECL(add_unless);
15286@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15287 }
15288
15289 /**
15290+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15291+ * @p: pointer to type atomic64_unchecked_t
15292+ * @o: expected value
15293+ * @n: new value
15294+ *
15295+ * Atomically sets @v to @n if it was equal to @o and returns
15296+ * the old value.
15297+ */
15298+
15299+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15300+{
15301+ return cmpxchg64(&v->counter, o, n);
15302+}
15303+
15304+/**
15305 * atomic64_xchg - xchg atomic64 variable
15306 * @v: pointer to type atomic64_t
15307 * @n: value to assign
15308@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15309 }
15310
15311 /**
15312+ * atomic64_set_unchecked - set atomic64 variable
15313+ * @v: pointer to type atomic64_unchecked_t
15314+ * @n: value to assign
15315+ *
15316+ * Atomically sets the value of @v to @n.
15317+ */
15318+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15319+{
15320+ unsigned high = (unsigned)(i >> 32);
15321+ unsigned low = (unsigned)i;
15322+ alternative_atomic64(set, /* no output */,
15323+ "S" (v), "b" (low), "c" (high)
15324+ : "eax", "edx", "memory");
15325+}
15326+
15327+/**
15328 * atomic64_read - read atomic64 variable
15329 * @v: pointer to type atomic64_t
15330 *
15331@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15332 }
15333
15334 /**
15335+ * atomic64_read_unchecked - read atomic64 variable
15336+ * @v: pointer to type atomic64_unchecked_t
15337+ *
15338+ * Atomically reads the value of @v and returns it.
15339+ */
15340+static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15341+{
15342+ long long r;
15343+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15344+ return r;
15345+ }
15346+
15347+/**
15348 * atomic64_add_return - add and return
15349 * @i: integer value to add
15350 * @v: pointer to type atomic64_t
15351@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15352 return i;
15353 }
15354
15355+/**
15356+ * atomic64_add_return_unchecked - add and return
15357+ * @i: integer value to add
15358+ * @v: pointer to type atomic64_unchecked_t
15359+ *
15360+ * Atomically adds @i to @v and returns @i + *@v
15361+ */
15362+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15363+{
15364+ alternative_atomic64(add_return_unchecked,
15365+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15366+ ASM_NO_INPUT_CLOBBER("memory"));
15367+ return i;
15368+}
15369+
15370 /*
15371 * Other variants with different arithmetic operators:
15372 */
15373@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15374 return a;
15375 }
15376
15377+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15378+{
15379+ long long a;
15380+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
15381+ "S" (v) : "memory", "ecx");
15382+ return a;
15383+}
15384+
15385 static inline long long atomic64_dec_return(atomic64_t *v)
15386 {
15387 long long a;
15388@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15389 }
15390
15391 /**
15392+ * atomic64_add_unchecked - add integer to atomic64 variable
15393+ * @i: integer value to add
15394+ * @v: pointer to type atomic64_unchecked_t
15395+ *
15396+ * Atomically adds @i to @v.
15397+ */
15398+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15399+{
15400+ __alternative_atomic64(add_unchecked, add_return_unchecked,
15401+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15402+ ASM_NO_INPUT_CLOBBER("memory"));
15403+ return i;
15404+}
15405+
15406+/**
15407 * atomic64_sub - subtract the atomic64 variable
15408 * @i: integer value to subtract
15409 * @v: pointer to type atomic64_t
15410diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15411index 46e9052..ae45136 100644
15412--- a/arch/x86/include/asm/atomic64_64.h
15413+++ b/arch/x86/include/asm/atomic64_64.h
15414@@ -18,7 +18,19 @@
15415 */
15416 static inline long atomic64_read(const atomic64_t *v)
15417 {
15418- return (*(volatile long *)&(v)->counter);
15419+ return (*(volatile const long *)&(v)->counter);
15420+}
15421+
15422+/**
15423+ * atomic64_read_unchecked - read atomic64 variable
15424+ * @v: pointer of type atomic64_unchecked_t
15425+ *
15426+ * Atomically reads the value of @v.
15427+ * Doesn't imply a read memory barrier.
15428+ */
15429+static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15430+{
15431+ return (*(volatile const long *)&(v)->counter);
15432 }
15433
15434 /**
15435@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15436 }
15437
15438 /**
15439+ * atomic64_set_unchecked - set atomic64 variable
15440+ * @v: pointer to type atomic64_unchecked_t
15441+ * @i: required value
15442+ *
15443+ * Atomically sets the value of @v to @i.
15444+ */
15445+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15446+{
15447+ v->counter = i;
15448+}
15449+
15450+/**
15451 * atomic64_add - add integer to atomic64 variable
15452 * @i: integer value to add
15453 * @v: pointer to type atomic64_t
15454@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15455 */
15456 static inline void atomic64_add(long i, atomic64_t *v)
15457 {
15458+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
15459+
15460+#ifdef CONFIG_PAX_REFCOUNT
15461+ "jno 0f\n"
15462+ LOCK_PREFIX "subq %1,%0\n"
15463+ "int $4\n0:\n"
15464+ _ASM_EXTABLE(0b, 0b)
15465+#endif
15466+
15467+ : "=m" (v->counter)
15468+ : "er" (i), "m" (v->counter));
15469+}
15470+
15471+/**
15472+ * atomic64_add_unchecked - add integer to atomic64 variable
15473+ * @i: integer value to add
15474+ * @v: pointer to type atomic64_unchecked_t
15475+ *
15476+ * Atomically adds @i to @v.
15477+ */
15478+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15479+{
15480 asm volatile(LOCK_PREFIX "addq %1,%0"
15481 : "=m" (v->counter)
15482 : "er" (i), "m" (v->counter));
15483@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15484 */
15485 static inline void atomic64_sub(long i, atomic64_t *v)
15486 {
15487- asm volatile(LOCK_PREFIX "subq %1,%0"
15488+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15489+
15490+#ifdef CONFIG_PAX_REFCOUNT
15491+ "jno 0f\n"
15492+ LOCK_PREFIX "addq %1,%0\n"
15493+ "int $4\n0:\n"
15494+ _ASM_EXTABLE(0b, 0b)
15495+#endif
15496+
15497+ : "=m" (v->counter)
15498+ : "er" (i), "m" (v->counter));
15499+}
15500+
15501+/**
15502+ * atomic64_sub_unchecked - subtract the atomic64 variable
15503+ * @i: integer value to subtract
15504+ * @v: pointer to type atomic64_unchecked_t
15505+ *
15506+ * Atomically subtracts @i from @v.
15507+ */
15508+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15509+{
15510+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15511 : "=m" (v->counter)
15512 : "er" (i), "m" (v->counter));
15513 }
15514@@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15515 */
15516 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15517 {
15518- GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15519+ GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15520 }
15521
15522 /**
15523@@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15524 */
15525 static inline void atomic64_inc(atomic64_t *v)
15526 {
15527+ asm volatile(LOCK_PREFIX "incq %0\n"
15528+
15529+#ifdef CONFIG_PAX_REFCOUNT
15530+ "jno 0f\n"
15531+ LOCK_PREFIX "decq %0\n"
15532+ "int $4\n0:\n"
15533+ _ASM_EXTABLE(0b, 0b)
15534+#endif
15535+
15536+ : "=m" (v->counter)
15537+ : "m" (v->counter));
15538+}
15539+
15540+/**
15541+ * atomic64_inc_unchecked - increment atomic64 variable
15542+ * @v: pointer to type atomic64_unchecked_t
15543+ *
15544+ * Atomically increments @v by 1.
15545+ */
15546+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15547+{
15548 asm volatile(LOCK_PREFIX "incq %0"
15549 : "=m" (v->counter)
15550 : "m" (v->counter));
15551@@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15552 */
15553 static inline void atomic64_dec(atomic64_t *v)
15554 {
15555- asm volatile(LOCK_PREFIX "decq %0"
15556+ asm volatile(LOCK_PREFIX "decq %0\n"
15557+
15558+#ifdef CONFIG_PAX_REFCOUNT
15559+ "jno 0f\n"
15560+ LOCK_PREFIX "incq %0\n"
15561+ "int $4\n0:\n"
15562+ _ASM_EXTABLE(0b, 0b)
15563+#endif
15564+
15565+ : "=m" (v->counter)
15566+ : "m" (v->counter));
15567+}
15568+
15569+/**
15570+ * atomic64_dec_unchecked - decrement atomic64 variable
15571+ * @v: pointer to type atomic64_t
15572+ *
15573+ * Atomically decrements @v by 1.
15574+ */
15575+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15576+{
15577+ asm volatile(LOCK_PREFIX "decq %0\n"
15578 : "=m" (v->counter)
15579 : "m" (v->counter));
15580 }
15581@@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15582 */
15583 static inline int atomic64_dec_and_test(atomic64_t *v)
15584 {
15585- GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15586+ GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15587 }
15588
15589 /**
15590@@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15591 */
15592 static inline int atomic64_inc_and_test(atomic64_t *v)
15593 {
15594- GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15595+ GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15596 }
15597
15598 /**
15599@@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15600 */
15601 static inline int atomic64_add_negative(long i, atomic64_t *v)
15602 {
15603- GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15604+ GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15605 }
15606
15607 /**
15608@@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15609 */
15610 static inline long atomic64_add_return(long i, atomic64_t *v)
15611 {
15612+ return i + xadd_check_overflow(&v->counter, i);
15613+}
15614+
15615+/**
15616+ * atomic64_add_return_unchecked - add and return
15617+ * @i: integer value to add
15618+ * @v: pointer to type atomic64_unchecked_t
15619+ *
15620+ * Atomically adds @i to @v and returns @i + @v
15621+ */
15622+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15623+{
15624 return i + xadd(&v->counter, i);
15625 }
15626
15627@@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15628 }
15629
15630 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15631+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15632+{
15633+ return atomic64_add_return_unchecked(1, v);
15634+}
15635 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15636
15637 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15638@@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15639 return cmpxchg(&v->counter, old, new);
15640 }
15641
15642+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15643+{
15644+ return cmpxchg(&v->counter, old, new);
15645+}
15646+
15647 static inline long atomic64_xchg(atomic64_t *v, long new)
15648 {
15649 return xchg(&v->counter, new);
15650@@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15651 */
15652 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15653 {
15654- long c, old;
15655+ long c, old, new;
15656 c = atomic64_read(v);
15657 for (;;) {
15658- if (unlikely(c == (u)))
15659+ if (unlikely(c == u))
15660 break;
15661- old = atomic64_cmpxchg((v), c, c + (a));
15662+
15663+ asm volatile("add %2,%0\n"
15664+
15665+#ifdef CONFIG_PAX_REFCOUNT
15666+ "jno 0f\n"
15667+ "sub %2,%0\n"
15668+ "int $4\n0:\n"
15669+ _ASM_EXTABLE(0b, 0b)
15670+#endif
15671+
15672+ : "=r" (new)
15673+ : "0" (c), "ir" (a));
15674+
15675+ old = atomic64_cmpxchg(v, c, new);
15676 if (likely(old == c))
15677 break;
15678 c = old;
15679 }
15680- return c != (u);
15681+ return c != u;
15682 }
15683
15684 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15685diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15686index 9fc1af7..fc71228 100644
15687--- a/arch/x86/include/asm/bitops.h
15688+++ b/arch/x86/include/asm/bitops.h
15689@@ -49,7 +49,7 @@
15690 * a mask operation on a byte.
15691 */
15692 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15693-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15694+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15695 #define CONST_MASK(nr) (1 << ((nr) & 7))
15696
15697 /**
15698@@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
15699 */
15700 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
15701 {
15702- GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15703+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15704 }
15705
15706 /**
15707@@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
15708 */
15709 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
15710 {
15711- GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15712+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15713 }
15714
15715 /**
15716@@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
15717 */
15718 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
15719 {
15720- GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15721+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15722 }
15723
15724 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
15725@@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15726 *
15727 * Undefined if no bit exists, so code should check against 0 first.
15728 */
15729-static inline unsigned long __ffs(unsigned long word)
15730+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15731 {
15732 asm("rep; bsf %1,%0"
15733 : "=r" (word)
15734@@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
15735 *
15736 * Undefined if no zero exists, so code should check against ~0UL first.
15737 */
15738-static inline unsigned long ffz(unsigned long word)
15739+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15740 {
15741 asm("rep; bsf %1,%0"
15742 : "=r" (word)
15743@@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
15744 *
15745 * Undefined if no set bit exists, so code should check against 0 first.
15746 */
15747-static inline unsigned long __fls(unsigned long word)
15748+static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15749 {
15750 asm("bsr %1,%0"
15751 : "=r" (word)
15752@@ -436,7 +436,7 @@ static inline int ffs(int x)
15753 * set bit if value is nonzero. The last (most significant) bit is
15754 * at position 32.
15755 */
15756-static inline int fls(int x)
15757+static inline int __intentional_overflow(-1) fls(int x)
15758 {
15759 int r;
15760
15761@@ -478,7 +478,7 @@ static inline int fls(int x)
15762 * at position 64.
15763 */
15764 #ifdef CONFIG_X86_64
15765-static __always_inline int fls64(__u64 x)
15766+static __always_inline long fls64(__u64 x)
15767 {
15768 int bitpos = -1;
15769 /*
15770diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15771index 4fa687a..60f2d39 100644
15772--- a/arch/x86/include/asm/boot.h
15773+++ b/arch/x86/include/asm/boot.h
15774@@ -6,10 +6,15 @@
15775 #include <uapi/asm/boot.h>
15776
15777 /* Physical address where kernel should be loaded. */
15778-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15779+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15780 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15781 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15782
15783+#ifndef __ASSEMBLY__
15784+extern unsigned char __LOAD_PHYSICAL_ADDR[];
15785+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15786+#endif
15787+
15788 /* Minimum kernel alignment, as a power of two */
15789 #ifdef CONFIG_X86_64
15790 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15791diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15792index 48f99f1..d78ebf9 100644
15793--- a/arch/x86/include/asm/cache.h
15794+++ b/arch/x86/include/asm/cache.h
15795@@ -5,12 +5,13 @@
15796
15797 /* L1 cache line size */
15798 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15799-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15800+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15801
15802 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15803+#define __read_only __attribute__((__section__(".data..read_only")))
15804
15805 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15806-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15807+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15808
15809 #ifdef CONFIG_X86_VSMP
15810 #ifdef CONFIG_SMP
15811diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15812index 9863ee3..4a1f8e1 100644
15813--- a/arch/x86/include/asm/cacheflush.h
15814+++ b/arch/x86/include/asm/cacheflush.h
15815@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15816 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15817
15818 if (pg_flags == _PGMT_DEFAULT)
15819- return -1;
15820+ return ~0UL;
15821 else if (pg_flags == _PGMT_WC)
15822 return _PAGE_CACHE_WC;
15823 else if (pg_flags == _PGMT_UC_MINUS)
15824diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15825index cb4c73b..c473c29 100644
15826--- a/arch/x86/include/asm/calling.h
15827+++ b/arch/x86/include/asm/calling.h
15828@@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
15829 #define RSP 152
15830 #define SS 160
15831
15832-#define ARGOFFSET R11
15833-#define SWFRAME ORIG_RAX
15834+#define ARGOFFSET R15
15835
15836 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15837- subq $9*8+\addskip, %rsp
15838- CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15839- movq_cfi rdi, 8*8
15840- movq_cfi rsi, 7*8
15841- movq_cfi rdx, 6*8
15842+ subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15843+ CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15844+ movq_cfi rdi, RDI
15845+ movq_cfi rsi, RSI
15846+ movq_cfi rdx, RDX
15847
15848 .if \save_rcx
15849- movq_cfi rcx, 5*8
15850+ movq_cfi rcx, RCX
15851 .endif
15852
15853- movq_cfi rax, 4*8
15854+ movq_cfi rax, RAX
15855
15856 .if \save_r891011
15857- movq_cfi r8, 3*8
15858- movq_cfi r9, 2*8
15859- movq_cfi r10, 1*8
15860- movq_cfi r11, 0*8
15861+ movq_cfi r8, R8
15862+ movq_cfi r9, R9
15863+ movq_cfi r10, R10
15864+ movq_cfi r11, R11
15865 .endif
15866
15867+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15868+ movq_cfi r12, R12
15869+#endif
15870+
15871 .endm
15872
15873-#define ARG_SKIP (9*8)
15874+#define ARG_SKIP ORIG_RAX
15875
15876 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15877 rstor_r8910=1, rstor_rdx=1
15878+
15879+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15880+ movq_cfi_restore R12, r12
15881+#endif
15882+
15883 .if \rstor_r11
15884- movq_cfi_restore 0*8, r11
15885+ movq_cfi_restore R11, r11
15886 .endif
15887
15888 .if \rstor_r8910
15889- movq_cfi_restore 1*8, r10
15890- movq_cfi_restore 2*8, r9
15891- movq_cfi_restore 3*8, r8
15892+ movq_cfi_restore R10, r10
15893+ movq_cfi_restore R9, r9
15894+ movq_cfi_restore R8, r8
15895 .endif
15896
15897 .if \rstor_rax
15898- movq_cfi_restore 4*8, rax
15899+ movq_cfi_restore RAX, rax
15900 .endif
15901
15902 .if \rstor_rcx
15903- movq_cfi_restore 5*8, rcx
15904+ movq_cfi_restore RCX, rcx
15905 .endif
15906
15907 .if \rstor_rdx
15908- movq_cfi_restore 6*8, rdx
15909+ movq_cfi_restore RDX, rdx
15910 .endif
15911
15912- movq_cfi_restore 7*8, rsi
15913- movq_cfi_restore 8*8, rdi
15914+ movq_cfi_restore RSI, rsi
15915+ movq_cfi_restore RDI, rdi
15916
15917- .if ARG_SKIP+\addskip > 0
15918- addq $ARG_SKIP+\addskip, %rsp
15919- CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
15920+ .if ORIG_RAX+\addskip > 0
15921+ addq $ORIG_RAX+\addskip, %rsp
15922+ CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
15923 .endif
15924 .endm
15925
15926- .macro LOAD_ARGS offset, skiprax=0
15927- movq \offset(%rsp), %r11
15928- movq \offset+8(%rsp), %r10
15929- movq \offset+16(%rsp), %r9
15930- movq \offset+24(%rsp), %r8
15931- movq \offset+40(%rsp), %rcx
15932- movq \offset+48(%rsp), %rdx
15933- movq \offset+56(%rsp), %rsi
15934- movq \offset+64(%rsp), %rdi
15935+ .macro LOAD_ARGS skiprax=0
15936+ movq R11(%rsp), %r11
15937+ movq R10(%rsp), %r10
15938+ movq R9(%rsp), %r9
15939+ movq R8(%rsp), %r8
15940+ movq RCX(%rsp), %rcx
15941+ movq RDX(%rsp), %rdx
15942+ movq RSI(%rsp), %rsi
15943+ movq RDI(%rsp), %rdi
15944 .if \skiprax
15945 .else
15946- movq \offset+72(%rsp), %rax
15947+ movq RAX(%rsp), %rax
15948 .endif
15949 .endm
15950
15951-#define REST_SKIP (6*8)
15952-
15953 .macro SAVE_REST
15954- subq $REST_SKIP, %rsp
15955- CFI_ADJUST_CFA_OFFSET REST_SKIP
15956- movq_cfi rbx, 5*8
15957- movq_cfi rbp, 4*8
15958- movq_cfi r12, 3*8
15959- movq_cfi r13, 2*8
15960- movq_cfi r14, 1*8
15961- movq_cfi r15, 0*8
15962+ movq_cfi rbx, RBX
15963+ movq_cfi rbp, RBP
15964+
15965+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15966+ movq_cfi r12, R12
15967+#endif
15968+
15969+ movq_cfi r13, R13
15970+ movq_cfi r14, R14
15971+ movq_cfi r15, R15
15972 .endm
15973
15974 .macro RESTORE_REST
15975- movq_cfi_restore 0*8, r15
15976- movq_cfi_restore 1*8, r14
15977- movq_cfi_restore 2*8, r13
15978- movq_cfi_restore 3*8, r12
15979- movq_cfi_restore 4*8, rbp
15980- movq_cfi_restore 5*8, rbx
15981- addq $REST_SKIP, %rsp
15982- CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
15983+ movq_cfi_restore R15, r15
15984+ movq_cfi_restore R14, r14
15985+ movq_cfi_restore R13, r13
15986+
15987+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15988+ movq_cfi_restore R12, r12
15989+#endif
15990+
15991+ movq_cfi_restore RBP, rbp
15992+ movq_cfi_restore RBX, rbx
15993 .endm
15994
15995 .macro SAVE_ALL
15996diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
15997index f50de69..2b0a458 100644
15998--- a/arch/x86/include/asm/checksum_32.h
15999+++ b/arch/x86/include/asm/checksum_32.h
16000@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16001 int len, __wsum sum,
16002 int *src_err_ptr, int *dst_err_ptr);
16003
16004+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16005+ int len, __wsum sum,
16006+ int *src_err_ptr, int *dst_err_ptr);
16007+
16008+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16009+ int len, __wsum sum,
16010+ int *src_err_ptr, int *dst_err_ptr);
16011+
16012 /*
16013 * Note: when you get a NULL pointer exception here this means someone
16014 * passed in an incorrect kernel address to one of these functions.
16015@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16016
16017 might_sleep();
16018 stac();
16019- ret = csum_partial_copy_generic((__force void *)src, dst,
16020+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16021 len, sum, err_ptr, NULL);
16022 clac();
16023
16024@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16025 might_sleep();
16026 if (access_ok(VERIFY_WRITE, dst, len)) {
16027 stac();
16028- ret = csum_partial_copy_generic(src, (__force void *)dst,
16029+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16030 len, sum, NULL, err_ptr);
16031 clac();
16032 return ret;
16033diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16034index d47786a..ce1b05d 100644
16035--- a/arch/x86/include/asm/cmpxchg.h
16036+++ b/arch/x86/include/asm/cmpxchg.h
16037@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
16038 __compiletime_error("Bad argument size for cmpxchg");
16039 extern void __xadd_wrong_size(void)
16040 __compiletime_error("Bad argument size for xadd");
16041+extern void __xadd_check_overflow_wrong_size(void)
16042+ __compiletime_error("Bad argument size for xadd_check_overflow");
16043 extern void __add_wrong_size(void)
16044 __compiletime_error("Bad argument size for add");
16045+extern void __add_check_overflow_wrong_size(void)
16046+ __compiletime_error("Bad argument size for add_check_overflow");
16047
16048 /*
16049 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16050@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
16051 __ret; \
16052 })
16053
16054+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16055+ ({ \
16056+ __typeof__ (*(ptr)) __ret = (arg); \
16057+ switch (sizeof(*(ptr))) { \
16058+ case __X86_CASE_L: \
16059+ asm volatile (lock #op "l %0, %1\n" \
16060+ "jno 0f\n" \
16061+ "mov %0,%1\n" \
16062+ "int $4\n0:\n" \
16063+ _ASM_EXTABLE(0b, 0b) \
16064+ : "+r" (__ret), "+m" (*(ptr)) \
16065+ : : "memory", "cc"); \
16066+ break; \
16067+ case __X86_CASE_Q: \
16068+ asm volatile (lock #op "q %q0, %1\n" \
16069+ "jno 0f\n" \
16070+ "mov %0,%1\n" \
16071+ "int $4\n0:\n" \
16072+ _ASM_EXTABLE(0b, 0b) \
16073+ : "+r" (__ret), "+m" (*(ptr)) \
16074+ : : "memory", "cc"); \
16075+ break; \
16076+ default: \
16077+ __ ## op ## _check_overflow_wrong_size(); \
16078+ } \
16079+ __ret; \
16080+ })
16081+
16082 /*
16083 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16084 * Since this is generally used to protect other memory information, we
16085@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
16086 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16087 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16088
16089+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16090+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16091+
16092 #define __add(ptr, inc, lock) \
16093 ({ \
16094 __typeof__ (*(ptr)) __ret = (inc); \
16095diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16096index 59c6c40..5e0b22c 100644
16097--- a/arch/x86/include/asm/compat.h
16098+++ b/arch/x86/include/asm/compat.h
16099@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16100 typedef u32 compat_uint_t;
16101 typedef u32 compat_ulong_t;
16102 typedef u64 __attribute__((aligned(4))) compat_u64;
16103-typedef u32 compat_uptr_t;
16104+typedef u32 __user compat_uptr_t;
16105
16106 struct compat_timespec {
16107 compat_time_t tv_sec;
16108diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16109index 89270b4..f0abf8e 100644
16110--- a/arch/x86/include/asm/cpufeature.h
16111+++ b/arch/x86/include/asm/cpufeature.h
16112@@ -203,7 +203,7 @@
16113 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16114 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16115 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16116-
16117+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16118
16119 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16120 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16121@@ -211,7 +211,7 @@
16122 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16123 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16124 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16125-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16126+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16127 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16128 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16129 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16130@@ -353,6 +353,7 @@ extern const char * const x86_power_flags[32];
16131 #undef cpu_has_centaur_mcr
16132 #define cpu_has_centaur_mcr 0
16133
16134+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16135 #endif /* CONFIG_X86_64 */
16136
16137 #if __GNUC__ >= 4
16138@@ -405,7 +406,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16139
16140 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16141 t_warn:
16142- warn_pre_alternatives();
16143+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16144+ warn_pre_alternatives();
16145 return false;
16146 #endif
16147
16148@@ -425,7 +427,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16149 ".section .discard,\"aw\",@progbits\n"
16150 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16151 ".previous\n"
16152- ".section .altinstr_replacement,\"ax\"\n"
16153+ ".section .altinstr_replacement,\"a\"\n"
16154 "3: movb $1,%0\n"
16155 "4:\n"
16156 ".previous\n"
16157@@ -462,7 +464,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16158 " .byte 2b - 1b\n" /* src len */
16159 " .byte 4f - 3f\n" /* repl len */
16160 ".previous\n"
16161- ".section .altinstr_replacement,\"ax\"\n"
16162+ ".section .altinstr_replacement,\"a\"\n"
16163 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16164 "4:\n"
16165 ".previous\n"
16166@@ -495,7 +497,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16167 ".section .discard,\"aw\",@progbits\n"
16168 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16169 ".previous\n"
16170- ".section .altinstr_replacement,\"ax\"\n"
16171+ ".section .altinstr_replacement,\"a\"\n"
16172 "3: movb $0,%0\n"
16173 "4:\n"
16174 ".previous\n"
16175@@ -509,7 +511,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16176 ".section .discard,\"aw\",@progbits\n"
16177 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16178 ".previous\n"
16179- ".section .altinstr_replacement,\"ax\"\n"
16180+ ".section .altinstr_replacement,\"a\"\n"
16181 "5: movb $1,%0\n"
16182 "6:\n"
16183 ".previous\n"
16184diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16185index 50d033a..37deb26 100644
16186--- a/arch/x86/include/asm/desc.h
16187+++ b/arch/x86/include/asm/desc.h
16188@@ -4,6 +4,7 @@
16189 #include <asm/desc_defs.h>
16190 #include <asm/ldt.h>
16191 #include <asm/mmu.h>
16192+#include <asm/pgtable.h>
16193
16194 #include <linux/smp.h>
16195 #include <linux/percpu.h>
16196@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16197
16198 desc->type = (info->read_exec_only ^ 1) << 1;
16199 desc->type |= info->contents << 2;
16200+ desc->type |= info->seg_not_present ^ 1;
16201
16202 desc->s = 1;
16203 desc->dpl = 0x3;
16204@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16205 }
16206
16207 extern struct desc_ptr idt_descr;
16208-extern gate_desc idt_table[];
16209-extern struct desc_ptr debug_idt_descr;
16210-extern gate_desc debug_idt_table[];
16211-
16212-struct gdt_page {
16213- struct desc_struct gdt[GDT_ENTRIES];
16214-} __attribute__((aligned(PAGE_SIZE)));
16215-
16216-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16217+extern gate_desc idt_table[IDT_ENTRIES];
16218+extern const struct desc_ptr debug_idt_descr;
16219+extern gate_desc debug_idt_table[IDT_ENTRIES];
16220
16221+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16222 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16223 {
16224- return per_cpu(gdt_page, cpu).gdt;
16225+ return cpu_gdt_table[cpu];
16226 }
16227
16228 #ifdef CONFIG_X86_64
16229@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16230 unsigned long base, unsigned dpl, unsigned flags,
16231 unsigned short seg)
16232 {
16233- gate->a = (seg << 16) | (base & 0xffff);
16234- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16235+ gate->gate.offset_low = base;
16236+ gate->gate.seg = seg;
16237+ gate->gate.reserved = 0;
16238+ gate->gate.type = type;
16239+ gate->gate.s = 0;
16240+ gate->gate.dpl = dpl;
16241+ gate->gate.p = 1;
16242+ gate->gate.offset_high = base >> 16;
16243 }
16244
16245 #endif
16246@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16247
16248 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16249 {
16250+ pax_open_kernel();
16251 memcpy(&idt[entry], gate, sizeof(*gate));
16252+ pax_close_kernel();
16253 }
16254
16255 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16256 {
16257+ pax_open_kernel();
16258 memcpy(&ldt[entry], desc, 8);
16259+ pax_close_kernel();
16260 }
16261
16262 static inline void
16263@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16264 default: size = sizeof(*gdt); break;
16265 }
16266
16267+ pax_open_kernel();
16268 memcpy(&gdt[entry], desc, size);
16269+ pax_close_kernel();
16270 }
16271
16272 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16273@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16274
16275 static inline void native_load_tr_desc(void)
16276 {
16277+ pax_open_kernel();
16278 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16279+ pax_close_kernel();
16280 }
16281
16282 static inline void native_load_gdt(const struct desc_ptr *dtr)
16283@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16284 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16285 unsigned int i;
16286
16287+ pax_open_kernel();
16288 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16289 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16290+ pax_close_kernel();
16291 }
16292
16293 #define _LDT_empty(info) \
16294@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16295 preempt_enable();
16296 }
16297
16298-static inline unsigned long get_desc_base(const struct desc_struct *desc)
16299+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16300 {
16301 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16302 }
16303@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16304 }
16305
16306 #ifdef CONFIG_X86_64
16307-static inline void set_nmi_gate(int gate, void *addr)
16308+static inline void set_nmi_gate(int gate, const void *addr)
16309 {
16310 gate_desc s;
16311
16312@@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16313 #endif
16314
16315 #ifdef CONFIG_TRACING
16316-extern struct desc_ptr trace_idt_descr;
16317-extern gate_desc trace_idt_table[];
16318+extern const struct desc_ptr trace_idt_descr;
16319+extern gate_desc trace_idt_table[IDT_ENTRIES];
16320 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16321 {
16322 write_idt_entry(trace_idt_table, entry, gate);
16323 }
16324
16325-static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16326+static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16327 unsigned dpl, unsigned ist, unsigned seg)
16328 {
16329 gate_desc s;
16330@@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16331 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16332 #endif
16333
16334-static inline void _set_gate(int gate, unsigned type, void *addr,
16335+static inline void _set_gate(int gate, unsigned type, const void *addr,
16336 unsigned dpl, unsigned ist, unsigned seg)
16337 {
16338 gate_desc s;
16339@@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16340 #define set_intr_gate(n, addr) \
16341 do { \
16342 BUG_ON((unsigned)n > 0xFF); \
16343- _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16344+ _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16345 __KERNEL_CS); \
16346- _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16347+ _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16348 0, 0, __KERNEL_CS); \
16349 } while (0)
16350
16351@@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16352 /*
16353 * This routine sets up an interrupt gate at directory privilege level 3.
16354 */
16355-static inline void set_system_intr_gate(unsigned int n, void *addr)
16356+static inline void set_system_intr_gate(unsigned int n, const void *addr)
16357 {
16358 BUG_ON((unsigned)n > 0xFF);
16359 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16360 }
16361
16362-static inline void set_system_trap_gate(unsigned int n, void *addr)
16363+static inline void set_system_trap_gate(unsigned int n, const void *addr)
16364 {
16365 BUG_ON((unsigned)n > 0xFF);
16366 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16367 }
16368
16369-static inline void set_trap_gate(unsigned int n, void *addr)
16370+static inline void set_trap_gate(unsigned int n, const void *addr)
16371 {
16372 BUG_ON((unsigned)n > 0xFF);
16373 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16374@@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16375 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16376 {
16377 BUG_ON((unsigned)n > 0xFF);
16378- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16379+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16380 }
16381
16382-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16383+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16384 {
16385 BUG_ON((unsigned)n > 0xFF);
16386 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16387 }
16388
16389-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16390+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16391 {
16392 BUG_ON((unsigned)n > 0xFF);
16393 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16394@@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16395 else
16396 load_idt((const struct desc_ptr *)&idt_descr);
16397 }
16398+
16399+#ifdef CONFIG_X86_32
16400+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16401+{
16402+ struct desc_struct d;
16403+
16404+ if (likely(limit))
16405+ limit = (limit - 1UL) >> PAGE_SHIFT;
16406+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
16407+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16408+}
16409+#endif
16410+
16411 #endif /* _ASM_X86_DESC_H */
16412diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16413index 278441f..b95a174 100644
16414--- a/arch/x86/include/asm/desc_defs.h
16415+++ b/arch/x86/include/asm/desc_defs.h
16416@@ -31,6 +31,12 @@ struct desc_struct {
16417 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16418 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16419 };
16420+ struct {
16421+ u16 offset_low;
16422+ u16 seg;
16423+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16424+ unsigned offset_high: 16;
16425+ } gate;
16426 };
16427 } __attribute__((packed));
16428
16429diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16430index ced283a..ffe04cc 100644
16431--- a/arch/x86/include/asm/div64.h
16432+++ b/arch/x86/include/asm/div64.h
16433@@ -39,7 +39,7 @@
16434 __mod; \
16435 })
16436
16437-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16438+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16439 {
16440 union {
16441 u64 v64;
16442diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16443index 9c999c1..3860cb8 100644
16444--- a/arch/x86/include/asm/elf.h
16445+++ b/arch/x86/include/asm/elf.h
16446@@ -243,7 +243,25 @@ extern int force_personality32;
16447 the loader. We need to make sure that it is out of the way of the program
16448 that it will "exec", and that there is sufficient room for the brk. */
16449
16450+#ifdef CONFIG_PAX_SEGMEXEC
16451+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16452+#else
16453 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16454+#endif
16455+
16456+#ifdef CONFIG_PAX_ASLR
16457+#ifdef CONFIG_X86_32
16458+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16459+
16460+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16461+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16462+#else
16463+#define PAX_ELF_ET_DYN_BASE 0x400000UL
16464+
16465+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16466+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16467+#endif
16468+#endif
16469
16470 /* This yields a mask that user programs can use to figure out what
16471 instruction set this CPU supports. This could be done in user space,
16472@@ -296,16 +314,12 @@ do { \
16473
16474 #define ARCH_DLINFO \
16475 do { \
16476- if (vdso_enabled) \
16477- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16478- (unsigned long)current->mm->context.vdso); \
16479+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16480 } while (0)
16481
16482 #define ARCH_DLINFO_X32 \
16483 do { \
16484- if (vdso_enabled) \
16485- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16486- (unsigned long)current->mm->context.vdso); \
16487+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16488 } while (0)
16489
16490 #define AT_SYSINFO 32
16491@@ -320,7 +334,7 @@ else \
16492
16493 #endif /* !CONFIG_X86_32 */
16494
16495-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16496+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16497
16498 #define VDSO_ENTRY \
16499 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
16500@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
16501 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
16502 #define compat_arch_setup_additional_pages syscall32_setup_pages
16503
16504-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16505-#define arch_randomize_brk arch_randomize_brk
16506-
16507 /*
16508 * True on X86_32 or when emulating IA32 on X86_64
16509 */
16510diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16511index 77a99ac..39ff7f5 100644
16512--- a/arch/x86/include/asm/emergency-restart.h
16513+++ b/arch/x86/include/asm/emergency-restart.h
16514@@ -1,6 +1,6 @@
16515 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16516 #define _ASM_X86_EMERGENCY_RESTART_H
16517
16518-extern void machine_emergency_restart(void);
16519+extern void machine_emergency_restart(void) __noreturn;
16520
16521 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16522diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16523index d3d7469..677ef72 100644
16524--- a/arch/x86/include/asm/floppy.h
16525+++ b/arch/x86/include/asm/floppy.h
16526@@ -229,18 +229,18 @@ static struct fd_routine_l {
16527 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16528 } fd_routine[] = {
16529 {
16530- request_dma,
16531- free_dma,
16532- get_dma_residue,
16533- dma_mem_alloc,
16534- hard_dma_setup
16535+ ._request_dma = request_dma,
16536+ ._free_dma = free_dma,
16537+ ._get_dma_residue = get_dma_residue,
16538+ ._dma_mem_alloc = dma_mem_alloc,
16539+ ._dma_setup = hard_dma_setup
16540 },
16541 {
16542- vdma_request_dma,
16543- vdma_nop,
16544- vdma_get_dma_residue,
16545- vdma_mem_alloc,
16546- vdma_dma_setup
16547+ ._request_dma = vdma_request_dma,
16548+ ._free_dma = vdma_nop,
16549+ ._get_dma_residue = vdma_get_dma_residue,
16550+ ._dma_mem_alloc = vdma_mem_alloc,
16551+ ._dma_setup = vdma_dma_setup
16552 }
16553 };
16554
16555diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16556index cea1c76..6c0d79b 100644
16557--- a/arch/x86/include/asm/fpu-internal.h
16558+++ b/arch/x86/include/asm/fpu-internal.h
16559@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16560 #define user_insn(insn, output, input...) \
16561 ({ \
16562 int err; \
16563+ pax_open_userland(); \
16564 asm volatile(ASM_STAC "\n" \
16565- "1:" #insn "\n\t" \
16566+ "1:" \
16567+ __copyuser_seg \
16568+ #insn "\n\t" \
16569 "2: " ASM_CLAC "\n" \
16570 ".section .fixup,\"ax\"\n" \
16571 "3: movl $-1,%[err]\n" \
16572@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16573 _ASM_EXTABLE(1b, 3b) \
16574 : [err] "=r" (err), output \
16575 : "0"(0), input); \
16576+ pax_close_userland(); \
16577 err; \
16578 })
16579
16580@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16581 "fnclex\n\t"
16582 "emms\n\t"
16583 "fildl %P[addr]" /* set F?P to defined value */
16584- : : [addr] "m" (tsk->thread.fpu.has_fpu));
16585+ : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16586 }
16587
16588 return fpu_restore_checking(&tsk->thread.fpu);
16589diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16590index be27ba1..04a8801 100644
16591--- a/arch/x86/include/asm/futex.h
16592+++ b/arch/x86/include/asm/futex.h
16593@@ -12,6 +12,7 @@
16594 #include <asm/smap.h>
16595
16596 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16597+ typecheck(u32 __user *, uaddr); \
16598 asm volatile("\t" ASM_STAC "\n" \
16599 "1:\t" insn "\n" \
16600 "2:\t" ASM_CLAC "\n" \
16601@@ -20,15 +21,16 @@
16602 "\tjmp\t2b\n" \
16603 "\t.previous\n" \
16604 _ASM_EXTABLE(1b, 3b) \
16605- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16606+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16607 : "i" (-EFAULT), "0" (oparg), "1" (0))
16608
16609 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16610+ typecheck(u32 __user *, uaddr); \
16611 asm volatile("\t" ASM_STAC "\n" \
16612 "1:\tmovl %2, %0\n" \
16613 "\tmovl\t%0, %3\n" \
16614 "\t" insn "\n" \
16615- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16616+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16617 "\tjnz\t1b\n" \
16618 "3:\t" ASM_CLAC "\n" \
16619 "\t.section .fixup,\"ax\"\n" \
16620@@ -38,7 +40,7 @@
16621 _ASM_EXTABLE(1b, 4b) \
16622 _ASM_EXTABLE(2b, 4b) \
16623 : "=&a" (oldval), "=&r" (ret), \
16624- "+m" (*uaddr), "=&r" (tem) \
16625+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16626 : "r" (oparg), "i" (-EFAULT), "1" (0))
16627
16628 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16629@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16630
16631 pagefault_disable();
16632
16633+ pax_open_userland();
16634 switch (op) {
16635 case FUTEX_OP_SET:
16636- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16637+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16638 break;
16639 case FUTEX_OP_ADD:
16640- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16641+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16642 uaddr, oparg);
16643 break;
16644 case FUTEX_OP_OR:
16645@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16646 default:
16647 ret = -ENOSYS;
16648 }
16649+ pax_close_userland();
16650
16651 pagefault_enable();
16652
16653@@ -115,18 +119,20 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
16654 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
16655 return -EFAULT;
16656
16657+ pax_open_userland();
16658 asm volatile("\t" ASM_STAC "\n"
16659- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
16660+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
16661 "2:\t" ASM_CLAC "\n"
16662 "\t.section .fixup, \"ax\"\n"
16663 "3:\tmov %3, %0\n"
16664 "\tjmp 2b\n"
16665 "\t.previous\n"
16666 _ASM_EXTABLE(1b, 3b)
16667- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
16668+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
16669 : "i" (-EFAULT), "r" (newval), "1" (oldval)
16670 : "memory"
16671 );
16672+ pax_close_userland();
16673
16674 *uval = oldval;
16675 return ret;
16676diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16677index cba45d9..86344ba 100644
16678--- a/arch/x86/include/asm/hw_irq.h
16679+++ b/arch/x86/include/asm/hw_irq.h
16680@@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
16681 extern void enable_IO_APIC(void);
16682
16683 /* Statistics */
16684-extern atomic_t irq_err_count;
16685-extern atomic_t irq_mis_count;
16686+extern atomic_unchecked_t irq_err_count;
16687+extern atomic_unchecked_t irq_mis_count;
16688
16689 /* EISA */
16690 extern void eisa_set_level_irq(unsigned int irq);
16691diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16692index a203659..9889f1c 100644
16693--- a/arch/x86/include/asm/i8259.h
16694+++ b/arch/x86/include/asm/i8259.h
16695@@ -62,7 +62,7 @@ struct legacy_pic {
16696 void (*init)(int auto_eoi);
16697 int (*irq_pending)(unsigned int irq);
16698 void (*make_irq)(unsigned int irq);
16699-};
16700+} __do_const;
16701
16702 extern struct legacy_pic *legacy_pic;
16703 extern struct legacy_pic null_legacy_pic;
16704diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16705index 34f69cb..6d95446 100644
16706--- a/arch/x86/include/asm/io.h
16707+++ b/arch/x86/include/asm/io.h
16708@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16709 "m" (*(volatile type __force *)addr) barrier); }
16710
16711 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16712-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16713-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16714+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16715+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16716
16717 build_mmio_read(__readb, "b", unsigned char, "=q", )
16718-build_mmio_read(__readw, "w", unsigned short, "=r", )
16719-build_mmio_read(__readl, "l", unsigned int, "=r", )
16720+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16721+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16722
16723 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16724 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16725@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16726 return ioremap_nocache(offset, size);
16727 }
16728
16729-extern void iounmap(volatile void __iomem *addr);
16730+extern void iounmap(const volatile void __iomem *addr);
16731
16732 extern void set_iounmap_nonlazy(void);
16733
16734@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
16735
16736 #include <linux/vmalloc.h>
16737
16738+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16739+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16740+{
16741+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16742+}
16743+
16744+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16745+{
16746+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16747+}
16748+
16749 /*
16750 * Convert a virtual cached pointer to an uncached pointer
16751 */
16752diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16753index bba3cf8..06bc8da 100644
16754--- a/arch/x86/include/asm/irqflags.h
16755+++ b/arch/x86/include/asm/irqflags.h
16756@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16757 sti; \
16758 sysexit
16759
16760+#define GET_CR0_INTO_RDI mov %cr0, %rdi
16761+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16762+#define GET_CR3_INTO_RDI mov %cr3, %rdi
16763+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16764+
16765 #else
16766 #define INTERRUPT_RETURN iret
16767 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16768diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16769index 9454c16..e4100e3 100644
16770--- a/arch/x86/include/asm/kprobes.h
16771+++ b/arch/x86/include/asm/kprobes.h
16772@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16773 #define RELATIVEJUMP_SIZE 5
16774 #define RELATIVECALL_OPCODE 0xe8
16775 #define RELATIVE_ADDR_SIZE 4
16776-#define MAX_STACK_SIZE 64
16777-#define MIN_STACK_SIZE(ADDR) \
16778- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16779- THREAD_SIZE - (unsigned long)(ADDR))) \
16780- ? (MAX_STACK_SIZE) \
16781- : (((unsigned long)current_thread_info()) + \
16782- THREAD_SIZE - (unsigned long)(ADDR)))
16783+#define MAX_STACK_SIZE 64UL
16784+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16785
16786 #define flush_insn_slot(p) do { } while (0)
16787
16788diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16789index 4ad6560..75c7bdd 100644
16790--- a/arch/x86/include/asm/local.h
16791+++ b/arch/x86/include/asm/local.h
16792@@ -10,33 +10,97 @@ typedef struct {
16793 atomic_long_t a;
16794 } local_t;
16795
16796+typedef struct {
16797+ atomic_long_unchecked_t a;
16798+} local_unchecked_t;
16799+
16800 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16801
16802 #define local_read(l) atomic_long_read(&(l)->a)
16803+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16804 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16805+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16806
16807 static inline void local_inc(local_t *l)
16808 {
16809- asm volatile(_ASM_INC "%0"
16810+ asm volatile(_ASM_INC "%0\n"
16811+
16812+#ifdef CONFIG_PAX_REFCOUNT
16813+ "jno 0f\n"
16814+ _ASM_DEC "%0\n"
16815+ "int $4\n0:\n"
16816+ _ASM_EXTABLE(0b, 0b)
16817+#endif
16818+
16819+ : "+m" (l->a.counter));
16820+}
16821+
16822+static inline void local_inc_unchecked(local_unchecked_t *l)
16823+{
16824+ asm volatile(_ASM_INC "%0\n"
16825 : "+m" (l->a.counter));
16826 }
16827
16828 static inline void local_dec(local_t *l)
16829 {
16830- asm volatile(_ASM_DEC "%0"
16831+ asm volatile(_ASM_DEC "%0\n"
16832+
16833+#ifdef CONFIG_PAX_REFCOUNT
16834+ "jno 0f\n"
16835+ _ASM_INC "%0\n"
16836+ "int $4\n0:\n"
16837+ _ASM_EXTABLE(0b, 0b)
16838+#endif
16839+
16840+ : "+m" (l->a.counter));
16841+}
16842+
16843+static inline void local_dec_unchecked(local_unchecked_t *l)
16844+{
16845+ asm volatile(_ASM_DEC "%0\n"
16846 : "+m" (l->a.counter));
16847 }
16848
16849 static inline void local_add(long i, local_t *l)
16850 {
16851- asm volatile(_ASM_ADD "%1,%0"
16852+ asm volatile(_ASM_ADD "%1,%0\n"
16853+
16854+#ifdef CONFIG_PAX_REFCOUNT
16855+ "jno 0f\n"
16856+ _ASM_SUB "%1,%0\n"
16857+ "int $4\n0:\n"
16858+ _ASM_EXTABLE(0b, 0b)
16859+#endif
16860+
16861+ : "+m" (l->a.counter)
16862+ : "ir" (i));
16863+}
16864+
16865+static inline void local_add_unchecked(long i, local_unchecked_t *l)
16866+{
16867+ asm volatile(_ASM_ADD "%1,%0\n"
16868 : "+m" (l->a.counter)
16869 : "ir" (i));
16870 }
16871
16872 static inline void local_sub(long i, local_t *l)
16873 {
16874- asm volatile(_ASM_SUB "%1,%0"
16875+ asm volatile(_ASM_SUB "%1,%0\n"
16876+
16877+#ifdef CONFIG_PAX_REFCOUNT
16878+ "jno 0f\n"
16879+ _ASM_ADD "%1,%0\n"
16880+ "int $4\n0:\n"
16881+ _ASM_EXTABLE(0b, 0b)
16882+#endif
16883+
16884+ : "+m" (l->a.counter)
16885+ : "ir" (i));
16886+}
16887+
16888+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16889+{
16890+ asm volatile(_ASM_SUB "%1,%0\n"
16891 : "+m" (l->a.counter)
16892 : "ir" (i));
16893 }
16894@@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
16895 */
16896 static inline int local_sub_and_test(long i, local_t *l)
16897 {
16898- GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
16899+ GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
16900 }
16901
16902 /**
16903@@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
16904 */
16905 static inline int local_dec_and_test(local_t *l)
16906 {
16907- GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
16908+ GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
16909 }
16910
16911 /**
16912@@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
16913 */
16914 static inline int local_inc_and_test(local_t *l)
16915 {
16916- GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
16917+ GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
16918 }
16919
16920 /**
16921@@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
16922 */
16923 static inline int local_add_negative(long i, local_t *l)
16924 {
16925- GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
16926+ GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
16927 }
16928
16929 /**
16930@@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
16931 static inline long local_add_return(long i, local_t *l)
16932 {
16933 long __i = i;
16934+ asm volatile(_ASM_XADD "%0, %1\n"
16935+
16936+#ifdef CONFIG_PAX_REFCOUNT
16937+ "jno 0f\n"
16938+ _ASM_MOV "%0,%1\n"
16939+ "int $4\n0:\n"
16940+ _ASM_EXTABLE(0b, 0b)
16941+#endif
16942+
16943+ : "+r" (i), "+m" (l->a.counter)
16944+ : : "memory");
16945+ return i + __i;
16946+}
16947+
16948+/**
16949+ * local_add_return_unchecked - add and return
16950+ * @i: integer value to add
16951+ * @l: pointer to type local_unchecked_t
16952+ *
16953+ * Atomically adds @i to @l and returns @i + @l
16954+ */
16955+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
16956+{
16957+ long __i = i;
16958 asm volatile(_ASM_XADD "%0, %1;"
16959 : "+r" (i), "+m" (l->a.counter)
16960 : : "memory");
16961@@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
16962
16963 #define local_cmpxchg(l, o, n) \
16964 (cmpxchg_local(&((l)->a.counter), (o), (n)))
16965+#define local_cmpxchg_unchecked(l, o, n) \
16966+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
16967 /* Always has a lock prefix */
16968 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
16969
16970diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
16971new file mode 100644
16972index 0000000..2bfd3ba
16973--- /dev/null
16974+++ b/arch/x86/include/asm/mman.h
16975@@ -0,0 +1,15 @@
16976+#ifndef _X86_MMAN_H
16977+#define _X86_MMAN_H
16978+
16979+#include <uapi/asm/mman.h>
16980+
16981+#ifdef __KERNEL__
16982+#ifndef __ASSEMBLY__
16983+#ifdef CONFIG_X86_32
16984+#define arch_mmap_check i386_mmap_check
16985+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
16986+#endif
16987+#endif
16988+#endif
16989+
16990+#endif /* X86_MMAN_H */
16991diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
16992index 5f55e69..e20bfb1 100644
16993--- a/arch/x86/include/asm/mmu.h
16994+++ b/arch/x86/include/asm/mmu.h
16995@@ -9,7 +9,7 @@
16996 * we put the segment information here.
16997 */
16998 typedef struct {
16999- void *ldt;
17000+ struct desc_struct *ldt;
17001 int size;
17002
17003 #ifdef CONFIG_X86_64
17004@@ -18,7 +18,19 @@ typedef struct {
17005 #endif
17006
17007 struct mutex lock;
17008- void *vdso;
17009+ unsigned long vdso;
17010+
17011+#ifdef CONFIG_X86_32
17012+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17013+ unsigned long user_cs_base;
17014+ unsigned long user_cs_limit;
17015+
17016+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17017+ cpumask_t cpu_user_cs_mask;
17018+#endif
17019+
17020+#endif
17021+#endif
17022 } mm_context_t;
17023
17024 #ifdef CONFIG_SMP
17025diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17026index be12c53..4d24039 100644
17027--- a/arch/x86/include/asm/mmu_context.h
17028+++ b/arch/x86/include/asm/mmu_context.h
17029@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
17030
17031 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17032 {
17033+
17034+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17035+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
17036+ unsigned int i;
17037+ pgd_t *pgd;
17038+
17039+ pax_open_kernel();
17040+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
17041+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17042+ set_pgd_batched(pgd+i, native_make_pgd(0));
17043+ pax_close_kernel();
17044+ }
17045+#endif
17046+
17047 #ifdef CONFIG_SMP
17048 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17049 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17050@@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17051 struct task_struct *tsk)
17052 {
17053 unsigned cpu = smp_processor_id();
17054+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17055+ int tlbstate = TLBSTATE_OK;
17056+#endif
17057
17058 if (likely(prev != next)) {
17059 #ifdef CONFIG_SMP
17060+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17061+ tlbstate = this_cpu_read(cpu_tlbstate.state);
17062+#endif
17063 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17064 this_cpu_write(cpu_tlbstate.active_mm, next);
17065 #endif
17066 cpumask_set_cpu(cpu, mm_cpumask(next));
17067
17068 /* Re-load page tables */
17069+#ifdef CONFIG_PAX_PER_CPU_PGD
17070+ pax_open_kernel();
17071+
17072+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17073+ if (static_cpu_has(X86_FEATURE_PCID))
17074+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17075+ else
17076+#endif
17077+
17078+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17079+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17080+ pax_close_kernel();
17081+ 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));
17082+
17083+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17084+ if (static_cpu_has(X86_FEATURE_PCID)) {
17085+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17086+ u64 descriptor[2];
17087+ descriptor[0] = PCID_USER;
17088+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17089+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17090+ descriptor[0] = PCID_KERNEL;
17091+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17092+ }
17093+ } else {
17094+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17095+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17096+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17097+ else
17098+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17099+ }
17100+ } else
17101+#endif
17102+
17103+ load_cr3(get_cpu_pgd(cpu, kernel));
17104+#else
17105 load_cr3(next->pgd);
17106+#endif
17107
17108 /* Stop flush ipis for the previous mm */
17109 cpumask_clear_cpu(cpu, mm_cpumask(prev));
17110@@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17111 /* Load the LDT, if the LDT is different: */
17112 if (unlikely(prev->context.ldt != next->context.ldt))
17113 load_LDT_nolock(&next->context);
17114+
17115+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17116+ if (!(__supported_pte_mask & _PAGE_NX)) {
17117+ smp_mb__before_clear_bit();
17118+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17119+ smp_mb__after_clear_bit();
17120+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17121+ }
17122+#endif
17123+
17124+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17125+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17126+ prev->context.user_cs_limit != next->context.user_cs_limit))
17127+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17128+#ifdef CONFIG_SMP
17129+ else if (unlikely(tlbstate != TLBSTATE_OK))
17130+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17131+#endif
17132+#endif
17133+
17134 }
17135+ else {
17136+
17137+#ifdef CONFIG_PAX_PER_CPU_PGD
17138+ pax_open_kernel();
17139+
17140+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17141+ if (static_cpu_has(X86_FEATURE_PCID))
17142+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17143+ else
17144+#endif
17145+
17146+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17147+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17148+ pax_close_kernel();
17149+ 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));
17150+
17151+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17152+ if (static_cpu_has(X86_FEATURE_PCID)) {
17153+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17154+ u64 descriptor[2];
17155+ descriptor[0] = PCID_USER;
17156+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17157+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17158+ descriptor[0] = PCID_KERNEL;
17159+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17160+ }
17161+ } else {
17162+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17163+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17164+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17165+ else
17166+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17167+ }
17168+ } else
17169+#endif
17170+
17171+ load_cr3(get_cpu_pgd(cpu, kernel));
17172+#endif
17173+
17174 #ifdef CONFIG_SMP
17175- else {
17176 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17177 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17178
17179@@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17180 * tlb flush IPI delivery. We must reload CR3
17181 * to make sure to use no freed page tables.
17182 */
17183+
17184+#ifndef CONFIG_PAX_PER_CPU_PGD
17185 load_cr3(next->pgd);
17186+#endif
17187+
17188 load_LDT_nolock(&next->context);
17189+
17190+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17191+ if (!(__supported_pte_mask & _PAGE_NX))
17192+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17193+#endif
17194+
17195+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17196+#ifdef CONFIG_PAX_PAGEEXEC
17197+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17198+#endif
17199+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17200+#endif
17201+
17202 }
17203+#endif
17204 }
17205-#endif
17206 }
17207
17208 #define activate_mm(prev, next) \
17209diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17210index e3b7819..b257c64 100644
17211--- a/arch/x86/include/asm/module.h
17212+++ b/arch/x86/include/asm/module.h
17213@@ -5,6 +5,7 @@
17214
17215 #ifdef CONFIG_X86_64
17216 /* X86_64 does not define MODULE_PROC_FAMILY */
17217+#define MODULE_PROC_FAMILY ""
17218 #elif defined CONFIG_M486
17219 #define MODULE_PROC_FAMILY "486 "
17220 #elif defined CONFIG_M586
17221@@ -57,8 +58,20 @@
17222 #error unknown processor family
17223 #endif
17224
17225-#ifdef CONFIG_X86_32
17226-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17227+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17228+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17229+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17230+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17231+#else
17232+#define MODULE_PAX_KERNEXEC ""
17233 #endif
17234
17235+#ifdef CONFIG_PAX_MEMORY_UDEREF
17236+#define MODULE_PAX_UDEREF "UDEREF "
17237+#else
17238+#define MODULE_PAX_UDEREF ""
17239+#endif
17240+
17241+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17242+
17243 #endif /* _ASM_X86_MODULE_H */
17244diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17245index 86f9301..b365cda 100644
17246--- a/arch/x86/include/asm/nmi.h
17247+++ b/arch/x86/include/asm/nmi.h
17248@@ -40,11 +40,11 @@ struct nmiaction {
17249 nmi_handler_t handler;
17250 unsigned long flags;
17251 const char *name;
17252-};
17253+} __do_const;
17254
17255 #define register_nmi_handler(t, fn, fg, n, init...) \
17256 ({ \
17257- static struct nmiaction init fn##_na = { \
17258+ static const struct nmiaction init fn##_na = { \
17259 .handler = (fn), \
17260 .name = (n), \
17261 .flags = (fg), \
17262@@ -52,7 +52,7 @@ struct nmiaction {
17263 __register_nmi_handler((t), &fn##_na); \
17264 })
17265
17266-int __register_nmi_handler(unsigned int, struct nmiaction *);
17267+int __register_nmi_handler(unsigned int, const struct nmiaction *);
17268
17269 void unregister_nmi_handler(unsigned int, const char *);
17270
17271diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17272index c878924..21f4889 100644
17273--- a/arch/x86/include/asm/page.h
17274+++ b/arch/x86/include/asm/page.h
17275@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17276 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17277
17278 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17279+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17280
17281 #define __boot_va(x) __va(x)
17282 #define __boot_pa(x) __pa(x)
17283diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17284index 0f1ddee..e2fc3d1 100644
17285--- a/arch/x86/include/asm/page_64.h
17286+++ b/arch/x86/include/asm/page_64.h
17287@@ -7,9 +7,9 @@
17288
17289 /* duplicated to the one in bootmem.h */
17290 extern unsigned long max_pfn;
17291-extern unsigned long phys_base;
17292+extern const unsigned long phys_base;
17293
17294-static inline unsigned long __phys_addr_nodebug(unsigned long x)
17295+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17296 {
17297 unsigned long y = x - __START_KERNEL_map;
17298
17299diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17300index 401f350..dee5d13 100644
17301--- a/arch/x86/include/asm/paravirt.h
17302+++ b/arch/x86/include/asm/paravirt.h
17303@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17304 return (pmd_t) { ret };
17305 }
17306
17307-static inline pmdval_t pmd_val(pmd_t pmd)
17308+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17309 {
17310 pmdval_t ret;
17311
17312@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17313 val);
17314 }
17315
17316+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17317+{
17318+ pgdval_t val = native_pgd_val(pgd);
17319+
17320+ if (sizeof(pgdval_t) > sizeof(long))
17321+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17322+ val, (u64)val >> 32);
17323+ else
17324+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17325+ val);
17326+}
17327+
17328 static inline void pgd_clear(pgd_t *pgdp)
17329 {
17330 set_pgd(pgdp, __pgd(0));
17331@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17332 pv_mmu_ops.set_fixmap(idx, phys, flags);
17333 }
17334
17335+#ifdef CONFIG_PAX_KERNEXEC
17336+static inline unsigned long pax_open_kernel(void)
17337+{
17338+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17339+}
17340+
17341+static inline unsigned long pax_close_kernel(void)
17342+{
17343+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17344+}
17345+#else
17346+static inline unsigned long pax_open_kernel(void) { return 0; }
17347+static inline unsigned long pax_close_kernel(void) { return 0; }
17348+#endif
17349+
17350 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17351
17352 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17353@@ -906,7 +933,7 @@ extern void default_banner(void);
17354
17355 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17356 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17357-#define PARA_INDIRECT(addr) *%cs:addr
17358+#define PARA_INDIRECT(addr) *%ss:addr
17359 #endif
17360
17361 #define INTERRUPT_RETURN \
17362@@ -981,6 +1008,21 @@ extern void default_banner(void);
17363 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17364 CLBR_NONE, \
17365 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17366+
17367+#define GET_CR0_INTO_RDI \
17368+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17369+ mov %rax,%rdi
17370+
17371+#define SET_RDI_INTO_CR0 \
17372+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17373+
17374+#define GET_CR3_INTO_RDI \
17375+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17376+ mov %rax,%rdi
17377+
17378+#define SET_RDI_INTO_CR3 \
17379+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17380+
17381 #endif /* CONFIG_X86_32 */
17382
17383 #endif /* __ASSEMBLY__ */
17384diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17385index aab8f67..0fb0ee4 100644
17386--- a/arch/x86/include/asm/paravirt_types.h
17387+++ b/arch/x86/include/asm/paravirt_types.h
17388@@ -84,7 +84,7 @@ struct pv_init_ops {
17389 */
17390 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17391 unsigned long addr, unsigned len);
17392-};
17393+} __no_const __no_randomize_layout;
17394
17395
17396 struct pv_lazy_ops {
17397@@ -92,13 +92,13 @@ struct pv_lazy_ops {
17398 void (*enter)(void);
17399 void (*leave)(void);
17400 void (*flush)(void);
17401-};
17402+} __no_randomize_layout;
17403
17404 struct pv_time_ops {
17405 unsigned long long (*sched_clock)(void);
17406 unsigned long long (*steal_clock)(int cpu);
17407 unsigned long (*get_tsc_khz)(void);
17408-};
17409+} __no_const __no_randomize_layout;
17410
17411 struct pv_cpu_ops {
17412 /* hooks for various privileged instructions */
17413@@ -192,7 +192,7 @@ struct pv_cpu_ops {
17414
17415 void (*start_context_switch)(struct task_struct *prev);
17416 void (*end_context_switch)(struct task_struct *next);
17417-};
17418+} __no_const __no_randomize_layout;
17419
17420 struct pv_irq_ops {
17421 /*
17422@@ -215,7 +215,7 @@ struct pv_irq_ops {
17423 #ifdef CONFIG_X86_64
17424 void (*adjust_exception_frame)(void);
17425 #endif
17426-};
17427+} __no_randomize_layout;
17428
17429 struct pv_apic_ops {
17430 #ifdef CONFIG_X86_LOCAL_APIC
17431@@ -223,7 +223,7 @@ struct pv_apic_ops {
17432 unsigned long start_eip,
17433 unsigned long start_esp);
17434 #endif
17435-};
17436+} __no_const __no_randomize_layout;
17437
17438 struct pv_mmu_ops {
17439 unsigned long (*read_cr2)(void);
17440@@ -313,6 +313,7 @@ struct pv_mmu_ops {
17441 struct paravirt_callee_save make_pud;
17442
17443 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17444+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17445 #endif /* PAGETABLE_LEVELS == 4 */
17446 #endif /* PAGETABLE_LEVELS >= 3 */
17447
17448@@ -324,7 +325,13 @@ struct pv_mmu_ops {
17449 an mfn. We can tell which is which from the index. */
17450 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17451 phys_addr_t phys, pgprot_t flags);
17452-};
17453+
17454+#ifdef CONFIG_PAX_KERNEXEC
17455+ unsigned long (*pax_open_kernel)(void);
17456+ unsigned long (*pax_close_kernel)(void);
17457+#endif
17458+
17459+} __no_randomize_layout;
17460
17461 struct arch_spinlock;
17462 #ifdef CONFIG_SMP
17463@@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17464 struct pv_lock_ops {
17465 struct paravirt_callee_save lock_spinning;
17466 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17467-};
17468+} __no_randomize_layout;
17469
17470 /* This contains all the paravirt structures: we get a convenient
17471 * number for each function using the offset which we use to indicate
17472- * what to patch. */
17473+ * what to patch.
17474+ * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17475+ */
17476+
17477 struct paravirt_patch_template {
17478 struct pv_init_ops pv_init_ops;
17479 struct pv_time_ops pv_time_ops;
17480@@ -349,7 +359,7 @@ struct paravirt_patch_template {
17481 struct pv_apic_ops pv_apic_ops;
17482 struct pv_mmu_ops pv_mmu_ops;
17483 struct pv_lock_ops pv_lock_ops;
17484-};
17485+} __no_randomize_layout;
17486
17487 extern struct pv_info pv_info;
17488 extern struct pv_init_ops pv_init_ops;
17489diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17490index c4412e9..90e88c5 100644
17491--- a/arch/x86/include/asm/pgalloc.h
17492+++ b/arch/x86/include/asm/pgalloc.h
17493@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17494 pmd_t *pmd, pte_t *pte)
17495 {
17496 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17497+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17498+}
17499+
17500+static inline void pmd_populate_user(struct mm_struct *mm,
17501+ pmd_t *pmd, pte_t *pte)
17502+{
17503+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17504 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17505 }
17506
17507@@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17508
17509 #ifdef CONFIG_X86_PAE
17510 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17511+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17512+{
17513+ pud_populate(mm, pudp, pmd);
17514+}
17515 #else /* !CONFIG_X86_PAE */
17516 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17517 {
17518 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17519 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17520 }
17521+
17522+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17523+{
17524+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17525+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17526+}
17527 #endif /* CONFIG_X86_PAE */
17528
17529 #if PAGETABLE_LEVELS > 3
17530@@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17531 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17532 }
17533
17534+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17535+{
17536+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17537+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17538+}
17539+
17540 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17541 {
17542 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17543diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17544index 3bf2dd0..23d2a9f 100644
17545--- a/arch/x86/include/asm/pgtable-2level.h
17546+++ b/arch/x86/include/asm/pgtable-2level.h
17547@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17548
17549 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17550 {
17551+ pax_open_kernel();
17552 *pmdp = pmd;
17553+ pax_close_kernel();
17554 }
17555
17556 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17557diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17558index 81bb91b..9392125 100644
17559--- a/arch/x86/include/asm/pgtable-3level.h
17560+++ b/arch/x86/include/asm/pgtable-3level.h
17561@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17562
17563 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17564 {
17565+ pax_open_kernel();
17566 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17567+ pax_close_kernel();
17568 }
17569
17570 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17571 {
17572+ pax_open_kernel();
17573 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17574+ pax_close_kernel();
17575 }
17576
17577 /*
17578diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17579index bbc8b12..f228861 100644
17580--- a/arch/x86/include/asm/pgtable.h
17581+++ b/arch/x86/include/asm/pgtable.h
17582@@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17583
17584 #ifndef __PAGETABLE_PUD_FOLDED
17585 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17586+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17587 #define pgd_clear(pgd) native_pgd_clear(pgd)
17588 #endif
17589
17590@@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17591
17592 #define arch_end_context_switch(prev) do {} while(0)
17593
17594+#define pax_open_kernel() native_pax_open_kernel()
17595+#define pax_close_kernel() native_pax_close_kernel()
17596 #endif /* CONFIG_PARAVIRT */
17597
17598+#define __HAVE_ARCH_PAX_OPEN_KERNEL
17599+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17600+
17601+#ifdef CONFIG_PAX_KERNEXEC
17602+static inline unsigned long native_pax_open_kernel(void)
17603+{
17604+ unsigned long cr0;
17605+
17606+ preempt_disable();
17607+ barrier();
17608+ cr0 = read_cr0() ^ X86_CR0_WP;
17609+ BUG_ON(cr0 & X86_CR0_WP);
17610+ write_cr0(cr0);
17611+ return cr0 ^ X86_CR0_WP;
17612+}
17613+
17614+static inline unsigned long native_pax_close_kernel(void)
17615+{
17616+ unsigned long cr0;
17617+
17618+ cr0 = read_cr0() ^ X86_CR0_WP;
17619+ BUG_ON(!(cr0 & X86_CR0_WP));
17620+ write_cr0(cr0);
17621+ barrier();
17622+ preempt_enable_no_resched();
17623+ return cr0 ^ X86_CR0_WP;
17624+}
17625+#else
17626+static inline unsigned long native_pax_open_kernel(void) { return 0; }
17627+static inline unsigned long native_pax_close_kernel(void) { return 0; }
17628+#endif
17629+
17630 /*
17631 * The following only work if pte_present() is true.
17632 * Undefined behaviour if not..
17633 */
17634+static inline int pte_user(pte_t pte)
17635+{
17636+ return pte_val(pte) & _PAGE_USER;
17637+}
17638+
17639 static inline int pte_dirty(pte_t pte)
17640 {
17641 return pte_flags(pte) & _PAGE_DIRTY;
17642@@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17643 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17644 }
17645
17646+static inline unsigned long pgd_pfn(pgd_t pgd)
17647+{
17648+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17649+}
17650+
17651 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17652
17653 static inline int pmd_large(pmd_t pte)
17654@@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17655 return pte_clear_flags(pte, _PAGE_RW);
17656 }
17657
17658+static inline pte_t pte_mkread(pte_t pte)
17659+{
17660+ return __pte(pte_val(pte) | _PAGE_USER);
17661+}
17662+
17663 static inline pte_t pte_mkexec(pte_t pte)
17664 {
17665- return pte_clear_flags(pte, _PAGE_NX);
17666+#ifdef CONFIG_X86_PAE
17667+ if (__supported_pte_mask & _PAGE_NX)
17668+ return pte_clear_flags(pte, _PAGE_NX);
17669+ else
17670+#endif
17671+ return pte_set_flags(pte, _PAGE_USER);
17672+}
17673+
17674+static inline pte_t pte_exprotect(pte_t pte)
17675+{
17676+#ifdef CONFIG_X86_PAE
17677+ if (__supported_pte_mask & _PAGE_NX)
17678+ return pte_set_flags(pte, _PAGE_NX);
17679+ else
17680+#endif
17681+ return pte_clear_flags(pte, _PAGE_USER);
17682 }
17683
17684 static inline pte_t pte_mkdirty(pte_t pte)
17685@@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17686 #endif
17687
17688 #ifndef __ASSEMBLY__
17689+
17690+#ifdef CONFIG_PAX_PER_CPU_PGD
17691+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17692+enum cpu_pgd_type {kernel = 0, user = 1};
17693+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17694+{
17695+ return cpu_pgd[cpu][type];
17696+}
17697+#endif
17698+
17699 #include <linux/mm_types.h>
17700 #include <linux/mmdebug.h>
17701 #include <linux/log2.h>
17702@@ -570,7 +645,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17703 * Currently stuck as a macro due to indirect forward reference to
17704 * linux/mmzone.h's __section_mem_map_addr() definition:
17705 */
17706-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17707+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17708
17709 /* Find an entry in the second-level page table.. */
17710 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17711@@ -610,7 +685,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17712 * Currently stuck as a macro due to indirect forward reference to
17713 * linux/mmzone.h's __section_mem_map_addr() definition:
17714 */
17715-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17716+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17717
17718 /* to find an entry in a page-table-directory. */
17719 static inline unsigned long pud_index(unsigned long address)
17720@@ -625,7 +700,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17721
17722 static inline int pgd_bad(pgd_t pgd)
17723 {
17724- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17725+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17726 }
17727
17728 static inline int pgd_none(pgd_t pgd)
17729@@ -648,7 +723,12 @@ static inline int pgd_none(pgd_t pgd)
17730 * pgd_offset() returns a (pgd_t *)
17731 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17732 */
17733-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17734+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17735+
17736+#ifdef CONFIG_PAX_PER_CPU_PGD
17737+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17738+#endif
17739+
17740 /*
17741 * a shortcut which implies the use of the kernel's pgd, instead
17742 * of a process's
17743@@ -659,6 +739,23 @@ static inline int pgd_none(pgd_t pgd)
17744 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17745 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17746
17747+#ifdef CONFIG_X86_32
17748+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17749+#else
17750+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17751+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17752+
17753+#ifdef CONFIG_PAX_MEMORY_UDEREF
17754+#ifdef __ASSEMBLY__
17755+#define pax_user_shadow_base pax_user_shadow_base(%rip)
17756+#else
17757+extern unsigned long pax_user_shadow_base;
17758+extern pgdval_t clone_pgd_mask;
17759+#endif
17760+#endif
17761+
17762+#endif
17763+
17764 #ifndef __ASSEMBLY__
17765
17766 extern int direct_gbpages;
17767@@ -825,11 +922,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17768 * dst and src can be on the same page, but the range must not overlap,
17769 * and must not cross a page boundary.
17770 */
17771-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17772+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17773 {
17774- memcpy(dst, src, count * sizeof(pgd_t));
17775+ pax_open_kernel();
17776+ while (count--)
17777+ *dst++ = *src++;
17778+ pax_close_kernel();
17779 }
17780
17781+#ifdef CONFIG_PAX_PER_CPU_PGD
17782+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17783+#endif
17784+
17785+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17786+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17787+#else
17788+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17789+#endif
17790+
17791 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17792 static inline int page_level_shift(enum pg_level level)
17793 {
17794diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17795index 9ee3221..b979c6b 100644
17796--- a/arch/x86/include/asm/pgtable_32.h
17797+++ b/arch/x86/include/asm/pgtable_32.h
17798@@ -25,9 +25,6 @@
17799 struct mm_struct;
17800 struct vm_area_struct;
17801
17802-extern pgd_t swapper_pg_dir[1024];
17803-extern pgd_t initial_page_table[1024];
17804-
17805 static inline void pgtable_cache_init(void) { }
17806 static inline void check_pgt_cache(void) { }
17807 void paging_init(void);
17808@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17809 # include <asm/pgtable-2level.h>
17810 #endif
17811
17812+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17813+extern pgd_t initial_page_table[PTRS_PER_PGD];
17814+#ifdef CONFIG_X86_PAE
17815+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17816+#endif
17817+
17818 #if defined(CONFIG_HIGHPTE)
17819 #define pte_offset_map(dir, address) \
17820 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17821@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17822 /* Clear a kernel PTE and flush it from the TLB */
17823 #define kpte_clear_flush(ptep, vaddr) \
17824 do { \
17825+ pax_open_kernel(); \
17826 pte_clear(&init_mm, (vaddr), (ptep)); \
17827+ pax_close_kernel(); \
17828 __flush_tlb_one((vaddr)); \
17829 } while (0)
17830
17831 #endif /* !__ASSEMBLY__ */
17832
17833+#define HAVE_ARCH_UNMAPPED_AREA
17834+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17835+
17836 /*
17837 * kern_addr_valid() is (1) for FLATMEM and (0) for
17838 * SPARSEMEM and DISCONTIGMEM
17839diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17840index ed5903b..c7fe163 100644
17841--- a/arch/x86/include/asm/pgtable_32_types.h
17842+++ b/arch/x86/include/asm/pgtable_32_types.h
17843@@ -8,7 +8,7 @@
17844 */
17845 #ifdef CONFIG_X86_PAE
17846 # include <asm/pgtable-3level_types.h>
17847-# define PMD_SIZE (1UL << PMD_SHIFT)
17848+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17849 # define PMD_MASK (~(PMD_SIZE - 1))
17850 #else
17851 # include <asm/pgtable-2level_types.h>
17852@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17853 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17854 #endif
17855
17856+#ifdef CONFIG_PAX_KERNEXEC
17857+#ifndef __ASSEMBLY__
17858+extern unsigned char MODULES_EXEC_VADDR[];
17859+extern unsigned char MODULES_EXEC_END[];
17860+#endif
17861+#include <asm/boot.h>
17862+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17863+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17864+#else
17865+#define ktla_ktva(addr) (addr)
17866+#define ktva_ktla(addr) (addr)
17867+#endif
17868+
17869 #define MODULES_VADDR VMALLOC_START
17870 #define MODULES_END VMALLOC_END
17871 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
17872diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
17873index e22c1db..23a625a 100644
17874--- a/arch/x86/include/asm/pgtable_64.h
17875+++ b/arch/x86/include/asm/pgtable_64.h
17876@@ -16,10 +16,14 @@
17877
17878 extern pud_t level3_kernel_pgt[512];
17879 extern pud_t level3_ident_pgt[512];
17880+extern pud_t level3_vmalloc_start_pgt[512];
17881+extern pud_t level3_vmalloc_end_pgt[512];
17882+extern pud_t level3_vmemmap_pgt[512];
17883+extern pud_t level2_vmemmap_pgt[512];
17884 extern pmd_t level2_kernel_pgt[512];
17885 extern pmd_t level2_fixmap_pgt[512];
17886-extern pmd_t level2_ident_pgt[512];
17887-extern pgd_t init_level4_pgt[];
17888+extern pmd_t level2_ident_pgt[512*2];
17889+extern pgd_t init_level4_pgt[512];
17890
17891 #define swapper_pg_dir init_level4_pgt
17892
17893@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17894
17895 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17896 {
17897+ pax_open_kernel();
17898 *pmdp = pmd;
17899+ pax_close_kernel();
17900 }
17901
17902 static inline void native_pmd_clear(pmd_t *pmd)
17903@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
17904
17905 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17906 {
17907+ pax_open_kernel();
17908 *pudp = pud;
17909+ pax_close_kernel();
17910 }
17911
17912 static inline void native_pud_clear(pud_t *pud)
17913@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
17914
17915 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
17916 {
17917+ pax_open_kernel();
17918+ *pgdp = pgd;
17919+ pax_close_kernel();
17920+}
17921+
17922+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17923+{
17924 *pgdp = pgd;
17925 }
17926
17927diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
17928index 2d88344..4679fc3 100644
17929--- a/arch/x86/include/asm/pgtable_64_types.h
17930+++ b/arch/x86/include/asm/pgtable_64_types.h
17931@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
17932 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
17933 #define MODULES_END _AC(0xffffffffff000000, UL)
17934 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
17935+#define MODULES_EXEC_VADDR MODULES_VADDR
17936+#define MODULES_EXEC_END MODULES_END
17937+
17938+#define ktla_ktva(addr) (addr)
17939+#define ktva_ktla(addr) (addr)
17940
17941 #define EARLY_DYNAMIC_PAGE_TABLES 64
17942
17943diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
17944index 840c127..a8f297b 100644
17945--- a/arch/x86/include/asm/pgtable_types.h
17946+++ b/arch/x86/include/asm/pgtable_types.h
17947@@ -16,13 +16,12 @@
17948 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
17949 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
17950 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
17951-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
17952+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
17953 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
17954 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
17955 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
17956-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
17957-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
17958-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
17959+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
17960+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
17961 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
17962
17963 /* If _PAGE_BIT_PRESENT is clear, we use these: */
17964@@ -40,7 +39,6 @@
17965 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
17966 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
17967 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
17968-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
17969 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
17970 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
17971 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
17972@@ -87,8 +85,10 @@
17973
17974 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
17975 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
17976-#else
17977+#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
17978 #define _PAGE_NX (_AT(pteval_t, 0))
17979+#else
17980+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
17981 #endif
17982
17983 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
17984@@ -147,6 +147,9 @@
17985 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
17986 _PAGE_ACCESSED)
17987
17988+#define PAGE_READONLY_NOEXEC PAGE_READONLY
17989+#define PAGE_SHARED_NOEXEC PAGE_SHARED
17990+
17991 #define __PAGE_KERNEL_EXEC \
17992 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
17993 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
17994@@ -157,7 +160,7 @@
17995 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
17996 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
17997 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
17998-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
17999+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18000 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18001 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18002 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18003@@ -219,8 +222,8 @@
18004 * bits are combined, this will alow user to access the high address mapped
18005 * VDSO in the presence of CONFIG_COMPAT_VDSO
18006 */
18007-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18008-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
18009+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18010+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18011 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18012 #endif
18013
18014@@ -258,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18015 {
18016 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18017 }
18018+#endif
18019
18020+#if PAGETABLE_LEVELS == 3
18021+#include <asm-generic/pgtable-nopud.h>
18022+#endif
18023+
18024+#if PAGETABLE_LEVELS == 2
18025+#include <asm-generic/pgtable-nopmd.h>
18026+#endif
18027+
18028+#ifndef __ASSEMBLY__
18029 #if PAGETABLE_LEVELS > 3
18030 typedef struct { pudval_t pud; } pud_t;
18031
18032@@ -272,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18033 return pud.pud;
18034 }
18035 #else
18036-#include <asm-generic/pgtable-nopud.h>
18037-
18038 static inline pudval_t native_pud_val(pud_t pud)
18039 {
18040 return native_pgd_val(pud.pgd);
18041@@ -293,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18042 return pmd.pmd;
18043 }
18044 #else
18045-#include <asm-generic/pgtable-nopmd.h>
18046-
18047 static inline pmdval_t native_pmd_val(pmd_t pmd)
18048 {
18049 return native_pgd_val(pmd.pud.pgd);
18050@@ -334,7 +343,6 @@ typedef struct page *pgtable_t;
18051
18052 extern pteval_t __supported_pte_mask;
18053 extern void set_nx(void);
18054-extern int nx_enabled;
18055
18056 #define pgprot_writecombine pgprot_writecombine
18057 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18058diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18059index c8b0519..fd29e73 100644
18060--- a/arch/x86/include/asm/preempt.h
18061+++ b/arch/x86/include/asm/preempt.h
18062@@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18063 */
18064 static __always_inline bool __preempt_count_dec_and_test(void)
18065 {
18066- GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18067+ GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18068 }
18069
18070 /*
18071diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18072index 7b034a4..4fe3e3f 100644
18073--- a/arch/x86/include/asm/processor.h
18074+++ b/arch/x86/include/asm/processor.h
18075@@ -128,7 +128,7 @@ struct cpuinfo_x86 {
18076 /* Index into per_cpu list: */
18077 u16 cpu_index;
18078 u32 microcode;
18079-} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18080+} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18081
18082 #define X86_VENDOR_INTEL 0
18083 #define X86_VENDOR_CYRIX 1
18084@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18085 : "memory");
18086 }
18087
18088+/* invpcid (%rdx),%rax */
18089+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18090+
18091+#define INVPCID_SINGLE_ADDRESS 0UL
18092+#define INVPCID_SINGLE_CONTEXT 1UL
18093+#define INVPCID_ALL_GLOBAL 2UL
18094+#define INVPCID_ALL_MONGLOBAL 3UL
18095+
18096+#define PCID_KERNEL 0UL
18097+#define PCID_USER 1UL
18098+#define PCID_NOFLUSH (1UL << 63)
18099+
18100 static inline void load_cr3(pgd_t *pgdir)
18101 {
18102- write_cr3(__pa(pgdir));
18103+ write_cr3(__pa(pgdir) | PCID_KERNEL);
18104 }
18105
18106 #ifdef CONFIG_X86_32
18107@@ -283,7 +295,7 @@ struct tss_struct {
18108
18109 } ____cacheline_aligned;
18110
18111-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18112+extern struct tss_struct init_tss[NR_CPUS];
18113
18114 /*
18115 * Save the original ist values for checking stack pointers during debugging
18116@@ -453,6 +465,7 @@ struct thread_struct {
18117 unsigned short ds;
18118 unsigned short fsindex;
18119 unsigned short gsindex;
18120+ unsigned short ss;
18121 #endif
18122 #ifdef CONFIG_X86_32
18123 unsigned long ip;
18124@@ -562,29 +575,8 @@ static inline void load_sp0(struct tss_struct *tss,
18125 extern unsigned long mmu_cr4_features;
18126 extern u32 *trampoline_cr4_features;
18127
18128-static inline void set_in_cr4(unsigned long mask)
18129-{
18130- unsigned long cr4;
18131-
18132- mmu_cr4_features |= mask;
18133- if (trampoline_cr4_features)
18134- *trampoline_cr4_features = mmu_cr4_features;
18135- cr4 = read_cr4();
18136- cr4 |= mask;
18137- write_cr4(cr4);
18138-}
18139-
18140-static inline void clear_in_cr4(unsigned long mask)
18141-{
18142- unsigned long cr4;
18143-
18144- mmu_cr4_features &= ~mask;
18145- if (trampoline_cr4_features)
18146- *trampoline_cr4_features = mmu_cr4_features;
18147- cr4 = read_cr4();
18148- cr4 &= ~mask;
18149- write_cr4(cr4);
18150-}
18151+extern void set_in_cr4(unsigned long mask);
18152+extern void clear_in_cr4(unsigned long mask);
18153
18154 typedef struct {
18155 unsigned long seg;
18156@@ -833,11 +825,18 @@ static inline void spin_lock_prefetch(const void *x)
18157 */
18158 #define TASK_SIZE PAGE_OFFSET
18159 #define TASK_SIZE_MAX TASK_SIZE
18160+
18161+#ifdef CONFIG_PAX_SEGMEXEC
18162+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18163+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18164+#else
18165 #define STACK_TOP TASK_SIZE
18166-#define STACK_TOP_MAX STACK_TOP
18167+#endif
18168+
18169+#define STACK_TOP_MAX TASK_SIZE
18170
18171 #define INIT_THREAD { \
18172- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18173+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18174 .vm86_info = NULL, \
18175 .sysenter_cs = __KERNEL_CS, \
18176 .io_bitmap_ptr = NULL, \
18177@@ -851,7 +850,7 @@ static inline void spin_lock_prefetch(const void *x)
18178 */
18179 #define INIT_TSS { \
18180 .x86_tss = { \
18181- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18182+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18183 .ss0 = __KERNEL_DS, \
18184 .ss1 = __KERNEL_CS, \
18185 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18186@@ -862,11 +861,7 @@ static inline void spin_lock_prefetch(const void *x)
18187 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18188
18189 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18190-#define KSTK_TOP(info) \
18191-({ \
18192- unsigned long *__ptr = (unsigned long *)(info); \
18193- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18194-})
18195+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18196
18197 /*
18198 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18199@@ -881,7 +876,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18200 #define task_pt_regs(task) \
18201 ({ \
18202 struct pt_regs *__regs__; \
18203- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18204+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18205 __regs__ - 1; \
18206 })
18207
18208@@ -891,13 +886,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18209 /*
18210 * User space process size. 47bits minus one guard page.
18211 */
18212-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18213+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18214
18215 /* This decides where the kernel will search for a free chunk of vm
18216 * space during mmap's.
18217 */
18218 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18219- 0xc0000000 : 0xFFFFe000)
18220+ 0xc0000000 : 0xFFFFf000)
18221
18222 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18223 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18224@@ -908,11 +903,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18225 #define STACK_TOP_MAX TASK_SIZE_MAX
18226
18227 #define INIT_THREAD { \
18228- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18229+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18230 }
18231
18232 #define INIT_TSS { \
18233- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18234+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18235 }
18236
18237 /*
18238@@ -940,6 +935,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18239 */
18240 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18241
18242+#ifdef CONFIG_PAX_SEGMEXEC
18243+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18244+#endif
18245+
18246 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18247
18248 /* Get/set a process' ability to use the timestamp counter instruction */
18249@@ -966,7 +965,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18250 return 0;
18251 }
18252
18253-extern unsigned long arch_align_stack(unsigned long sp);
18254+#define arch_align_stack(x) ((x) & ~0xfUL)
18255 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18256
18257 void default_idle(void);
18258@@ -976,6 +975,6 @@ bool xen_set_default_idle(void);
18259 #define xen_set_default_idle 0
18260 #endif
18261
18262-void stop_this_cpu(void *dummy);
18263+void stop_this_cpu(void *dummy) __noreturn;
18264 void df_debug(struct pt_regs *regs, long error_code);
18265 #endif /* _ASM_X86_PROCESSOR_H */
18266diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18267index 942a086..6c26446 100644
18268--- a/arch/x86/include/asm/ptrace.h
18269+++ b/arch/x86/include/asm/ptrace.h
18270@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18271 }
18272
18273 /*
18274- * user_mode_vm(regs) determines whether a register set came from user mode.
18275+ * user_mode(regs) determines whether a register set came from user mode.
18276 * This is true if V8086 mode was enabled OR if the register set was from
18277 * protected mode with RPL-3 CS value. This tricky test checks that with
18278 * one comparison. Many places in the kernel can bypass this full check
18279- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18280+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18281+ * be used.
18282 */
18283-static inline int user_mode(struct pt_regs *regs)
18284+static inline int user_mode_novm(struct pt_regs *regs)
18285 {
18286 #ifdef CONFIG_X86_32
18287 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18288 #else
18289- return !!(regs->cs & 3);
18290+ return !!(regs->cs & SEGMENT_RPL_MASK);
18291 #endif
18292 }
18293
18294-static inline int user_mode_vm(struct pt_regs *regs)
18295+static inline int user_mode(struct pt_regs *regs)
18296 {
18297 #ifdef CONFIG_X86_32
18298 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18299 USER_RPL;
18300 #else
18301- return user_mode(regs);
18302+ return user_mode_novm(regs);
18303 #endif
18304 }
18305
18306@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18307 #ifdef CONFIG_X86_64
18308 static inline bool user_64bit_mode(struct pt_regs *regs)
18309 {
18310+ unsigned long cs = regs->cs & 0xffff;
18311 #ifndef CONFIG_PARAVIRT
18312 /*
18313 * On non-paravirt systems, this is the only long mode CPL 3
18314 * selector. We do not allow long mode selectors in the LDT.
18315 */
18316- return regs->cs == __USER_CS;
18317+ return cs == __USER_CS;
18318 #else
18319 /* Headers are too twisted for this to go in paravirt.h. */
18320- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18321+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18322 #endif
18323 }
18324
18325@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18326 * Traps from the kernel do not save sp and ss.
18327 * Use the helper function to retrieve sp.
18328 */
18329- if (offset == offsetof(struct pt_regs, sp) &&
18330- regs->cs == __KERNEL_CS)
18331- return kernel_stack_pointer(regs);
18332+ if (offset == offsetof(struct pt_regs, sp)) {
18333+ unsigned long cs = regs->cs & 0xffff;
18334+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18335+ return kernel_stack_pointer(regs);
18336+ }
18337 #endif
18338 return *(unsigned long *)((unsigned long)regs + offset);
18339 }
18340diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18341index 9c6b890..5305f53 100644
18342--- a/arch/x86/include/asm/realmode.h
18343+++ b/arch/x86/include/asm/realmode.h
18344@@ -22,16 +22,14 @@ struct real_mode_header {
18345 #endif
18346 /* APM/BIOS reboot */
18347 u32 machine_real_restart_asm;
18348-#ifdef CONFIG_X86_64
18349 u32 machine_real_restart_seg;
18350-#endif
18351 };
18352
18353 /* This must match data at trampoline_32/64.S */
18354 struct trampoline_header {
18355 #ifdef CONFIG_X86_32
18356 u32 start;
18357- u16 gdt_pad;
18358+ u16 boot_cs;
18359 u16 gdt_limit;
18360 u32 gdt_base;
18361 #else
18362diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18363index a82c4f1..ac45053 100644
18364--- a/arch/x86/include/asm/reboot.h
18365+++ b/arch/x86/include/asm/reboot.h
18366@@ -6,13 +6,13 @@
18367 struct pt_regs;
18368
18369 struct machine_ops {
18370- void (*restart)(char *cmd);
18371- void (*halt)(void);
18372- void (*power_off)(void);
18373+ void (* __noreturn restart)(char *cmd);
18374+ void (* __noreturn halt)(void);
18375+ void (* __noreturn power_off)(void);
18376 void (*shutdown)(void);
18377 void (*crash_shutdown)(struct pt_regs *);
18378- void (*emergency_restart)(void);
18379-};
18380+ void (* __noreturn emergency_restart)(void);
18381+} __no_const;
18382
18383 extern struct machine_ops machine_ops;
18384
18385diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18386index 8f7866a..e442f20 100644
18387--- a/arch/x86/include/asm/rmwcc.h
18388+++ b/arch/x86/include/asm/rmwcc.h
18389@@ -3,7 +3,34 @@
18390
18391 #ifdef CC_HAVE_ASM_GOTO
18392
18393-#define __GEN_RMWcc(fullop, var, cc, ...) \
18394+#ifdef CONFIG_PAX_REFCOUNT
18395+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18396+do { \
18397+ asm_volatile_goto (fullop \
18398+ ";jno 0f\n" \
18399+ fullantiop \
18400+ ";int $4\n0:\n" \
18401+ _ASM_EXTABLE(0b, 0b) \
18402+ ";j" cc " %l[cc_label]" \
18403+ : : "m" (var), ## __VA_ARGS__ \
18404+ : "memory" : cc_label); \
18405+ return 0; \
18406+cc_label: \
18407+ return 1; \
18408+} while (0)
18409+#else
18410+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18411+do { \
18412+ asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18413+ : : "m" (var), ## __VA_ARGS__ \
18414+ : "memory" : cc_label); \
18415+ return 0; \
18416+cc_label: \
18417+ return 1; \
18418+} while (0)
18419+#endif
18420+
18421+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18422 do { \
18423 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18424 : : "m" (var), ## __VA_ARGS__ \
18425@@ -13,15 +40,46 @@ cc_label: \
18426 return 1; \
18427 } while (0)
18428
18429-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18430- __GEN_RMWcc(op " " arg0, var, cc)
18431+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18432+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18433
18434-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18435- __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18436+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18437+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18438+
18439+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18440+ __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18441+
18442+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18443+ __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18444
18445 #else /* !CC_HAVE_ASM_GOTO */
18446
18447-#define __GEN_RMWcc(fullop, var, cc, ...) \
18448+#ifdef CONFIG_PAX_REFCOUNT
18449+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18450+do { \
18451+ char c; \
18452+ asm volatile (fullop \
18453+ ";jno 0f\n" \
18454+ fullantiop \
18455+ ";int $4\n0:\n" \
18456+ _ASM_EXTABLE(0b, 0b) \
18457+ "; set" cc " %1" \
18458+ : "+m" (var), "=qm" (c) \
18459+ : __VA_ARGS__ : "memory"); \
18460+ return c != 0; \
18461+} while (0)
18462+#else
18463+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18464+do { \
18465+ char c; \
18466+ asm volatile (fullop "; set" cc " %1" \
18467+ : "+m" (var), "=qm" (c) \
18468+ : __VA_ARGS__ : "memory"); \
18469+ return c != 0; \
18470+} while (0)
18471+#endif
18472+
18473+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18474 do { \
18475 char c; \
18476 asm volatile (fullop "; set" cc " %1" \
18477@@ -30,11 +88,17 @@ do { \
18478 return c != 0; \
18479 } while (0)
18480
18481-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18482- __GEN_RMWcc(op " " arg0, var, cc)
18483+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18484+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18485+
18486+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18487+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18488+
18489+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18490+ __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18491
18492-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18493- __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18494+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18495+ __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18496
18497 #endif /* CC_HAVE_ASM_GOTO */
18498
18499diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18500index cad82c9..2e5c5c1 100644
18501--- a/arch/x86/include/asm/rwsem.h
18502+++ b/arch/x86/include/asm/rwsem.h
18503@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18504 {
18505 asm volatile("# beginning down_read\n\t"
18506 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18507+
18508+#ifdef CONFIG_PAX_REFCOUNT
18509+ "jno 0f\n"
18510+ LOCK_PREFIX _ASM_DEC "(%1)\n"
18511+ "int $4\n0:\n"
18512+ _ASM_EXTABLE(0b, 0b)
18513+#endif
18514+
18515 /* adds 0x00000001 */
18516 " jns 1f\n"
18517 " call call_rwsem_down_read_failed\n"
18518@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18519 "1:\n\t"
18520 " mov %1,%2\n\t"
18521 " add %3,%2\n\t"
18522+
18523+#ifdef CONFIG_PAX_REFCOUNT
18524+ "jno 0f\n"
18525+ "sub %3,%2\n"
18526+ "int $4\n0:\n"
18527+ _ASM_EXTABLE(0b, 0b)
18528+#endif
18529+
18530 " jle 2f\n\t"
18531 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18532 " jnz 1b\n\t"
18533@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18534 long tmp;
18535 asm volatile("# beginning down_write\n\t"
18536 LOCK_PREFIX " xadd %1,(%2)\n\t"
18537+
18538+#ifdef CONFIG_PAX_REFCOUNT
18539+ "jno 0f\n"
18540+ "mov %1,(%2)\n"
18541+ "int $4\n0:\n"
18542+ _ASM_EXTABLE(0b, 0b)
18543+#endif
18544+
18545 /* adds 0xffff0001, returns the old value */
18546 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18547 /* was the active mask 0 before? */
18548@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18549 long tmp;
18550 asm volatile("# beginning __up_read\n\t"
18551 LOCK_PREFIX " xadd %1,(%2)\n\t"
18552+
18553+#ifdef CONFIG_PAX_REFCOUNT
18554+ "jno 0f\n"
18555+ "mov %1,(%2)\n"
18556+ "int $4\n0:\n"
18557+ _ASM_EXTABLE(0b, 0b)
18558+#endif
18559+
18560 /* subtracts 1, returns the old value */
18561 " jns 1f\n\t"
18562 " call call_rwsem_wake\n" /* expects old value in %edx */
18563@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18564 long tmp;
18565 asm volatile("# beginning __up_write\n\t"
18566 LOCK_PREFIX " xadd %1,(%2)\n\t"
18567+
18568+#ifdef CONFIG_PAX_REFCOUNT
18569+ "jno 0f\n"
18570+ "mov %1,(%2)\n"
18571+ "int $4\n0:\n"
18572+ _ASM_EXTABLE(0b, 0b)
18573+#endif
18574+
18575 /* subtracts 0xffff0001, returns the old value */
18576 " jns 1f\n\t"
18577 " call call_rwsem_wake\n" /* expects old value in %edx */
18578@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18579 {
18580 asm volatile("# beginning __downgrade_write\n\t"
18581 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18582+
18583+#ifdef CONFIG_PAX_REFCOUNT
18584+ "jno 0f\n"
18585+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18586+ "int $4\n0:\n"
18587+ _ASM_EXTABLE(0b, 0b)
18588+#endif
18589+
18590 /*
18591 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18592 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18593@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18594 */
18595 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18596 {
18597- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18598+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18599+
18600+#ifdef CONFIG_PAX_REFCOUNT
18601+ "jno 0f\n"
18602+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
18603+ "int $4\n0:\n"
18604+ _ASM_EXTABLE(0b, 0b)
18605+#endif
18606+
18607 : "+m" (sem->count)
18608 : "er" (delta));
18609 }
18610@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18611 */
18612 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18613 {
18614- return delta + xadd(&sem->count, delta);
18615+ return delta + xadd_check_overflow(&sem->count, delta);
18616 }
18617
18618 #endif /* __KERNEL__ */
18619diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18620index 6f1c3a8..7744f19 100644
18621--- a/arch/x86/include/asm/segment.h
18622+++ b/arch/x86/include/asm/segment.h
18623@@ -64,10 +64,15 @@
18624 * 26 - ESPFIX small SS
18625 * 27 - per-cpu [ offset to per-cpu data area ]
18626 * 28 - stack_canary-20 [ for stack protector ]
18627- * 29 - unused
18628- * 30 - unused
18629+ * 29 - PCI BIOS CS
18630+ * 30 - PCI BIOS DS
18631 * 31 - TSS for double fault handler
18632 */
18633+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18634+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18635+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18636+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18637+
18638 #define GDT_ENTRY_TLS_MIN 6
18639 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18640
18641@@ -79,6 +84,8 @@
18642
18643 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18644
18645+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18646+
18647 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18648
18649 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18650@@ -104,6 +111,12 @@
18651 #define __KERNEL_STACK_CANARY 0
18652 #endif
18653
18654+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18655+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18656+
18657+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18658+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18659+
18660 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18661
18662 /*
18663@@ -141,7 +154,7 @@
18664 */
18665
18666 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18667-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18668+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18669
18670
18671 #else
18672@@ -165,6 +178,8 @@
18673 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18674 #define __USER32_DS __USER_DS
18675
18676+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18677+
18678 #define GDT_ENTRY_TSS 8 /* needs two entries */
18679 #define GDT_ENTRY_LDT 10 /* needs two entries */
18680 #define GDT_ENTRY_TLS_MIN 12
18681@@ -173,6 +188,8 @@
18682 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18683 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18684
18685+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18686+
18687 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18688 #define FS_TLS 0
18689 #define GS_TLS 1
18690@@ -180,12 +197,14 @@
18691 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18692 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18693
18694-#define GDT_ENTRIES 16
18695+#define GDT_ENTRIES 17
18696
18697 #endif
18698
18699 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18700+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18701 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18702+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18703 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18704 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
18705 #ifndef CONFIG_PARAVIRT
18706@@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
18707 {
18708 unsigned long __limit;
18709 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
18710- return __limit + 1;
18711+ return __limit;
18712 }
18713
18714 #endif /* !__ASSEMBLY__ */
18715diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18716index 8d3120f..352b440 100644
18717--- a/arch/x86/include/asm/smap.h
18718+++ b/arch/x86/include/asm/smap.h
18719@@ -25,11 +25,40 @@
18720
18721 #include <asm/alternative-asm.h>
18722
18723+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18724+#define ASM_PAX_OPEN_USERLAND \
18725+ 661: jmp 663f; \
18726+ .pushsection .altinstr_replacement, "a" ; \
18727+ 662: pushq %rax; nop; \
18728+ .popsection ; \
18729+ .pushsection .altinstructions, "a" ; \
18730+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18731+ .popsection ; \
18732+ call __pax_open_userland; \
18733+ popq %rax; \
18734+ 663:
18735+
18736+#define ASM_PAX_CLOSE_USERLAND \
18737+ 661: jmp 663f; \
18738+ .pushsection .altinstr_replacement, "a" ; \
18739+ 662: pushq %rax; nop; \
18740+ .popsection; \
18741+ .pushsection .altinstructions, "a" ; \
18742+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18743+ .popsection; \
18744+ call __pax_close_userland; \
18745+ popq %rax; \
18746+ 663:
18747+#else
18748+#define ASM_PAX_OPEN_USERLAND
18749+#define ASM_PAX_CLOSE_USERLAND
18750+#endif
18751+
18752 #ifdef CONFIG_X86_SMAP
18753
18754 #define ASM_CLAC \
18755 661: ASM_NOP3 ; \
18756- .pushsection .altinstr_replacement, "ax" ; \
18757+ .pushsection .altinstr_replacement, "a" ; \
18758 662: __ASM_CLAC ; \
18759 .popsection ; \
18760 .pushsection .altinstructions, "a" ; \
18761@@ -38,7 +67,7 @@
18762
18763 #define ASM_STAC \
18764 661: ASM_NOP3 ; \
18765- .pushsection .altinstr_replacement, "ax" ; \
18766+ .pushsection .altinstr_replacement, "a" ; \
18767 662: __ASM_STAC ; \
18768 .popsection ; \
18769 .pushsection .altinstructions, "a" ; \
18770@@ -56,6 +85,37 @@
18771
18772 #include <asm/alternative.h>
18773
18774+#define __HAVE_ARCH_PAX_OPEN_USERLAND
18775+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18776+
18777+extern void __pax_open_userland(void);
18778+static __always_inline unsigned long pax_open_userland(void)
18779+{
18780+
18781+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18782+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18783+ :
18784+ : [open] "i" (__pax_open_userland)
18785+ : "memory", "rax");
18786+#endif
18787+
18788+ return 0;
18789+}
18790+
18791+extern void __pax_close_userland(void);
18792+static __always_inline unsigned long pax_close_userland(void)
18793+{
18794+
18795+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18796+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18797+ :
18798+ : [close] "i" (__pax_close_userland)
18799+ : "memory", "rax");
18800+#endif
18801+
18802+ return 0;
18803+}
18804+
18805 #ifdef CONFIG_X86_SMAP
18806
18807 static __always_inline void clac(void)
18808diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18809index 4137890..03fa172 100644
18810--- a/arch/x86/include/asm/smp.h
18811+++ b/arch/x86/include/asm/smp.h
18812@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18813 /* cpus sharing the last level cache: */
18814 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18815 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18816-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18817+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18818
18819 static inline struct cpumask *cpu_sibling_mask(int cpu)
18820 {
18821@@ -79,7 +79,7 @@ struct smp_ops {
18822
18823 void (*send_call_func_ipi)(const struct cpumask *mask);
18824 void (*send_call_func_single_ipi)(int cpu);
18825-};
18826+} __no_const;
18827
18828 /* Globals due to paravirt */
18829 extern void set_cpu_sibling_map(int cpu);
18830@@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
18831 extern int safe_smp_processor_id(void);
18832
18833 #elif defined(CONFIG_X86_64_SMP)
18834-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18835-
18836-#define stack_smp_processor_id() \
18837-({ \
18838- struct thread_info *ti; \
18839- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18840- ti->cpu; \
18841-})
18842+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18843+#define stack_smp_processor_id() raw_smp_processor_id()
18844 #define safe_smp_processor_id() smp_processor_id()
18845
18846 #endif
18847diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18848index bf156de..1a782ab 100644
18849--- a/arch/x86/include/asm/spinlock.h
18850+++ b/arch/x86/include/asm/spinlock.h
18851@@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18852 static inline void arch_read_lock(arch_rwlock_t *rw)
18853 {
18854 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18855+
18856+#ifdef CONFIG_PAX_REFCOUNT
18857+ "jno 0f\n"
18858+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18859+ "int $4\n0:\n"
18860+ _ASM_EXTABLE(0b, 0b)
18861+#endif
18862+
18863 "jns 1f\n"
18864 "call __read_lock_failed\n\t"
18865 "1:\n"
18866@@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18867 static inline void arch_write_lock(arch_rwlock_t *rw)
18868 {
18869 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
18870+
18871+#ifdef CONFIG_PAX_REFCOUNT
18872+ "jno 0f\n"
18873+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
18874+ "int $4\n0:\n"
18875+ _ASM_EXTABLE(0b, 0b)
18876+#endif
18877+
18878 "jz 1f\n"
18879 "call __write_lock_failed\n\t"
18880 "1:\n"
18881@@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
18882
18883 static inline void arch_read_unlock(arch_rwlock_t *rw)
18884 {
18885- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
18886+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
18887+
18888+#ifdef CONFIG_PAX_REFCOUNT
18889+ "jno 0f\n"
18890+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
18891+ "int $4\n0:\n"
18892+ _ASM_EXTABLE(0b, 0b)
18893+#endif
18894+
18895 :"+m" (rw->lock) : : "memory");
18896 }
18897
18898 static inline void arch_write_unlock(arch_rwlock_t *rw)
18899 {
18900- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
18901+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
18902+
18903+#ifdef CONFIG_PAX_REFCOUNT
18904+ "jno 0f\n"
18905+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
18906+ "int $4\n0:\n"
18907+ _ASM_EXTABLE(0b, 0b)
18908+#endif
18909+
18910 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
18911 }
18912
18913diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
18914index 6a99859..03cb807 100644
18915--- a/arch/x86/include/asm/stackprotector.h
18916+++ b/arch/x86/include/asm/stackprotector.h
18917@@ -47,7 +47,7 @@
18918 * head_32 for boot CPU and setup_per_cpu_areas() for others.
18919 */
18920 #define GDT_STACK_CANARY_INIT \
18921- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
18922+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
18923
18924 /*
18925 * Initialize the stackprotector canary value.
18926@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
18927
18928 static inline void load_stack_canary_segment(void)
18929 {
18930-#ifdef CONFIG_X86_32
18931+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18932 asm volatile ("mov %0, %%gs" : : "r" (0));
18933 #endif
18934 }
18935diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
18936index 70bbe39..4ae2bd4 100644
18937--- a/arch/x86/include/asm/stacktrace.h
18938+++ b/arch/x86/include/asm/stacktrace.h
18939@@ -11,28 +11,20 @@
18940
18941 extern int kstack_depth_to_print;
18942
18943-struct thread_info;
18944+struct task_struct;
18945 struct stacktrace_ops;
18946
18947-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
18948- unsigned long *stack,
18949- unsigned long bp,
18950- const struct stacktrace_ops *ops,
18951- void *data,
18952- unsigned long *end,
18953- int *graph);
18954+typedef unsigned long walk_stack_t(struct task_struct *task,
18955+ void *stack_start,
18956+ unsigned long *stack,
18957+ unsigned long bp,
18958+ const struct stacktrace_ops *ops,
18959+ void *data,
18960+ unsigned long *end,
18961+ int *graph);
18962
18963-extern unsigned long
18964-print_context_stack(struct thread_info *tinfo,
18965- unsigned long *stack, unsigned long bp,
18966- const struct stacktrace_ops *ops, void *data,
18967- unsigned long *end, int *graph);
18968-
18969-extern unsigned long
18970-print_context_stack_bp(struct thread_info *tinfo,
18971- unsigned long *stack, unsigned long bp,
18972- const struct stacktrace_ops *ops, void *data,
18973- unsigned long *end, int *graph);
18974+extern walk_stack_t print_context_stack;
18975+extern walk_stack_t print_context_stack_bp;
18976
18977 /* Generic stack tracer with callbacks */
18978
18979@@ -40,7 +32,7 @@ struct stacktrace_ops {
18980 void (*address)(void *data, unsigned long address, int reliable);
18981 /* On negative return stop dumping */
18982 int (*stack)(void *data, char *name);
18983- walk_stack_t walk_stack;
18984+ walk_stack_t *walk_stack;
18985 };
18986
18987 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
18988diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
18989index d7f3b3b..3cc39f1 100644
18990--- a/arch/x86/include/asm/switch_to.h
18991+++ b/arch/x86/include/asm/switch_to.h
18992@@ -108,7 +108,7 @@ do { \
18993 "call __switch_to\n\t" \
18994 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
18995 __switch_canary \
18996- "movq %P[thread_info](%%rsi),%%r8\n\t" \
18997+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
18998 "movq %%rax,%%rdi\n\t" \
18999 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19000 "jnz ret_from_fork\n\t" \
19001@@ -119,7 +119,7 @@ do { \
19002 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19003 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19004 [_tif_fork] "i" (_TIF_FORK), \
19005- [thread_info] "i" (offsetof(struct task_struct, stack)), \
19006+ [thread_info] "m" (current_tinfo), \
19007 [current_task] "m" (current_task) \
19008 __switch_canary_iparam \
19009 : "memory", "cc" __EXTRA_CLOBBER)
19010diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19011index 3ba3de4..6c113b2 100644
19012--- a/arch/x86/include/asm/thread_info.h
19013+++ b/arch/x86/include/asm/thread_info.h
19014@@ -10,6 +10,7 @@
19015 #include <linux/compiler.h>
19016 #include <asm/page.h>
19017 #include <asm/types.h>
19018+#include <asm/percpu.h>
19019
19020 /*
19021 * low level task data that entry.S needs immediate access to
19022@@ -23,7 +24,6 @@ struct exec_domain;
19023 #include <linux/atomic.h>
19024
19025 struct thread_info {
19026- struct task_struct *task; /* main task structure */
19027 struct exec_domain *exec_domain; /* execution domain */
19028 __u32 flags; /* low level flags */
19029 __u32 status; /* thread synchronous flags */
19030@@ -32,19 +32,13 @@ struct thread_info {
19031 mm_segment_t addr_limit;
19032 struct restart_block restart_block;
19033 void __user *sysenter_return;
19034-#ifdef CONFIG_X86_32
19035- unsigned long previous_esp; /* ESP of the previous stack in
19036- case of nested (IRQ) stacks
19037- */
19038- __u8 supervisor_stack[0];
19039-#endif
19040+ unsigned long lowest_stack;
19041 unsigned int sig_on_uaccess_error:1;
19042 unsigned int uaccess_err:1; /* uaccess failed */
19043 };
19044
19045-#define INIT_THREAD_INFO(tsk) \
19046+#define INIT_THREAD_INFO \
19047 { \
19048- .task = &tsk, \
19049 .exec_domain = &default_exec_domain, \
19050 .flags = 0, \
19051 .cpu = 0, \
19052@@ -55,7 +49,7 @@ struct thread_info {
19053 }, \
19054 }
19055
19056-#define init_thread_info (init_thread_union.thread_info)
19057+#define init_thread_info (init_thread_union.stack)
19058 #define init_stack (init_thread_union.stack)
19059
19060 #else /* !__ASSEMBLY__ */
19061@@ -95,6 +89,7 @@ struct thread_info {
19062 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19063 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19064 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19065+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19066
19067 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19068 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19069@@ -118,17 +113,18 @@ struct thread_info {
19070 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19071 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19072 #define _TIF_X32 (1 << TIF_X32)
19073+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19074
19075 /* work to do in syscall_trace_enter() */
19076 #define _TIF_WORK_SYSCALL_ENTRY \
19077 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19078 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19079- _TIF_NOHZ)
19080+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19081
19082 /* work to do in syscall_trace_leave() */
19083 #define _TIF_WORK_SYSCALL_EXIT \
19084 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19085- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19086+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19087
19088 /* work to do on interrupt/exception return */
19089 #define _TIF_WORK_MASK \
19090@@ -139,7 +135,7 @@ struct thread_info {
19091 /* work to do on any return to user space */
19092 #define _TIF_ALLWORK_MASK \
19093 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19094- _TIF_NOHZ)
19095+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19096
19097 /* Only used for 64 bit */
19098 #define _TIF_DO_NOTIFY_MASK \
19099@@ -153,45 +149,40 @@ struct thread_info {
19100 #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
19101 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19102
19103-#ifdef CONFIG_X86_32
19104-
19105-#define STACK_WARN (THREAD_SIZE/8)
19106-/*
19107- * macros/functions for gaining access to the thread information structure
19108- *
19109- * preempt_count needs to be 1 initially, until the scheduler is functional.
19110- */
19111-#ifndef __ASSEMBLY__
19112-
19113-
19114-/* how to get the current stack pointer from C */
19115-register unsigned long current_stack_pointer asm("esp") __used;
19116-
19117-/* how to get the thread information struct from C */
19118-static inline struct thread_info *current_thread_info(void)
19119-{
19120- return (struct thread_info *)
19121- (current_stack_pointer & ~(THREAD_SIZE - 1));
19122-}
19123-
19124-#else /* !__ASSEMBLY__ */
19125-
19126+#ifdef __ASSEMBLY__
19127 /* how to get the thread information struct from ASM */
19128 #define GET_THREAD_INFO(reg) \
19129- movl $-THREAD_SIZE, reg; \
19130- andl %esp, reg
19131+ mov PER_CPU_VAR(current_tinfo), reg
19132
19133 /* use this one if reg already contains %esp */
19134-#define GET_THREAD_INFO_WITH_ESP(reg) \
19135- andl $-THREAD_SIZE, reg
19136+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
19137+#else
19138+/* how to get the thread information struct from C */
19139+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19140+
19141+static __always_inline struct thread_info *current_thread_info(void)
19142+{
19143+ return this_cpu_read_stable(current_tinfo);
19144+}
19145+#endif
19146+
19147+#ifdef CONFIG_X86_32
19148+
19149+#define STACK_WARN (THREAD_SIZE/8)
19150+/*
19151+ * macros/functions for gaining access to the thread information structure
19152+ *
19153+ * preempt_count needs to be 1 initially, until the scheduler is functional.
19154+ */
19155+#ifndef __ASSEMBLY__
19156+
19157+/* how to get the current stack pointer from C */
19158+register unsigned long current_stack_pointer asm("esp") __used;
19159
19160 #endif
19161
19162 #else /* X86_32 */
19163
19164-#include <asm/percpu.h>
19165-#define KERNEL_STACK_OFFSET (5*8)
19166-
19167 /*
19168 * macros/functions for gaining access to the thread information structure
19169 * preempt_count needs to be 1 initially, until the scheduler is functional.
19170@@ -199,27 +190,8 @@ static inline struct thread_info *current_thread_info(void)
19171 #ifndef __ASSEMBLY__
19172 DECLARE_PER_CPU(unsigned long, kernel_stack);
19173
19174-static inline struct thread_info *current_thread_info(void)
19175-{
19176- struct thread_info *ti;
19177- ti = (void *)(this_cpu_read_stable(kernel_stack) +
19178- KERNEL_STACK_OFFSET - THREAD_SIZE);
19179- return ti;
19180-}
19181-
19182-#else /* !__ASSEMBLY__ */
19183-
19184-/* how to get the thread information struct from ASM */
19185-#define GET_THREAD_INFO(reg) \
19186- movq PER_CPU_VAR(kernel_stack),reg ; \
19187- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
19188-
19189-/*
19190- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19191- * a certain register (to be used in assembler memory operands).
19192- */
19193-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19194-
19195+/* how to get the current stack pointer from C */
19196+register unsigned long current_stack_pointer asm("rsp") __used;
19197 #endif
19198
19199 #endif /* !X86_32 */
19200@@ -278,5 +250,12 @@ static inline bool is_ia32_task(void)
19201 extern void arch_task_cache_init(void);
19202 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19203 extern void arch_release_task_struct(struct task_struct *tsk);
19204+
19205+#define __HAVE_THREAD_FUNCTIONS
19206+#define task_thread_info(task) (&(task)->tinfo)
19207+#define task_stack_page(task) ((task)->stack)
19208+#define setup_thread_stack(p, org) do {} while (0)
19209+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19210+
19211 #endif
19212 #endif /* _ASM_X86_THREAD_INFO_H */
19213diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19214index e6d90ba..f81f114 100644
19215--- a/arch/x86/include/asm/tlbflush.h
19216+++ b/arch/x86/include/asm/tlbflush.h
19217@@ -17,18 +17,44 @@
19218
19219 static inline void __native_flush_tlb(void)
19220 {
19221+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19222+ u64 descriptor[2];
19223+
19224+ descriptor[0] = PCID_KERNEL;
19225+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19226+ return;
19227+ }
19228+
19229+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19230+ if (static_cpu_has(X86_FEATURE_PCID)) {
19231+ unsigned int cpu = raw_get_cpu();
19232+
19233+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19234+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19235+ raw_put_cpu_no_resched();
19236+ return;
19237+ }
19238+#endif
19239+
19240 native_write_cr3(native_read_cr3());
19241 }
19242
19243 static inline void __native_flush_tlb_global_irq_disabled(void)
19244 {
19245- unsigned long cr4;
19246+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19247+ u64 descriptor[2];
19248
19249- cr4 = native_read_cr4();
19250- /* clear PGE */
19251- native_write_cr4(cr4 & ~X86_CR4_PGE);
19252- /* write old PGE again and flush TLBs */
19253- native_write_cr4(cr4);
19254+ descriptor[0] = PCID_KERNEL;
19255+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19256+ } else {
19257+ unsigned long cr4;
19258+
19259+ cr4 = native_read_cr4();
19260+ /* clear PGE */
19261+ native_write_cr4(cr4 & ~X86_CR4_PGE);
19262+ /* write old PGE again and flush TLBs */
19263+ native_write_cr4(cr4);
19264+ }
19265 }
19266
19267 static inline void __native_flush_tlb_global(void)
19268@@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19269
19270 static inline void __native_flush_tlb_single(unsigned long addr)
19271 {
19272+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19273+ u64 descriptor[2];
19274+
19275+ descriptor[0] = PCID_KERNEL;
19276+ descriptor[1] = addr;
19277+
19278+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19279+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19280+ if (addr < TASK_SIZE_MAX)
19281+ descriptor[1] += pax_user_shadow_base;
19282+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19283+ }
19284+
19285+ descriptor[0] = PCID_USER;
19286+ descriptor[1] = addr;
19287+#endif
19288+
19289+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19290+ return;
19291+ }
19292+
19293+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19294+ if (static_cpu_has(X86_FEATURE_PCID)) {
19295+ unsigned int cpu = raw_get_cpu();
19296+
19297+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19298+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19299+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19300+ raw_put_cpu_no_resched();
19301+
19302+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19303+ addr += pax_user_shadow_base;
19304+ }
19305+#endif
19306+
19307 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19308 }
19309
19310diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19311index 8ec57c0..451bcfc 100644
19312--- a/arch/x86/include/asm/uaccess.h
19313+++ b/arch/x86/include/asm/uaccess.h
19314@@ -7,6 +7,7 @@
19315 #include <linux/compiler.h>
19316 #include <linux/thread_info.h>
19317 #include <linux/string.h>
19318+#include <linux/spinlock.h>
19319 #include <asm/asm.h>
19320 #include <asm/page.h>
19321 #include <asm/smap.h>
19322@@ -29,7 +30,12 @@
19323
19324 #define get_ds() (KERNEL_DS)
19325 #define get_fs() (current_thread_info()->addr_limit)
19326+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19327+void __set_fs(mm_segment_t x);
19328+void set_fs(mm_segment_t x);
19329+#else
19330 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19331+#endif
19332
19333 #define segment_eq(a, b) ((a).seg == (b).seg)
19334
19335@@ -77,8 +83,34 @@
19336 * checks that the pointer is in the user space range - after calling
19337 * this function, memory access functions may still return -EFAULT.
19338 */
19339-#define access_ok(type, addr, size) \
19340- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
19341+extern int _cond_resched(void);
19342+#define access_ok_noprefault(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
19343+#define access_ok(type, addr, size) \
19344+({ \
19345+ long __size = size; \
19346+ unsigned long __addr = (unsigned long)addr; \
19347+ unsigned long __addr_ao = __addr & PAGE_MASK; \
19348+ unsigned long __end_ao = __addr + __size - 1; \
19349+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19350+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19351+ while(__addr_ao <= __end_ao) { \
19352+ char __c_ao; \
19353+ __addr_ao += PAGE_SIZE; \
19354+ if (__size > PAGE_SIZE) \
19355+ _cond_resched(); \
19356+ if (__get_user(__c_ao, (char __user *)__addr)) \
19357+ break; \
19358+ if (type != VERIFY_WRITE) { \
19359+ __addr = __addr_ao; \
19360+ continue; \
19361+ } \
19362+ if (__put_user(__c_ao, (char __user *)__addr)) \
19363+ break; \
19364+ __addr = __addr_ao; \
19365+ } \
19366+ } \
19367+ __ret_ao; \
19368+})
19369
19370 /*
19371 * The exception table consists of pairs of addresses relative to the
19372@@ -168,10 +200,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19373 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19374 __chk_user_ptr(ptr); \
19375 might_fault(); \
19376+ pax_open_userland(); \
19377 asm volatile("call __get_user_%P3" \
19378 : "=a" (__ret_gu), "=r" (__val_gu) \
19379 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19380 (x) = (__typeof__(*(ptr))) __val_gu; \
19381+ pax_close_userland(); \
19382 __ret_gu; \
19383 })
19384
19385@@ -179,13 +213,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19386 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19387 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19388
19389-
19390+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19391+#define __copyuser_seg "gs;"
19392+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19393+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19394+#else
19395+#define __copyuser_seg
19396+#define __COPYUSER_SET_ES
19397+#define __COPYUSER_RESTORE_ES
19398+#endif
19399
19400 #ifdef CONFIG_X86_32
19401 #define __put_user_asm_u64(x, addr, err, errret) \
19402 asm volatile(ASM_STAC "\n" \
19403- "1: movl %%eax,0(%2)\n" \
19404- "2: movl %%edx,4(%2)\n" \
19405+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19406+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19407 "3: " ASM_CLAC "\n" \
19408 ".section .fixup,\"ax\"\n" \
19409 "4: movl %3,%0\n" \
19410@@ -198,8 +240,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19411
19412 #define __put_user_asm_ex_u64(x, addr) \
19413 asm volatile(ASM_STAC "\n" \
19414- "1: movl %%eax,0(%1)\n" \
19415- "2: movl %%edx,4(%1)\n" \
19416+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19417+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19418 "3: " ASM_CLAC "\n" \
19419 _ASM_EXTABLE_EX(1b, 2b) \
19420 _ASM_EXTABLE_EX(2b, 3b) \
19421@@ -249,7 +291,8 @@ extern void __put_user_8(void);
19422 __typeof__(*(ptr)) __pu_val; \
19423 __chk_user_ptr(ptr); \
19424 might_fault(); \
19425- __pu_val = x; \
19426+ __pu_val = (x); \
19427+ pax_open_userland(); \
19428 switch (sizeof(*(ptr))) { \
19429 case 1: \
19430 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19431@@ -267,6 +310,7 @@ extern void __put_user_8(void);
19432 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19433 break; \
19434 } \
19435+ pax_close_userland(); \
19436 __ret_pu; \
19437 })
19438
19439@@ -347,8 +391,10 @@ do { \
19440 } while (0)
19441
19442 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19443+do { \
19444+ pax_open_userland(); \
19445 asm volatile(ASM_STAC "\n" \
19446- "1: mov"itype" %2,%"rtype"1\n" \
19447+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19448 "2: " ASM_CLAC "\n" \
19449 ".section .fixup,\"ax\"\n" \
19450 "3: mov %3,%0\n" \
19451@@ -356,8 +402,10 @@ do { \
19452 " jmp 2b\n" \
19453 ".previous\n" \
19454 _ASM_EXTABLE(1b, 3b) \
19455- : "=r" (err), ltype(x) \
19456- : "m" (__m(addr)), "i" (errret), "0" (err))
19457+ : "=r" (err), ltype (x) \
19458+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
19459+ pax_close_userland(); \
19460+} while (0)
19461
19462 #define __get_user_size_ex(x, ptr, size) \
19463 do { \
19464@@ -381,7 +429,7 @@ do { \
19465 } while (0)
19466
19467 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19468- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19469+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19470 "2:\n" \
19471 _ASM_EXTABLE_EX(1b, 2b) \
19472 : ltype(x) : "m" (__m(addr)))
19473@@ -398,13 +446,24 @@ do { \
19474 int __gu_err; \
19475 unsigned long __gu_val; \
19476 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19477- (x) = (__force __typeof__(*(ptr)))__gu_val; \
19478+ (x) = (__typeof__(*(ptr)))__gu_val; \
19479 __gu_err; \
19480 })
19481
19482 /* FIXME: this hack is definitely wrong -AK */
19483 struct __large_struct { unsigned long buf[100]; };
19484-#define __m(x) (*(struct __large_struct __user *)(x))
19485+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19486+#define ____m(x) \
19487+({ \
19488+ unsigned long ____x = (unsigned long)(x); \
19489+ if (____x < pax_user_shadow_base) \
19490+ ____x += pax_user_shadow_base; \
19491+ (typeof(x))____x; \
19492+})
19493+#else
19494+#define ____m(x) (x)
19495+#endif
19496+#define __m(x) (*(struct __large_struct __user *)____m(x))
19497
19498 /*
19499 * Tell gcc we read from memory instead of writing: this is because
19500@@ -412,8 +471,10 @@ struct __large_struct { unsigned long buf[100]; };
19501 * aliasing issues.
19502 */
19503 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19504+do { \
19505+ pax_open_userland(); \
19506 asm volatile(ASM_STAC "\n" \
19507- "1: mov"itype" %"rtype"1,%2\n" \
19508+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19509 "2: " ASM_CLAC "\n" \
19510 ".section .fixup,\"ax\"\n" \
19511 "3: mov %3,%0\n" \
19512@@ -421,10 +482,12 @@ struct __large_struct { unsigned long buf[100]; };
19513 ".previous\n" \
19514 _ASM_EXTABLE(1b, 3b) \
19515 : "=r"(err) \
19516- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19517+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19518+ pax_close_userland(); \
19519+} while (0)
19520
19521 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19522- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19523+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19524 "2:\n" \
19525 _ASM_EXTABLE_EX(1b, 2b) \
19526 : : ltype(x), "m" (__m(addr)))
19527@@ -434,11 +497,13 @@ struct __large_struct { unsigned long buf[100]; };
19528 */
19529 #define uaccess_try do { \
19530 current_thread_info()->uaccess_err = 0; \
19531+ pax_open_userland(); \
19532 stac(); \
19533 barrier();
19534
19535 #define uaccess_catch(err) \
19536 clac(); \
19537+ pax_close_userland(); \
19538 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19539 } while (0)
19540
19541@@ -463,8 +528,12 @@ struct __large_struct { unsigned long buf[100]; };
19542 * On error, the variable @x is set to zero.
19543 */
19544
19545+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19546+#define __get_user(x, ptr) get_user((x), (ptr))
19547+#else
19548 #define __get_user(x, ptr) \
19549 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19550+#endif
19551
19552 /**
19553 * __put_user: - Write a simple value into user space, with less checking.
19554@@ -486,8 +555,12 @@ struct __large_struct { unsigned long buf[100]; };
19555 * Returns zero on success, or -EFAULT on error.
19556 */
19557
19558+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19559+#define __put_user(x, ptr) put_user((x), (ptr))
19560+#else
19561 #define __put_user(x, ptr) \
19562 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19563+#endif
19564
19565 #define __get_user_unaligned __get_user
19566 #define __put_user_unaligned __put_user
19567@@ -505,7 +578,7 @@ struct __large_struct { unsigned long buf[100]; };
19568 #define get_user_ex(x, ptr) do { \
19569 unsigned long __gue_val; \
19570 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19571- (x) = (__force __typeof__(*(ptr)))__gue_val; \
19572+ (x) = (__typeof__(*(ptr)))__gue_val; \
19573 } while (0)
19574
19575 #define put_user_try uaccess_try
19576@@ -536,17 +609,6 @@ extern struct movsl_mask {
19577
19578 #define ARCH_HAS_NOCACHE_UACCESS 1
19579
19580-#ifdef CONFIG_X86_32
19581-# include <asm/uaccess_32.h>
19582-#else
19583-# include <asm/uaccess_64.h>
19584-#endif
19585-
19586-unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19587- unsigned n);
19588-unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19589- unsigned n);
19590-
19591 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19592 # define copy_user_diag __compiletime_error
19593 #else
19594@@ -556,7 +618,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19595 extern void copy_user_diag("copy_from_user() buffer size is too small")
19596 copy_from_user_overflow(void);
19597 extern void copy_user_diag("copy_to_user() buffer size is too small")
19598-copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19599+copy_to_user_overflow(void);
19600
19601 #undef copy_user_diag
19602
19603@@ -569,7 +631,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19604
19605 extern void
19606 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19607-__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19608+__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19609 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19610
19611 #else
19612@@ -584,10 +646,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19613
19614 #endif
19615
19616+#ifdef CONFIG_X86_32
19617+# include <asm/uaccess_32.h>
19618+#else
19619+# include <asm/uaccess_64.h>
19620+#endif
19621+
19622 static inline unsigned long __must_check
19623 copy_from_user(void *to, const void __user *from, unsigned long n)
19624 {
19625- int sz = __compiletime_object_size(to);
19626+ size_t sz = __compiletime_object_size(to);
19627
19628 might_fault();
19629
19630@@ -609,12 +677,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19631 * case, and do only runtime checking for non-constant sizes.
19632 */
19633
19634- if (likely(sz < 0 || sz >= n))
19635- n = _copy_from_user(to, from, n);
19636- else if(__builtin_constant_p(n))
19637- copy_from_user_overflow();
19638- else
19639- __copy_from_user_overflow(sz, n);
19640+ if (likely(sz != (size_t)-1 && sz < n)) {
19641+ if(__builtin_constant_p(n))
19642+ copy_from_user_overflow();
19643+ else
19644+ __copy_from_user_overflow(sz, n);
19645+ } if (access_ok(VERIFY_READ, from, n))
19646+ n = __copy_from_user(to, from, n);
19647+ else if ((long)n > 0)
19648+ memset(to, 0, n);
19649
19650 return n;
19651 }
19652@@ -622,17 +693,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19653 static inline unsigned long __must_check
19654 copy_to_user(void __user *to, const void *from, unsigned long n)
19655 {
19656- int sz = __compiletime_object_size(from);
19657+ size_t sz = __compiletime_object_size(from);
19658
19659 might_fault();
19660
19661 /* See the comment in copy_from_user() above. */
19662- if (likely(sz < 0 || sz >= n))
19663- n = _copy_to_user(to, from, n);
19664- else if(__builtin_constant_p(n))
19665- copy_to_user_overflow();
19666- else
19667- __copy_to_user_overflow(sz, n);
19668+ if (likely(sz != (size_t)-1 && sz < n)) {
19669+ if(__builtin_constant_p(n))
19670+ copy_to_user_overflow();
19671+ else
19672+ __copy_to_user_overflow(sz, n);
19673+ } else if (access_ok(VERIFY_WRITE, to, n))
19674+ n = __copy_to_user(to, from, n);
19675
19676 return n;
19677 }
19678diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19679index 3c03a5d..1071638 100644
19680--- a/arch/x86/include/asm/uaccess_32.h
19681+++ b/arch/x86/include/asm/uaccess_32.h
19682@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19683 static __always_inline unsigned long __must_check
19684 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19685 {
19686+ if ((long)n < 0)
19687+ return n;
19688+
19689+ check_object_size(from, n, true);
19690+
19691 if (__builtin_constant_p(n)) {
19692 unsigned long ret;
19693
19694@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
19695 __copy_to_user(void __user *to, const void *from, unsigned long n)
19696 {
19697 might_fault();
19698+
19699 return __copy_to_user_inatomic(to, from, n);
19700 }
19701
19702 static __always_inline unsigned long
19703 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
19704 {
19705+ if ((long)n < 0)
19706+ return n;
19707+
19708 /* Avoid zeroing the tail if the copy fails..
19709 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
19710 * but as the zeroing behaviour is only significant when n is not
19711@@ -137,6 +146,12 @@ static __always_inline unsigned long
19712 __copy_from_user(void *to, const void __user *from, unsigned long n)
19713 {
19714 might_fault();
19715+
19716+ if ((long)n < 0)
19717+ return n;
19718+
19719+ check_object_size(to, n, false);
19720+
19721 if (__builtin_constant_p(n)) {
19722 unsigned long ret;
19723
19724@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
19725 const void __user *from, unsigned long n)
19726 {
19727 might_fault();
19728+
19729+ if ((long)n < 0)
19730+ return n;
19731+
19732 if (__builtin_constant_p(n)) {
19733 unsigned long ret;
19734
19735@@ -181,7 +200,10 @@ static __always_inline unsigned long
19736 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
19737 unsigned long n)
19738 {
19739- return __copy_from_user_ll_nocache_nozero(to, from, n);
19740+ if ((long)n < 0)
19741+ return n;
19742+
19743+ return __copy_from_user_ll_nocache_nozero(to, from, n);
19744 }
19745
19746 #endif /* _ASM_X86_UACCESS_32_H */
19747diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19748index 190413d..206c200 100644
19749--- a/arch/x86/include/asm/uaccess_64.h
19750+++ b/arch/x86/include/asm/uaccess_64.h
19751@@ -10,6 +10,9 @@
19752 #include <asm/alternative.h>
19753 #include <asm/cpufeature.h>
19754 #include <asm/page.h>
19755+#include <asm/pgtable.h>
19756+
19757+#define set_fs(x) (current_thread_info()->addr_limit = (x))
19758
19759 /*
19760 * Copy To/From Userspace
19761@@ -17,14 +20,14 @@
19762
19763 /* Handles exceptions in both to and from, but doesn't do access_ok */
19764 __must_check unsigned long
19765-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19766+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19767 __must_check unsigned long
19768-copy_user_generic_string(void *to, const void *from, unsigned len);
19769+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19770 __must_check unsigned long
19771-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19772+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19773
19774 static __always_inline __must_check unsigned long
19775-copy_user_generic(void *to, const void *from, unsigned len)
19776+copy_user_generic(void *to, const void *from, unsigned long len)
19777 {
19778 unsigned ret;
19779
19780@@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
19781 }
19782
19783 __must_check unsigned long
19784-copy_in_user(void __user *to, const void __user *from, unsigned len);
19785+copy_in_user(void __user *to, const void __user *from, unsigned long len);
19786
19787 static __always_inline __must_check
19788-int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
19789+unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
19790 {
19791- int ret = 0;
19792+ size_t sz = __compiletime_object_size(dst);
19793+ unsigned ret = 0;
19794+
19795+ if (size > INT_MAX)
19796+ return size;
19797+
19798+ check_object_size(dst, size, false);
19799+
19800+#ifdef CONFIG_PAX_MEMORY_UDEREF
19801+ if (!access_ok_noprefault(VERIFY_READ, src, size))
19802+ return size;
19803+#endif
19804+
19805+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19806+ if(__builtin_constant_p(size))
19807+ copy_from_user_overflow();
19808+ else
19809+ __copy_from_user_overflow(sz, size);
19810+ return size;
19811+ }
19812
19813 if (!__builtin_constant_p(size))
19814- return copy_user_generic(dst, (__force void *)src, size);
19815+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19816 switch (size) {
19817- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19818+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19819 ret, "b", "b", "=q", 1);
19820 return ret;
19821- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19822+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19823 ret, "w", "w", "=r", 2);
19824 return ret;
19825- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19826+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19827 ret, "l", "k", "=r", 4);
19828 return ret;
19829- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19830+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19831 ret, "q", "", "=r", 8);
19832 return ret;
19833 case 10:
19834- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19835+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19836 ret, "q", "", "=r", 10);
19837 if (unlikely(ret))
19838 return ret;
19839 __get_user_asm(*(u16 *)(8 + (char *)dst),
19840- (u16 __user *)(8 + (char __user *)src),
19841+ (const u16 __user *)(8 + (const char __user *)src),
19842 ret, "w", "w", "=r", 2);
19843 return ret;
19844 case 16:
19845- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19846+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19847 ret, "q", "", "=r", 16);
19848 if (unlikely(ret))
19849 return ret;
19850 __get_user_asm(*(u64 *)(8 + (char *)dst),
19851- (u64 __user *)(8 + (char __user *)src),
19852+ (const u64 __user *)(8 + (const char __user *)src),
19853 ret, "q", "", "=r", 8);
19854 return ret;
19855 default:
19856- return copy_user_generic(dst, (__force void *)src, size);
19857+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19858 }
19859 }
19860
19861 static __always_inline __must_check
19862-int __copy_from_user(void *dst, const void __user *src, unsigned size)
19863+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
19864 {
19865 might_fault();
19866 return __copy_from_user_nocheck(dst, src, size);
19867 }
19868
19869 static __always_inline __must_check
19870-int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
19871+unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
19872 {
19873- int ret = 0;
19874+ size_t sz = __compiletime_object_size(src);
19875+ unsigned ret = 0;
19876+
19877+ if (size > INT_MAX)
19878+ return size;
19879+
19880+ check_object_size(src, size, true);
19881+
19882+#ifdef CONFIG_PAX_MEMORY_UDEREF
19883+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19884+ return size;
19885+#endif
19886+
19887+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19888+ if(__builtin_constant_p(size))
19889+ copy_to_user_overflow();
19890+ else
19891+ __copy_to_user_overflow(sz, size);
19892+ return size;
19893+ }
19894
19895 if (!__builtin_constant_p(size))
19896- return copy_user_generic((__force void *)dst, src, size);
19897+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19898 switch (size) {
19899- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
19900+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
19901 ret, "b", "b", "iq", 1);
19902 return ret;
19903- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
19904+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
19905 ret, "w", "w", "ir", 2);
19906 return ret;
19907- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
19908+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
19909 ret, "l", "k", "ir", 4);
19910 return ret;
19911- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
19912+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19913 ret, "q", "", "er", 8);
19914 return ret;
19915 case 10:
19916- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19917+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19918 ret, "q", "", "er", 10);
19919 if (unlikely(ret))
19920 return ret;
19921 asm("":::"memory");
19922- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
19923+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
19924 ret, "w", "w", "ir", 2);
19925 return ret;
19926 case 16:
19927- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19928+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19929 ret, "q", "", "er", 16);
19930 if (unlikely(ret))
19931 return ret;
19932 asm("":::"memory");
19933- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
19934+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
19935 ret, "q", "", "er", 8);
19936 return ret;
19937 default:
19938- return copy_user_generic((__force void *)dst, src, size);
19939+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19940 }
19941 }
19942
19943 static __always_inline __must_check
19944-int __copy_to_user(void __user *dst, const void *src, unsigned size)
19945+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
19946 {
19947 might_fault();
19948 return __copy_to_user_nocheck(dst, src, size);
19949 }
19950
19951 static __always_inline __must_check
19952-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19953+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19954 {
19955- int ret = 0;
19956+ unsigned ret = 0;
19957
19958 might_fault();
19959+
19960+ if (size > INT_MAX)
19961+ return size;
19962+
19963+#ifdef CONFIG_PAX_MEMORY_UDEREF
19964+ if (!access_ok_noprefault(VERIFY_READ, src, size))
19965+ return size;
19966+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19967+ return size;
19968+#endif
19969+
19970 if (!__builtin_constant_p(size))
19971- return copy_user_generic((__force void *)dst,
19972- (__force void *)src, size);
19973+ return copy_user_generic((__force_kernel void *)____m(dst),
19974+ (__force_kernel const void *)____m(src), size);
19975 switch (size) {
19976 case 1: {
19977 u8 tmp;
19978- __get_user_asm(tmp, (u8 __user *)src,
19979+ __get_user_asm(tmp, (const u8 __user *)src,
19980 ret, "b", "b", "=q", 1);
19981 if (likely(!ret))
19982 __put_user_asm(tmp, (u8 __user *)dst,
19983@@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19984 }
19985 case 2: {
19986 u16 tmp;
19987- __get_user_asm(tmp, (u16 __user *)src,
19988+ __get_user_asm(tmp, (const u16 __user *)src,
19989 ret, "w", "w", "=r", 2);
19990 if (likely(!ret))
19991 __put_user_asm(tmp, (u16 __user *)dst,
19992@@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19993
19994 case 4: {
19995 u32 tmp;
19996- __get_user_asm(tmp, (u32 __user *)src,
19997+ __get_user_asm(tmp, (const u32 __user *)src,
19998 ret, "l", "k", "=r", 4);
19999 if (likely(!ret))
20000 __put_user_asm(tmp, (u32 __user *)dst,
20001@@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20002 }
20003 case 8: {
20004 u64 tmp;
20005- __get_user_asm(tmp, (u64 __user *)src,
20006+ __get_user_asm(tmp, (const u64 __user *)src,
20007 ret, "q", "", "=r", 8);
20008 if (likely(!ret))
20009 __put_user_asm(tmp, (u64 __user *)dst,
20010@@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20011 return ret;
20012 }
20013 default:
20014- return copy_user_generic((__force void *)dst,
20015- (__force void *)src, size);
20016+ return copy_user_generic((__force_kernel void *)____m(dst),
20017+ (__force_kernel const void *)____m(src), size);
20018 }
20019 }
20020
20021-static __must_check __always_inline int
20022-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20023+static __must_check __always_inline unsigned long
20024+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20025 {
20026- return __copy_from_user_nocheck(dst, (__force const void *)src, size);
20027+ return __copy_from_user_nocheck(dst, src, size);
20028 }
20029
20030-static __must_check __always_inline int
20031-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20032+static __must_check __always_inline unsigned long
20033+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20034 {
20035- return __copy_to_user_nocheck((__force void *)dst, src, size);
20036+ return __copy_to_user_nocheck(dst, src, size);
20037 }
20038
20039-extern long __copy_user_nocache(void *dst, const void __user *src,
20040- unsigned size, int zerorest);
20041+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20042+ unsigned long size, int zerorest);
20043
20044-static inline int
20045-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20046+static inline unsigned long
20047+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20048 {
20049 might_fault();
20050+
20051+ if (size > INT_MAX)
20052+ return size;
20053+
20054+#ifdef CONFIG_PAX_MEMORY_UDEREF
20055+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20056+ return size;
20057+#endif
20058+
20059 return __copy_user_nocache(dst, src, size, 1);
20060 }
20061
20062-static inline int
20063+static inline unsigned long
20064 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20065- unsigned size)
20066+ unsigned long size)
20067 {
20068+ if (size > INT_MAX)
20069+ return size;
20070+
20071+#ifdef CONFIG_PAX_MEMORY_UDEREF
20072+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20073+ return size;
20074+#endif
20075+
20076 return __copy_user_nocache(dst, src, size, 0);
20077 }
20078
20079 unsigned long
20080-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20081+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20082
20083 #endif /* _ASM_X86_UACCESS_64_H */
20084diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20085index 5b238981..77fdd78 100644
20086--- a/arch/x86/include/asm/word-at-a-time.h
20087+++ b/arch/x86/include/asm/word-at-a-time.h
20088@@ -11,7 +11,7 @@
20089 * and shift, for example.
20090 */
20091 struct word_at_a_time {
20092- const unsigned long one_bits, high_bits;
20093+ unsigned long one_bits, high_bits;
20094 };
20095
20096 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20097diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20098index 0f1be11..f7542bf 100644
20099--- a/arch/x86/include/asm/x86_init.h
20100+++ b/arch/x86/include/asm/x86_init.h
20101@@ -129,7 +129,7 @@ struct x86_init_ops {
20102 struct x86_init_timers timers;
20103 struct x86_init_iommu iommu;
20104 struct x86_init_pci pci;
20105-};
20106+} __no_const;
20107
20108 /**
20109 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20110@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20111 void (*setup_percpu_clockev)(void);
20112 void (*early_percpu_clock_init)(void);
20113 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20114-};
20115+} __no_const;
20116
20117 struct timespec;
20118
20119@@ -168,7 +168,7 @@ struct x86_platform_ops {
20120 void (*save_sched_clock_state)(void);
20121 void (*restore_sched_clock_state)(void);
20122 void (*apic_post_init)(void);
20123-};
20124+} __no_const;
20125
20126 struct pci_dev;
20127 struct msi_msg;
20128@@ -185,7 +185,7 @@ struct x86_msi_ops {
20129 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20130 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20131 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20132-};
20133+} __no_const;
20134
20135 struct IO_APIC_route_entry;
20136 struct io_apic_irq_attr;
20137@@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20138 unsigned int destination, int vector,
20139 struct io_apic_irq_attr *attr);
20140 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20141-};
20142+} __no_const;
20143
20144 extern struct x86_init_ops x86_init;
20145 extern struct x86_cpuinit_ops x86_cpuinit;
20146diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20147index b913915..4f5a581 100644
20148--- a/arch/x86/include/asm/xen/page.h
20149+++ b/arch/x86/include/asm/xen/page.h
20150@@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
20151 extern struct page *m2p_find_override(unsigned long mfn);
20152 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20153
20154-static inline unsigned long pfn_to_mfn(unsigned long pfn)
20155+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20156 {
20157 unsigned long mfn;
20158
20159diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20160index 0415cda..3b22adc 100644
20161--- a/arch/x86/include/asm/xsave.h
20162+++ b/arch/x86/include/asm/xsave.h
20163@@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20164 if (unlikely(err))
20165 return -EFAULT;
20166
20167+ pax_open_userland();
20168 __asm__ __volatile__(ASM_STAC "\n"
20169- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20170+ "1:"
20171+ __copyuser_seg
20172+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20173 "2: " ASM_CLAC "\n"
20174 ".section .fixup,\"ax\"\n"
20175 "3: movl $-1,%[err]\n"
20176@@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20177 : [err] "=r" (err)
20178 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20179 : "memory");
20180+ pax_close_userland();
20181 return err;
20182 }
20183
20184 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20185 {
20186 int err;
20187- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20188+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20189 u32 lmask = mask;
20190 u32 hmask = mask >> 32;
20191
20192+ pax_open_userland();
20193 __asm__ __volatile__(ASM_STAC "\n"
20194- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20195+ "1:"
20196+ __copyuser_seg
20197+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20198 "2: " ASM_CLAC "\n"
20199 ".section .fixup,\"ax\"\n"
20200 "3: movl $-1,%[err]\n"
20201@@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20202 : [err] "=r" (err)
20203 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20204 : "memory"); /* memory required? */
20205+ pax_close_userland();
20206 return err;
20207 }
20208
20209diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20210index bbae024..e1528f9 100644
20211--- a/arch/x86/include/uapi/asm/e820.h
20212+++ b/arch/x86/include/uapi/asm/e820.h
20213@@ -63,7 +63,7 @@ struct e820map {
20214 #define ISA_START_ADDRESS 0xa0000
20215 #define ISA_END_ADDRESS 0x100000
20216
20217-#define BIOS_BEGIN 0x000a0000
20218+#define BIOS_BEGIN 0x000c0000
20219 #define BIOS_END 0x00100000
20220
20221 #define BIOS_ROM_BASE 0xffe00000
20222diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20223index 7b0a55a..ad115bf 100644
20224--- a/arch/x86/include/uapi/asm/ptrace-abi.h
20225+++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20226@@ -49,7 +49,6 @@
20227 #define EFLAGS 144
20228 #define RSP 152
20229 #define SS 160
20230-#define ARGOFFSET R11
20231 #endif /* __ASSEMBLY__ */
20232
20233 /* top of stack page */
20234diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20235index 9b0a34e..fc7e553 100644
20236--- a/arch/x86/kernel/Makefile
20237+++ b/arch/x86/kernel/Makefile
20238@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20239 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20240 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20241 obj-y += probe_roms.o
20242-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20243+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20244 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20245 obj-y += syscall_$(BITS).o
20246 obj-$(CONFIG_X86_64) += vsyscall_64.o
20247diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20248index 6c0b43b..e67bb31 100644
20249--- a/arch/x86/kernel/acpi/boot.c
20250+++ b/arch/x86/kernel/acpi/boot.c
20251@@ -1315,7 +1315,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20252 * If your system is blacklisted here, but you find that acpi=force
20253 * works for you, please contact linux-acpi@vger.kernel.org
20254 */
20255-static struct dmi_system_id __initdata acpi_dmi_table[] = {
20256+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20257 /*
20258 * Boxes that need ACPI disabled
20259 */
20260@@ -1390,7 +1390,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20261 };
20262
20263 /* second table for DMI checks that should run after early-quirks */
20264-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20265+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20266 /*
20267 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20268 * which includes some code which overrides all temperature
20269diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20270index 3a2ae4c..9db31d6 100644
20271--- a/arch/x86/kernel/acpi/sleep.c
20272+++ b/arch/x86/kernel/acpi/sleep.c
20273@@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20274 #else /* CONFIG_64BIT */
20275 #ifdef CONFIG_SMP
20276 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20277+
20278+ pax_open_kernel();
20279 early_gdt_descr.address =
20280 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20281+ pax_close_kernel();
20282+
20283 initial_gs = per_cpu_offset(smp_processor_id());
20284 #endif
20285 initial_code = (unsigned long)wakeup_long64;
20286diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20287index 665c6b7..eae4d56 100644
20288--- a/arch/x86/kernel/acpi/wakeup_32.S
20289+++ b/arch/x86/kernel/acpi/wakeup_32.S
20290@@ -29,13 +29,11 @@ wakeup_pmode_return:
20291 # and restore the stack ... but you need gdt for this to work
20292 movl saved_context_esp, %esp
20293
20294- movl %cs:saved_magic, %eax
20295- cmpl $0x12345678, %eax
20296+ cmpl $0x12345678, saved_magic
20297 jne bogus_magic
20298
20299 # jump to place where we left off
20300- movl saved_eip, %eax
20301- jmp *%eax
20302+ jmp *(saved_eip)
20303
20304 bogus_magic:
20305 jmp bogus_magic
20306diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20307index df94598..f3b29bf 100644
20308--- a/arch/x86/kernel/alternative.c
20309+++ b/arch/x86/kernel/alternative.c
20310@@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20311 */
20312 for (a = start; a < end; a++) {
20313 instr = (u8 *)&a->instr_offset + a->instr_offset;
20314+
20315+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20316+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20317+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20318+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20319+#endif
20320+
20321 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20322 BUG_ON(a->replacementlen > a->instrlen);
20323 BUG_ON(a->instrlen > sizeof(insnbuf));
20324@@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20325 for (poff = start; poff < end; poff++) {
20326 u8 *ptr = (u8 *)poff + *poff;
20327
20328+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20329+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20330+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20331+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20332+#endif
20333+
20334 if (!*poff || ptr < text || ptr >= text_end)
20335 continue;
20336 /* turn DS segment override prefix into lock prefix */
20337- if (*ptr == 0x3e)
20338+ if (*ktla_ktva(ptr) == 0x3e)
20339 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20340 }
20341 mutex_unlock(&text_mutex);
20342@@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20343 for (poff = start; poff < end; poff++) {
20344 u8 *ptr = (u8 *)poff + *poff;
20345
20346+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20347+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20348+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20349+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20350+#endif
20351+
20352 if (!*poff || ptr < text || ptr >= text_end)
20353 continue;
20354 /* turn lock prefix into DS segment override prefix */
20355- if (*ptr == 0xf0)
20356+ if (*ktla_ktva(ptr) == 0xf0)
20357 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20358 }
20359 mutex_unlock(&text_mutex);
20360@@ -458,7 +477,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20361
20362 BUG_ON(p->len > MAX_PATCH_LEN);
20363 /* prep the buffer with the original instructions */
20364- memcpy(insnbuf, p->instr, p->len);
20365+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20366 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20367 (unsigned long)p->instr, p->len);
20368
20369@@ -505,7 +524,7 @@ void __init alternative_instructions(void)
20370 if (!uniproc_patched || num_possible_cpus() == 1)
20371 free_init_pages("SMP alternatives",
20372 (unsigned long)__smp_locks,
20373- (unsigned long)__smp_locks_end);
20374+ PAGE_ALIGN((unsigned long)__smp_locks_end));
20375 #endif
20376
20377 apply_paravirt(__parainstructions, __parainstructions_end);
20378@@ -525,13 +544,17 @@ void __init alternative_instructions(void)
20379 * instructions. And on the local CPU you need to be protected again NMI or MCE
20380 * handlers seeing an inconsistent instruction while you patch.
20381 */
20382-void *__init_or_module text_poke_early(void *addr, const void *opcode,
20383+void *__kprobes text_poke_early(void *addr, const void *opcode,
20384 size_t len)
20385 {
20386 unsigned long flags;
20387 local_irq_save(flags);
20388- memcpy(addr, opcode, len);
20389+
20390+ pax_open_kernel();
20391+ memcpy(ktla_ktva(addr), opcode, len);
20392 sync_core();
20393+ pax_close_kernel();
20394+
20395 local_irq_restore(flags);
20396 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20397 that causes hangs on some VIA CPUs. */
20398@@ -553,36 +576,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20399 */
20400 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
20401 {
20402- unsigned long flags;
20403- char *vaddr;
20404+ unsigned char *vaddr = ktla_ktva(addr);
20405 struct page *pages[2];
20406- int i;
20407+ size_t i;
20408
20409 if (!core_kernel_text((unsigned long)addr)) {
20410- pages[0] = vmalloc_to_page(addr);
20411- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20412+ pages[0] = vmalloc_to_page(vaddr);
20413+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20414 } else {
20415- pages[0] = virt_to_page(addr);
20416+ pages[0] = virt_to_page(vaddr);
20417 WARN_ON(!PageReserved(pages[0]));
20418- pages[1] = virt_to_page(addr + PAGE_SIZE);
20419+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20420 }
20421 BUG_ON(!pages[0]);
20422- local_irq_save(flags);
20423- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20424- if (pages[1])
20425- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20426- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20427- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20428- clear_fixmap(FIX_TEXT_POKE0);
20429- if (pages[1])
20430- clear_fixmap(FIX_TEXT_POKE1);
20431- local_flush_tlb();
20432- sync_core();
20433- /* Could also do a CLFLUSH here to speed up CPU recovery; but
20434- that causes hangs on some VIA CPUs. */
20435+ text_poke_early(addr, opcode, len);
20436 for (i = 0; i < len; i++)
20437- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20438- local_irq_restore(flags);
20439+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20440 return addr;
20441 }
20442
20443@@ -602,7 +611,7 @@ int poke_int3_handler(struct pt_regs *regs)
20444 if (likely(!bp_patching_in_progress))
20445 return 0;
20446
20447- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20448+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20449 return 0;
20450
20451 /* set up the specified breakpoint handler */
20452@@ -636,7 +645,7 @@ int poke_int3_handler(struct pt_regs *regs)
20453 */
20454 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20455 {
20456- unsigned char int3 = 0xcc;
20457+ const unsigned char int3 = 0xcc;
20458
20459 bp_int3_handler = handler;
20460 bp_int3_addr = (u8 *)addr + sizeof(int3);
20461diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20462index d278736..0b4af9a8 100644
20463--- a/arch/x86/kernel/apic/apic.c
20464+++ b/arch/x86/kernel/apic/apic.c
20465@@ -191,7 +191,7 @@ int first_system_vector = 0xfe;
20466 /*
20467 * Debug level, exported for io_apic.c
20468 */
20469-unsigned int apic_verbosity;
20470+int apic_verbosity;
20471
20472 int pic_mode;
20473
20474@@ -1986,7 +1986,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20475 apic_write(APIC_ESR, 0);
20476 v1 = apic_read(APIC_ESR);
20477 ack_APIC_irq();
20478- atomic_inc(&irq_err_count);
20479+ atomic_inc_unchecked(&irq_err_count);
20480
20481 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
20482 smp_processor_id(), v0 , v1);
20483diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20484index 00c77cf..2dc6a2d 100644
20485--- a/arch/x86/kernel/apic/apic_flat_64.c
20486+++ b/arch/x86/kernel/apic/apic_flat_64.c
20487@@ -157,7 +157,7 @@ static int flat_probe(void)
20488 return 1;
20489 }
20490
20491-static struct apic apic_flat = {
20492+static struct apic apic_flat __read_only = {
20493 .name = "flat",
20494 .probe = flat_probe,
20495 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20496@@ -271,7 +271,7 @@ static int physflat_probe(void)
20497 return 0;
20498 }
20499
20500-static struct apic apic_physflat = {
20501+static struct apic apic_physflat __read_only = {
20502
20503 .name = "physical flat",
20504 .probe = physflat_probe,
20505diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20506index e145f28..2752888 100644
20507--- a/arch/x86/kernel/apic/apic_noop.c
20508+++ b/arch/x86/kernel/apic/apic_noop.c
20509@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
20510 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20511 }
20512
20513-struct apic apic_noop = {
20514+struct apic apic_noop __read_only = {
20515 .name = "noop",
20516 .probe = noop_probe,
20517 .acpi_madt_oem_check = NULL,
20518diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20519index d50e364..543bee3 100644
20520--- a/arch/x86/kernel/apic/bigsmp_32.c
20521+++ b/arch/x86/kernel/apic/bigsmp_32.c
20522@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
20523 return dmi_bigsmp;
20524 }
20525
20526-static struct apic apic_bigsmp = {
20527+static struct apic apic_bigsmp __read_only = {
20528
20529 .name = "bigsmp",
20530 .probe = probe_bigsmp,
20531diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
20532index c552247..587a316 100644
20533--- a/arch/x86/kernel/apic/es7000_32.c
20534+++ b/arch/x86/kernel/apic/es7000_32.c
20535@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
20536 return ret && es7000_apic_is_cluster();
20537 }
20538
20539-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
20540-static struct apic __refdata apic_es7000_cluster = {
20541+static struct apic apic_es7000_cluster __read_only = {
20542
20543 .name = "es7000",
20544 .probe = probe_es7000,
20545@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
20546 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
20547 };
20548
20549-static struct apic __refdata apic_es7000 = {
20550+static struct apic apic_es7000 __read_only = {
20551
20552 .name = "es7000",
20553 .probe = probe_es7000,
20554diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20555index e63a5bd..c0babf8 100644
20556--- a/arch/x86/kernel/apic/io_apic.c
20557+++ b/arch/x86/kernel/apic/io_apic.c
20558@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20559 }
20560 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20561
20562-void lock_vector_lock(void)
20563+void lock_vector_lock(void) __acquires(vector_lock)
20564 {
20565 /* Used to the online set of cpus does not change
20566 * during assign_irq_vector.
20567@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
20568 raw_spin_lock(&vector_lock);
20569 }
20570
20571-void unlock_vector_lock(void)
20572+void unlock_vector_lock(void) __releases(vector_lock)
20573 {
20574 raw_spin_unlock(&vector_lock);
20575 }
20576@@ -2367,7 +2367,7 @@ static void ack_apic_edge(struct irq_data *data)
20577 ack_APIC_irq();
20578 }
20579
20580-atomic_t irq_mis_count;
20581+atomic_unchecked_t irq_mis_count;
20582
20583 #ifdef CONFIG_GENERIC_PENDING_IRQ
20584 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20585@@ -2508,7 +2508,7 @@ static void ack_apic_level(struct irq_data *data)
20586 * at the cpu.
20587 */
20588 if (!(v & (1 << (i & 0x1f)))) {
20589- atomic_inc(&irq_mis_count);
20590+ atomic_inc_unchecked(&irq_mis_count);
20591
20592 eoi_ioapic_irq(irq, cfg);
20593 }
20594diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
20595index 1e42e8f..daacf44 100644
20596--- a/arch/x86/kernel/apic/numaq_32.c
20597+++ b/arch/x86/kernel/apic/numaq_32.c
20598@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
20599 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
20600 }
20601
20602-/* Use __refdata to keep false positive warning calm. */
20603-static struct apic __refdata apic_numaq = {
20604+static struct apic apic_numaq __read_only = {
20605
20606 .name = "NUMAQ",
20607 .probe = probe_numaq,
20608diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20609index eb35ef9..f184a21 100644
20610--- a/arch/x86/kernel/apic/probe_32.c
20611+++ b/arch/x86/kernel/apic/probe_32.c
20612@@ -72,7 +72,7 @@ static int probe_default(void)
20613 return 1;
20614 }
20615
20616-static struct apic apic_default = {
20617+static struct apic apic_default __read_only = {
20618
20619 .name = "default",
20620 .probe = probe_default,
20621diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
20622index 77c95c0..434f8a4 100644
20623--- a/arch/x86/kernel/apic/summit_32.c
20624+++ b/arch/x86/kernel/apic/summit_32.c
20625@@ -486,7 +486,7 @@ void setup_summit(void)
20626 }
20627 #endif
20628
20629-static struct apic apic_summit = {
20630+static struct apic apic_summit __read_only = {
20631
20632 .name = "summit",
20633 .probe = probe_summit,
20634diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20635index 140e29d..d88bc95 100644
20636--- a/arch/x86/kernel/apic/x2apic_cluster.c
20637+++ b/arch/x86/kernel/apic/x2apic_cluster.c
20638@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20639 return notifier_from_errno(err);
20640 }
20641
20642-static struct notifier_block __refdata x2apic_cpu_notifier = {
20643+static struct notifier_block x2apic_cpu_notifier = {
20644 .notifier_call = update_clusterinfo,
20645 };
20646
20647@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20648 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20649 }
20650
20651-static struct apic apic_x2apic_cluster = {
20652+static struct apic apic_x2apic_cluster __read_only = {
20653
20654 .name = "cluster x2apic",
20655 .probe = x2apic_cluster_probe,
20656diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20657index 562a76d..a003c0f 100644
20658--- a/arch/x86/kernel/apic/x2apic_phys.c
20659+++ b/arch/x86/kernel/apic/x2apic_phys.c
20660@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
20661 return apic == &apic_x2apic_phys;
20662 }
20663
20664-static struct apic apic_x2apic_phys = {
20665+static struct apic apic_x2apic_phys __read_only = {
20666
20667 .name = "physical x2apic",
20668 .probe = x2apic_phys_probe,
20669diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20670index ad0dc04..0d9cc56 100644
20671--- a/arch/x86/kernel/apic/x2apic_uv_x.c
20672+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20673@@ -350,7 +350,7 @@ static int uv_probe(void)
20674 return apic == &apic_x2apic_uv_x;
20675 }
20676
20677-static struct apic __refdata apic_x2apic_uv_x = {
20678+static struct apic apic_x2apic_uv_x __read_only = {
20679
20680 .name = "UV large system",
20681 .probe = uv_probe,
20682diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20683index 3ab0343..814c4787 100644
20684--- a/arch/x86/kernel/apm_32.c
20685+++ b/arch/x86/kernel/apm_32.c
20686@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20687 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20688 * even though they are called in protected mode.
20689 */
20690-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20691+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20692 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20693
20694 static const char driver_version[] = "1.16ac"; /* no spaces */
20695@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20696 BUG_ON(cpu != 0);
20697 gdt = get_cpu_gdt_table(cpu);
20698 save_desc_40 = gdt[0x40 / 8];
20699+
20700+ pax_open_kernel();
20701 gdt[0x40 / 8] = bad_bios_desc;
20702+ pax_close_kernel();
20703
20704 apm_irq_save(flags);
20705 APM_DO_SAVE_SEGS;
20706@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20707 &call->esi);
20708 APM_DO_RESTORE_SEGS;
20709 apm_irq_restore(flags);
20710+
20711+ pax_open_kernel();
20712 gdt[0x40 / 8] = save_desc_40;
20713+ pax_close_kernel();
20714+
20715 put_cpu();
20716
20717 return call->eax & 0xff;
20718@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20719 BUG_ON(cpu != 0);
20720 gdt = get_cpu_gdt_table(cpu);
20721 save_desc_40 = gdt[0x40 / 8];
20722+
20723+ pax_open_kernel();
20724 gdt[0x40 / 8] = bad_bios_desc;
20725+ pax_close_kernel();
20726
20727 apm_irq_save(flags);
20728 APM_DO_SAVE_SEGS;
20729@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20730 &call->eax);
20731 APM_DO_RESTORE_SEGS;
20732 apm_irq_restore(flags);
20733+
20734+ pax_open_kernel();
20735 gdt[0x40 / 8] = save_desc_40;
20736+ pax_close_kernel();
20737+
20738 put_cpu();
20739 return error;
20740 }
20741@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20742 * code to that CPU.
20743 */
20744 gdt = get_cpu_gdt_table(0);
20745+
20746+ pax_open_kernel();
20747 set_desc_base(&gdt[APM_CS >> 3],
20748 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20749 set_desc_base(&gdt[APM_CS_16 >> 3],
20750 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20751 set_desc_base(&gdt[APM_DS >> 3],
20752 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20753+ pax_close_kernel();
20754
20755 proc_create("apm", 0, NULL, &apm_file_ops);
20756
20757diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20758index 9f6b934..cf5ffb3 100644
20759--- a/arch/x86/kernel/asm-offsets.c
20760+++ b/arch/x86/kernel/asm-offsets.c
20761@@ -32,6 +32,8 @@ void common(void) {
20762 OFFSET(TI_flags, thread_info, flags);
20763 OFFSET(TI_status, thread_info, status);
20764 OFFSET(TI_addr_limit, thread_info, addr_limit);
20765+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20766+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20767
20768 BLANK();
20769 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20770@@ -52,8 +54,26 @@ void common(void) {
20771 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20772 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20773 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20774+
20775+#ifdef CONFIG_PAX_KERNEXEC
20776+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20777 #endif
20778
20779+#ifdef CONFIG_PAX_MEMORY_UDEREF
20780+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20781+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20782+#ifdef CONFIG_X86_64
20783+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20784+#endif
20785+#endif
20786+
20787+#endif
20788+
20789+ BLANK();
20790+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20791+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20792+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20793+
20794 #ifdef CONFIG_XEN
20795 BLANK();
20796 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20797diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20798index e7c798b..2b2019b 100644
20799--- a/arch/x86/kernel/asm-offsets_64.c
20800+++ b/arch/x86/kernel/asm-offsets_64.c
20801@@ -77,6 +77,7 @@ int main(void)
20802 BLANK();
20803 #undef ENTRY
20804
20805+ DEFINE(TSS_size, sizeof(struct tss_struct));
20806 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20807 BLANK();
20808
20809diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20810index 47b56a7..efc2bc6 100644
20811--- a/arch/x86/kernel/cpu/Makefile
20812+++ b/arch/x86/kernel/cpu/Makefile
20813@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20814 CFLAGS_REMOVE_perf_event.o = -pg
20815 endif
20816
20817-# Make sure load_percpu_segment has no stackprotector
20818-nostackp := $(call cc-option, -fno-stack-protector)
20819-CFLAGS_common.o := $(nostackp)
20820-
20821 obj-y := intel_cacheinfo.o scattered.o topology.o
20822 obj-y += proc.o capflags.o powerflags.o common.o
20823 obj-y += rdrand.o
20824diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20825index 59bfebc..d8f27bd 100644
20826--- a/arch/x86/kernel/cpu/amd.c
20827+++ b/arch/x86/kernel/cpu/amd.c
20828@@ -753,7 +753,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20829 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20830 {
20831 /* AMD errata T13 (order #21922) */
20832- if ((c->x86 == 6)) {
20833+ if (c->x86 == 6) {
20834 /* Duron Rev A0 */
20835 if (c->x86_model == 3 && c->x86_mask == 0)
20836 size = 64;
20837diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20838index fe2bdd0..77b0d1b 100644
20839--- a/arch/x86/kernel/cpu/common.c
20840+++ b/arch/x86/kernel/cpu/common.c
20841@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20842
20843 static const struct cpu_dev *this_cpu = &default_cpu;
20844
20845-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20846-#ifdef CONFIG_X86_64
20847- /*
20848- * We need valid kernel segments for data and code in long mode too
20849- * IRET will check the segment types kkeil 2000/10/28
20850- * Also sysret mandates a special GDT layout
20851- *
20852- * TLS descriptors are currently at a different place compared to i386.
20853- * Hopefully nobody expects them at a fixed place (Wine?)
20854- */
20855- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20856- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20857- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20858- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20859- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20860- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20861-#else
20862- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20863- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20864- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20865- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20866- /*
20867- * Segments used for calling PnP BIOS have byte granularity.
20868- * They code segments and data segments have fixed 64k limits,
20869- * the transfer segment sizes are set at run time.
20870- */
20871- /* 32-bit code */
20872- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20873- /* 16-bit code */
20874- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20875- /* 16-bit data */
20876- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20877- /* 16-bit data */
20878- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20879- /* 16-bit data */
20880- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20881- /*
20882- * The APM segments have byte granularity and their bases
20883- * are set at run time. All have 64k limits.
20884- */
20885- /* 32-bit code */
20886- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20887- /* 16-bit code */
20888- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20889- /* data */
20890- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20891-
20892- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20893- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20894- GDT_STACK_CANARY_INIT
20895-#endif
20896-} };
20897-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20898-
20899 static int __init x86_xsave_setup(char *s)
20900 {
20901 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20902@@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
20903 }
20904 }
20905
20906+#ifdef CONFIG_X86_64
20907+static __init int setup_disable_pcid(char *arg)
20908+{
20909+ setup_clear_cpu_cap(X86_FEATURE_PCID);
20910+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
20911+
20912+#ifdef CONFIG_PAX_MEMORY_UDEREF
20913+ if (clone_pgd_mask != ~(pgdval_t)0UL)
20914+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20915+#endif
20916+
20917+ return 1;
20918+}
20919+__setup("nopcid", setup_disable_pcid);
20920+
20921+static void setup_pcid(struct cpuinfo_x86 *c)
20922+{
20923+ if (!cpu_has(c, X86_FEATURE_PCID)) {
20924+ clear_cpu_cap(c, X86_FEATURE_INVPCID);
20925+
20926+#ifdef CONFIG_PAX_MEMORY_UDEREF
20927+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
20928+ pax_open_kernel();
20929+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20930+ pax_close_kernel();
20931+ printk("PAX: slow and weak UDEREF enabled\n");
20932+ } else
20933+ printk("PAX: UDEREF disabled\n");
20934+#endif
20935+
20936+ return;
20937+ }
20938+
20939+ printk("PAX: PCID detected\n");
20940+ set_in_cr4(X86_CR4_PCIDE);
20941+
20942+#ifdef CONFIG_PAX_MEMORY_UDEREF
20943+ pax_open_kernel();
20944+ clone_pgd_mask = ~(pgdval_t)0UL;
20945+ pax_close_kernel();
20946+ if (pax_user_shadow_base)
20947+ printk("PAX: weak UDEREF enabled\n");
20948+ else {
20949+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
20950+ printk("PAX: strong UDEREF enabled\n");
20951+ }
20952+#endif
20953+
20954+ if (cpu_has(c, X86_FEATURE_INVPCID))
20955+ printk("PAX: INVPCID detected\n");
20956+}
20957+#endif
20958+
20959 /*
20960 * Some CPU features depend on higher CPUID levels, which may not always
20961 * be available due to CPUID level capping or broken virtualization
20962@@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
20963 {
20964 struct desc_ptr gdt_descr;
20965
20966- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
20967+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20968 gdt_descr.size = GDT_SIZE - 1;
20969 load_gdt(&gdt_descr);
20970 /* Reload the per-cpu base */
20971@@ -882,6 +881,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20972 setup_smep(c);
20973 setup_smap(c);
20974
20975+#ifdef CONFIG_X86_64
20976+ setup_pcid(c);
20977+#endif
20978+
20979 /*
20980 * The vendor-specific functions might have changed features.
20981 * Now we do "generic changes."
20982@@ -890,6 +893,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20983 /* Filter out anything that depends on CPUID levels we don't have */
20984 filter_cpuid_features(c, true);
20985
20986+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20987+ setup_clear_cpu_cap(X86_FEATURE_SEP);
20988+#endif
20989+
20990 /* If the model name is still unset, do table lookup. */
20991 if (!c->x86_model_id[0]) {
20992 const char *p;
20993@@ -1077,10 +1084,12 @@ static __init int setup_disablecpuid(char *arg)
20994 }
20995 __setup("clearcpuid=", setup_disablecpuid);
20996
20997+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
20998+EXPORT_PER_CPU_SYMBOL(current_tinfo);
20999+
21000 #ifdef CONFIG_X86_64
21001-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21002-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21003- (unsigned long) debug_idt_table };
21004+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21005+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21006
21007 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21008 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21009@@ -1094,7 +1103,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
21010 EXPORT_PER_CPU_SYMBOL(current_task);
21011
21012 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21013- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21014+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21015 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21016
21017 DEFINE_PER_CPU(char *, irq_stack_ptr) =
21018@@ -1244,7 +1253,7 @@ void cpu_init(void)
21019 load_ucode_ap();
21020
21021 cpu = stack_smp_processor_id();
21022- t = &per_cpu(init_tss, cpu);
21023+ t = init_tss + cpu;
21024 oist = &per_cpu(orig_ist, cpu);
21025
21026 #ifdef CONFIG_NUMA
21027@@ -1279,7 +1288,6 @@ void cpu_init(void)
21028 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21029 barrier();
21030
21031- x86_configure_nx();
21032 enable_x2apic();
21033
21034 /*
21035@@ -1331,7 +1339,7 @@ void cpu_init(void)
21036 {
21037 int cpu = smp_processor_id();
21038 struct task_struct *curr = current;
21039- struct tss_struct *t = &per_cpu(init_tss, cpu);
21040+ struct tss_struct *t = init_tss + cpu;
21041 struct thread_struct *thread = &curr->thread;
21042
21043 show_ucode_info_early();
21044diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21045index 0641113..06f5ba4 100644
21046--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21047+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21048@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
21049 };
21050
21051 #ifdef CONFIG_AMD_NB
21052+static struct attribute *default_attrs_amd_nb[] = {
21053+ &type.attr,
21054+ &level.attr,
21055+ &coherency_line_size.attr,
21056+ &physical_line_partition.attr,
21057+ &ways_of_associativity.attr,
21058+ &number_of_sets.attr,
21059+ &size.attr,
21060+ &shared_cpu_map.attr,
21061+ &shared_cpu_list.attr,
21062+ NULL,
21063+ NULL,
21064+ NULL,
21065+ NULL
21066+};
21067+
21068 static struct attribute **amd_l3_attrs(void)
21069 {
21070 static struct attribute **attrs;
21071@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
21072
21073 n = ARRAY_SIZE(default_attrs);
21074
21075- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21076- n += 2;
21077-
21078- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21079- n += 1;
21080-
21081- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21082- if (attrs == NULL)
21083- return attrs = default_attrs;
21084-
21085- for (n = 0; default_attrs[n]; n++)
21086- attrs[n] = default_attrs[n];
21087+ attrs = default_attrs_amd_nb;
21088
21089 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21090 attrs[n++] = &cache_disable_0.attr;
21091@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
21092 .default_attrs = default_attrs,
21093 };
21094
21095+#ifdef CONFIG_AMD_NB
21096+static struct kobj_type ktype_cache_amd_nb = {
21097+ .sysfs_ops = &sysfs_ops,
21098+ .default_attrs = default_attrs_amd_nb,
21099+};
21100+#endif
21101+
21102 static struct kobj_type ktype_percpu_entry = {
21103 .sysfs_ops = &sysfs_ops,
21104 };
21105@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
21106 return retval;
21107 }
21108
21109+#ifdef CONFIG_AMD_NB
21110+ amd_l3_attrs();
21111+#endif
21112+
21113 for (i = 0; i < num_cache_leaves; i++) {
21114+ struct kobj_type *ktype;
21115+
21116 this_object = INDEX_KOBJECT_PTR(cpu, i);
21117 this_object->cpu = cpu;
21118 this_object->index = i;
21119
21120 this_leaf = CPUID4_INFO_IDX(cpu, i);
21121
21122- ktype_cache.default_attrs = default_attrs;
21123+ ktype = &ktype_cache;
21124 #ifdef CONFIG_AMD_NB
21125 if (this_leaf->base.nb)
21126- ktype_cache.default_attrs = amd_l3_attrs();
21127+ ktype = &ktype_cache_amd_nb;
21128 #endif
21129 retval = kobject_init_and_add(&(this_object->kobj),
21130- &ktype_cache,
21131+ ktype,
21132 per_cpu(ici_cache_kobject, cpu),
21133 "index%1lu", i);
21134 if (unlikely(retval)) {
21135diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21136index b3218cd..99a75de 100644
21137--- a/arch/x86/kernel/cpu/mcheck/mce.c
21138+++ b/arch/x86/kernel/cpu/mcheck/mce.c
21139@@ -45,6 +45,7 @@
21140 #include <asm/processor.h>
21141 #include <asm/mce.h>
21142 #include <asm/msr.h>
21143+#include <asm/local.h>
21144
21145 #include "mce-internal.h"
21146
21147@@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
21148 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21149 m->cs, m->ip);
21150
21151- if (m->cs == __KERNEL_CS)
21152+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21153 print_symbol("{%s}", m->ip);
21154 pr_cont("\n");
21155 }
21156@@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
21157
21158 #define PANIC_TIMEOUT 5 /* 5 seconds */
21159
21160-static atomic_t mce_paniced;
21161+static atomic_unchecked_t mce_paniced;
21162
21163 static int fake_panic;
21164-static atomic_t mce_fake_paniced;
21165+static atomic_unchecked_t mce_fake_paniced;
21166
21167 /* Panic in progress. Enable interrupts and wait for final IPI */
21168 static void wait_for_panic(void)
21169@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21170 /*
21171 * Make sure only one CPU runs in machine check panic
21172 */
21173- if (atomic_inc_return(&mce_paniced) > 1)
21174+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21175 wait_for_panic();
21176 barrier();
21177
21178@@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21179 console_verbose();
21180 } else {
21181 /* Don't log too much for fake panic */
21182- if (atomic_inc_return(&mce_fake_paniced) > 1)
21183+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21184 return;
21185 }
21186 /* First print corrected ones that are still unlogged */
21187@@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21188 if (!fake_panic) {
21189 if (panic_timeout == 0)
21190 panic_timeout = mca_cfg.panic_timeout;
21191- panic(msg);
21192+ panic("%s", msg);
21193 } else
21194 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21195 }
21196@@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
21197 * might have been modified by someone else.
21198 */
21199 rmb();
21200- if (atomic_read(&mce_paniced))
21201+ if (atomic_read_unchecked(&mce_paniced))
21202 wait_for_panic();
21203 if (!mca_cfg.monarch_timeout)
21204 goto out;
21205@@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21206 }
21207
21208 /* Call the installed machine check handler for this CPU setup. */
21209-void (*machine_check_vector)(struct pt_regs *, long error_code) =
21210+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21211 unexpected_machine_check;
21212
21213 /*
21214@@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21215 return;
21216 }
21217
21218+ pax_open_kernel();
21219 machine_check_vector = do_machine_check;
21220+ pax_close_kernel();
21221
21222 __mcheck_cpu_init_generic();
21223 __mcheck_cpu_init_vendor(c);
21224@@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21225 */
21226
21227 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21228-static int mce_chrdev_open_count; /* #times opened */
21229+static local_t mce_chrdev_open_count; /* #times opened */
21230 static int mce_chrdev_open_exclu; /* already open exclusive? */
21231
21232 static int mce_chrdev_open(struct inode *inode, struct file *file)
21233@@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21234 spin_lock(&mce_chrdev_state_lock);
21235
21236 if (mce_chrdev_open_exclu ||
21237- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21238+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21239 spin_unlock(&mce_chrdev_state_lock);
21240
21241 return -EBUSY;
21242@@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21243
21244 if (file->f_flags & O_EXCL)
21245 mce_chrdev_open_exclu = 1;
21246- mce_chrdev_open_count++;
21247+ local_inc(&mce_chrdev_open_count);
21248
21249 spin_unlock(&mce_chrdev_state_lock);
21250
21251@@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21252 {
21253 spin_lock(&mce_chrdev_state_lock);
21254
21255- mce_chrdev_open_count--;
21256+ local_dec(&mce_chrdev_open_count);
21257 mce_chrdev_open_exclu = 0;
21258
21259 spin_unlock(&mce_chrdev_state_lock);
21260@@ -2404,7 +2407,7 @@ static __init void mce_init_banks(void)
21261
21262 for (i = 0; i < mca_cfg.banks; i++) {
21263 struct mce_bank *b = &mce_banks[i];
21264- struct device_attribute *a = &b->attr;
21265+ device_attribute_no_const *a = &b->attr;
21266
21267 sysfs_attr_init(&a->attr);
21268 a->attr.name = b->attrname;
21269@@ -2472,7 +2475,7 @@ struct dentry *mce_get_debugfs_dir(void)
21270 static void mce_reset(void)
21271 {
21272 cpu_missing = 0;
21273- atomic_set(&mce_fake_paniced, 0);
21274+ atomic_set_unchecked(&mce_fake_paniced, 0);
21275 atomic_set(&mce_executing, 0);
21276 atomic_set(&mce_callin, 0);
21277 atomic_set(&global_nwo, 0);
21278diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21279index 1c044b1..37a2a43 100644
21280--- a/arch/x86/kernel/cpu/mcheck/p5.c
21281+++ b/arch/x86/kernel/cpu/mcheck/p5.c
21282@@ -11,6 +11,7 @@
21283 #include <asm/processor.h>
21284 #include <asm/mce.h>
21285 #include <asm/msr.h>
21286+#include <asm/pgtable.h>
21287
21288 /* By default disabled */
21289 int mce_p5_enabled __read_mostly;
21290@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21291 if (!cpu_has(c, X86_FEATURE_MCE))
21292 return;
21293
21294+ pax_open_kernel();
21295 machine_check_vector = pentium_machine_check;
21296+ pax_close_kernel();
21297 /* Make sure the vector pointer is visible before we enable MCEs: */
21298 wmb();
21299
21300diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21301index e9a701a..35317d6 100644
21302--- a/arch/x86/kernel/cpu/mcheck/winchip.c
21303+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21304@@ -10,6 +10,7 @@
21305 #include <asm/processor.h>
21306 #include <asm/mce.h>
21307 #include <asm/msr.h>
21308+#include <asm/pgtable.h>
21309
21310 /* Machine check handler for WinChip C6: */
21311 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21312@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21313 {
21314 u32 lo, hi;
21315
21316+ pax_open_kernel();
21317 machine_check_vector = winchip_machine_check;
21318+ pax_close_kernel();
21319 /* Make sure the vector pointer is visible before we enable MCEs: */
21320 wmb();
21321
21322diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21323index f961de9..8a9d332 100644
21324--- a/arch/x86/kernel/cpu/mtrr/main.c
21325+++ b/arch/x86/kernel/cpu/mtrr/main.c
21326@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21327 u64 size_or_mask, size_and_mask;
21328 static bool mtrr_aps_delayed_init;
21329
21330-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21331+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21332
21333 const struct mtrr_ops *mtrr_if;
21334
21335diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21336index df5e41f..816c719 100644
21337--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21338+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21339@@ -25,7 +25,7 @@ struct mtrr_ops {
21340 int (*validate_add_page)(unsigned long base, unsigned long size,
21341 unsigned int type);
21342 int (*have_wrcomb)(void);
21343-};
21344+} __do_const;
21345
21346 extern int generic_get_free_region(unsigned long base, unsigned long size,
21347 int replace_reg);
21348diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21349index db6cdbe..faaf834 100644
21350--- a/arch/x86/kernel/cpu/perf_event.c
21351+++ b/arch/x86/kernel/cpu/perf_event.c
21352@@ -1351,7 +1351,7 @@ static void __init pmu_check_apic(void)
21353 pr_info("no hardware sampling interrupt available.\n");
21354 }
21355
21356-static struct attribute_group x86_pmu_format_group = {
21357+static attribute_group_no_const x86_pmu_format_group = {
21358 .name = "format",
21359 .attrs = NULL,
21360 };
21361@@ -1450,7 +1450,7 @@ static struct attribute *events_attr[] = {
21362 NULL,
21363 };
21364
21365-static struct attribute_group x86_pmu_events_group = {
21366+static attribute_group_no_const x86_pmu_events_group = {
21367 .name = "events",
21368 .attrs = events_attr,
21369 };
21370@@ -1961,7 +1961,7 @@ static unsigned long get_segment_base(unsigned int segment)
21371 if (idx > GDT_ENTRIES)
21372 return 0;
21373
21374- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21375+ desc = get_cpu_gdt_table(smp_processor_id());
21376 }
21377
21378 return get_desc_base(desc + idx);
21379@@ -2051,7 +2051,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21380 break;
21381
21382 perf_callchain_store(entry, frame.return_address);
21383- fp = frame.next_frame;
21384+ fp = (const void __force_user *)frame.next_frame;
21385 }
21386 }
21387
21388diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21389index 639d128..e92d7e5 100644
21390--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21391+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21392@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21393 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21394 {
21395 struct attribute **attrs;
21396- struct attribute_group *attr_group;
21397+ attribute_group_no_const *attr_group;
21398 int i = 0, j;
21399
21400 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21401diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21402index 0fa4f24..17990ed 100644
21403--- a/arch/x86/kernel/cpu/perf_event_intel.c
21404+++ b/arch/x86/kernel/cpu/perf_event_intel.c
21405@@ -2314,10 +2314,10 @@ __init int intel_pmu_init(void)
21406 * v2 and above have a perf capabilities MSR
21407 */
21408 if (version > 1) {
21409- u64 capabilities;
21410+ u64 capabilities = x86_pmu.intel_cap.capabilities;
21411
21412- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21413- x86_pmu.intel_cap.capabilities = capabilities;
21414+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21415+ x86_pmu.intel_cap.capabilities = capabilities;
21416 }
21417
21418 intel_ds_init();
21419diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21420index 29c2487..a5606fa 100644
21421--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21422+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21423@@ -3318,7 +3318,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21424 static int __init uncore_type_init(struct intel_uncore_type *type)
21425 {
21426 struct intel_uncore_pmu *pmus;
21427- struct attribute_group *attr_group;
21428+ attribute_group_no_const *attr_group;
21429 struct attribute **attrs;
21430 int i, j;
21431
21432diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21433index a80ab71..4089da5 100644
21434--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21435+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21436@@ -498,7 +498,7 @@ struct intel_uncore_box {
21437 struct uncore_event_desc {
21438 struct kobj_attribute attr;
21439 const char *config;
21440-};
21441+} __do_const;
21442
21443 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
21444 { \
21445diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21446index 7d9481c..99c7e4b 100644
21447--- a/arch/x86/kernel/cpuid.c
21448+++ b/arch/x86/kernel/cpuid.c
21449@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21450 return notifier_from_errno(err);
21451 }
21452
21453-static struct notifier_block __refdata cpuid_class_cpu_notifier =
21454+static struct notifier_block cpuid_class_cpu_notifier =
21455 {
21456 .notifier_call = cpuid_class_cpu_callback,
21457 };
21458diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21459index 18677a9..f67c45b 100644
21460--- a/arch/x86/kernel/crash.c
21461+++ b/arch/x86/kernel/crash.c
21462@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21463 {
21464 #ifdef CONFIG_X86_32
21465 struct pt_regs fixed_regs;
21466-#endif
21467
21468-#ifdef CONFIG_X86_32
21469- if (!user_mode_vm(regs)) {
21470+ if (!user_mode(regs)) {
21471 crash_fixup_ss_esp(&fixed_regs, regs);
21472 regs = &fixed_regs;
21473 }
21474diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21475index afa64ad..dce67dd 100644
21476--- a/arch/x86/kernel/crash_dump_64.c
21477+++ b/arch/x86/kernel/crash_dump_64.c
21478@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21479 return -ENOMEM;
21480
21481 if (userbuf) {
21482- if (copy_to_user(buf, vaddr + offset, csize)) {
21483+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21484 iounmap(vaddr);
21485 return -EFAULT;
21486 }
21487diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21488index 5d3fe8d..02e1429 100644
21489--- a/arch/x86/kernel/doublefault.c
21490+++ b/arch/x86/kernel/doublefault.c
21491@@ -13,7 +13,7 @@
21492
21493 #define DOUBLEFAULT_STACKSIZE (1024)
21494 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21495-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21496+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21497
21498 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21499
21500@@ -23,7 +23,7 @@ static void doublefault_fn(void)
21501 unsigned long gdt, tss;
21502
21503 native_store_gdt(&gdt_desc);
21504- gdt = gdt_desc.address;
21505+ gdt = (unsigned long)gdt_desc.address;
21506
21507 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21508
21509@@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21510 /* 0x2 bit is always set */
21511 .flags = X86_EFLAGS_SF | 0x2,
21512 .sp = STACK_START,
21513- .es = __USER_DS,
21514+ .es = __KERNEL_DS,
21515 .cs = __KERNEL_CS,
21516 .ss = __KERNEL_DS,
21517- .ds = __USER_DS,
21518+ .ds = __KERNEL_DS,
21519 .fs = __KERNEL_PERCPU,
21520
21521 .__cr3 = __pa_nodebug(swapper_pg_dir),
21522diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21523index d9c12d3..7858b62 100644
21524--- a/arch/x86/kernel/dumpstack.c
21525+++ b/arch/x86/kernel/dumpstack.c
21526@@ -2,6 +2,9 @@
21527 * Copyright (C) 1991, 1992 Linus Torvalds
21528 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21529 */
21530+#ifdef CONFIG_GRKERNSEC_HIDESYM
21531+#define __INCLUDED_BY_HIDESYM 1
21532+#endif
21533 #include <linux/kallsyms.h>
21534 #include <linux/kprobes.h>
21535 #include <linux/uaccess.h>
21536@@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21537 static void
21538 print_ftrace_graph_addr(unsigned long addr, void *data,
21539 const struct stacktrace_ops *ops,
21540- struct thread_info *tinfo, int *graph)
21541+ struct task_struct *task, int *graph)
21542 {
21543- struct task_struct *task;
21544 unsigned long ret_addr;
21545 int index;
21546
21547 if (addr != (unsigned long)return_to_handler)
21548 return;
21549
21550- task = tinfo->task;
21551 index = task->curr_ret_stack;
21552
21553 if (!task->ret_stack || index < *graph)
21554@@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21555 static inline void
21556 print_ftrace_graph_addr(unsigned long addr, void *data,
21557 const struct stacktrace_ops *ops,
21558- struct thread_info *tinfo, int *graph)
21559+ struct task_struct *task, int *graph)
21560 { }
21561 #endif
21562
21563@@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21564 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21565 */
21566
21567-static inline int valid_stack_ptr(struct thread_info *tinfo,
21568- void *p, unsigned int size, void *end)
21569+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21570 {
21571- void *t = tinfo;
21572 if (end) {
21573 if (p < end && p >= (end-THREAD_SIZE))
21574 return 1;
21575@@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21576 }
21577
21578 unsigned long
21579-print_context_stack(struct thread_info *tinfo,
21580+print_context_stack(struct task_struct *task, void *stack_start,
21581 unsigned long *stack, unsigned long bp,
21582 const struct stacktrace_ops *ops, void *data,
21583 unsigned long *end, int *graph)
21584 {
21585 struct stack_frame *frame = (struct stack_frame *)bp;
21586
21587- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21588+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21589 unsigned long addr;
21590
21591 addr = *stack;
21592@@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21593 } else {
21594 ops->address(data, addr, 0);
21595 }
21596- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21597+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21598 }
21599 stack++;
21600 }
21601@@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21602 EXPORT_SYMBOL_GPL(print_context_stack);
21603
21604 unsigned long
21605-print_context_stack_bp(struct thread_info *tinfo,
21606+print_context_stack_bp(struct task_struct *task, void *stack_start,
21607 unsigned long *stack, unsigned long bp,
21608 const struct stacktrace_ops *ops, void *data,
21609 unsigned long *end, int *graph)
21610@@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21611 struct stack_frame *frame = (struct stack_frame *)bp;
21612 unsigned long *ret_addr = &frame->return_address;
21613
21614- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21615+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21616 unsigned long addr = *ret_addr;
21617
21618 if (!__kernel_text_address(addr))
21619@@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21620 ops->address(data, addr, 1);
21621 frame = frame->next_frame;
21622 ret_addr = &frame->return_address;
21623- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21624+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21625 }
21626
21627 return (unsigned long)frame;
21628@@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21629 static void print_trace_address(void *data, unsigned long addr, int reliable)
21630 {
21631 touch_nmi_watchdog();
21632- printk(data);
21633+ printk("%s", (char *)data);
21634 printk_stack_address(addr, reliable);
21635 }
21636
21637@@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
21638 }
21639 EXPORT_SYMBOL_GPL(oops_begin);
21640
21641+extern void gr_handle_kernel_exploit(void);
21642+
21643 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21644 {
21645 if (regs && kexec_should_crash(current))
21646@@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21647 panic("Fatal exception in interrupt");
21648 if (panic_on_oops)
21649 panic("Fatal exception");
21650- do_exit(signr);
21651+
21652+ gr_handle_kernel_exploit();
21653+
21654+ do_group_exit(signr);
21655 }
21656
21657 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21658@@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21659 print_modules();
21660 show_regs(regs);
21661 #ifdef CONFIG_X86_32
21662- if (user_mode_vm(regs)) {
21663+ if (user_mode(regs)) {
21664 sp = regs->sp;
21665 ss = regs->ss & 0xffff;
21666 } else {
21667@@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
21668 unsigned long flags = oops_begin();
21669 int sig = SIGSEGV;
21670
21671- if (!user_mode_vm(regs))
21672+ if (!user_mode(regs))
21673 report_bug(regs->ip, regs);
21674
21675 if (__die(str, regs, err))
21676diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21677index f2a1770..540657f 100644
21678--- a/arch/x86/kernel/dumpstack_32.c
21679+++ b/arch/x86/kernel/dumpstack_32.c
21680@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21681 bp = stack_frame(task, regs);
21682
21683 for (;;) {
21684- struct thread_info *context;
21685+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21686
21687- context = (struct thread_info *)
21688- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
21689- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
21690+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21691
21692- stack = (unsigned long *)context->previous_esp;
21693- if (!stack)
21694+ if (stack_start == task_stack_page(task))
21695 break;
21696+ stack = *(unsigned long **)stack_start;
21697 if (ops->stack(data, "IRQ") < 0)
21698 break;
21699 touch_nmi_watchdog();
21700@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
21701 int i;
21702
21703 show_regs_print_info(KERN_EMERG);
21704- __show_regs(regs, !user_mode_vm(regs));
21705+ __show_regs(regs, !user_mode(regs));
21706
21707 /*
21708 * When in-kernel, we also print out the stack and code at the
21709 * time of the fault..
21710 */
21711- if (!user_mode_vm(regs)) {
21712+ if (!user_mode(regs)) {
21713 unsigned int code_prologue = code_bytes * 43 / 64;
21714 unsigned int code_len = code_bytes;
21715 unsigned char c;
21716 u8 *ip;
21717+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21718
21719 pr_emerg("Stack:\n");
21720 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21721
21722 pr_emerg("Code:");
21723
21724- ip = (u8 *)regs->ip - code_prologue;
21725+ ip = (u8 *)regs->ip - code_prologue + cs_base;
21726 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21727 /* try starting at IP */
21728- ip = (u8 *)regs->ip;
21729+ ip = (u8 *)regs->ip + cs_base;
21730 code_len = code_len - code_prologue + 1;
21731 }
21732 for (i = 0; i < code_len; i++, ip++) {
21733@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
21734 pr_cont(" Bad EIP value.");
21735 break;
21736 }
21737- if (ip == (u8 *)regs->ip)
21738+ if (ip == (u8 *)regs->ip + cs_base)
21739 pr_cont(" <%02x>", c);
21740 else
21741 pr_cont(" %02x", c);
21742@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
21743 {
21744 unsigned short ud2;
21745
21746+ ip = ktla_ktva(ip);
21747 if (ip < PAGE_OFFSET)
21748 return 0;
21749 if (probe_kernel_address((unsigned short *)ip, ud2))
21750@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
21751
21752 return ud2 == 0x0b0f;
21753 }
21754+
21755+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21756+void pax_check_alloca(unsigned long size)
21757+{
21758+ unsigned long sp = (unsigned long)&sp, stack_left;
21759+
21760+ /* all kernel stacks are of the same size */
21761+ stack_left = sp & (THREAD_SIZE - 1);
21762+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21763+}
21764+EXPORT_SYMBOL(pax_check_alloca);
21765+#endif
21766diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21767index addb207..99635fa 100644
21768--- a/arch/x86/kernel/dumpstack_64.c
21769+++ b/arch/x86/kernel/dumpstack_64.c
21770@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21771 unsigned long *irq_stack_end =
21772 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21773 unsigned used = 0;
21774- struct thread_info *tinfo;
21775 int graph = 0;
21776 unsigned long dummy;
21777+ void *stack_start;
21778
21779 if (!task)
21780 task = current;
21781@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21782 * current stack address. If the stacks consist of nested
21783 * exceptions
21784 */
21785- tinfo = task_thread_info(task);
21786 for (;;) {
21787 char *id;
21788 unsigned long *estack_end;
21789+
21790 estack_end = in_exception_stack(cpu, (unsigned long)stack,
21791 &used, &id);
21792
21793@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21794 if (ops->stack(data, id) < 0)
21795 break;
21796
21797- bp = ops->walk_stack(tinfo, stack, bp, ops,
21798+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
21799 data, estack_end, &graph);
21800 ops->stack(data, "<EOE>");
21801 /*
21802@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21803 * second-to-last pointer (index -2 to end) in the
21804 * exception stack:
21805 */
21806+ if ((u16)estack_end[-1] != __KERNEL_DS)
21807+ goto out;
21808 stack = (unsigned long *) estack_end[-2];
21809 continue;
21810 }
21811@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21812 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
21813 if (ops->stack(data, "IRQ") < 0)
21814 break;
21815- bp = ops->walk_stack(tinfo, stack, bp,
21816+ bp = ops->walk_stack(task, irq_stack, stack, bp,
21817 ops, data, irq_stack_end, &graph);
21818 /*
21819 * We link to the next stack (which would be
21820@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21821 /*
21822 * This handles the process stack:
21823 */
21824- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21825+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21826+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21827+out:
21828 put_cpu();
21829 }
21830 EXPORT_SYMBOL(dump_trace);
21831@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
21832
21833 return ud2 == 0x0b0f;
21834 }
21835+
21836+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21837+void pax_check_alloca(unsigned long size)
21838+{
21839+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21840+ unsigned cpu, used;
21841+ char *id;
21842+
21843+ /* check the process stack first */
21844+ stack_start = (unsigned long)task_stack_page(current);
21845+ stack_end = stack_start + THREAD_SIZE;
21846+ if (likely(stack_start <= sp && sp < stack_end)) {
21847+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
21848+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21849+ return;
21850+ }
21851+
21852+ cpu = get_cpu();
21853+
21854+ /* check the irq stacks */
21855+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21856+ stack_start = stack_end - IRQ_STACK_SIZE;
21857+ if (stack_start <= sp && sp < stack_end) {
21858+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21859+ put_cpu();
21860+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21861+ return;
21862+ }
21863+
21864+ /* check the exception stacks */
21865+ used = 0;
21866+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
21867+ stack_start = stack_end - EXCEPTION_STKSZ;
21868+ if (stack_end && stack_start <= sp && sp < stack_end) {
21869+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
21870+ put_cpu();
21871+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21872+ return;
21873+ }
21874+
21875+ put_cpu();
21876+
21877+ /* unknown stack */
21878+ BUG();
21879+}
21880+EXPORT_SYMBOL(pax_check_alloca);
21881+#endif
21882diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
21883index 174da5f..5e55606 100644
21884--- a/arch/x86/kernel/e820.c
21885+++ b/arch/x86/kernel/e820.c
21886@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
21887
21888 static void early_panic(char *msg)
21889 {
21890- early_printk(msg);
21891- panic(msg);
21892+ early_printk("%s", msg);
21893+ panic("%s", msg);
21894 }
21895
21896 static int userdef __initdata;
21897diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
21898index 01d1c18..8073693 100644
21899--- a/arch/x86/kernel/early_printk.c
21900+++ b/arch/x86/kernel/early_printk.c
21901@@ -7,6 +7,7 @@
21902 #include <linux/pci_regs.h>
21903 #include <linux/pci_ids.h>
21904 #include <linux/errno.h>
21905+#include <linux/sched.h>
21906 #include <asm/io.h>
21907 #include <asm/processor.h>
21908 #include <asm/fcntl.h>
21909diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
21910index a2a4f46..6cab058 100644
21911--- a/arch/x86/kernel/entry_32.S
21912+++ b/arch/x86/kernel/entry_32.S
21913@@ -177,13 +177,153 @@
21914 /*CFI_REL_OFFSET gs, PT_GS*/
21915 .endm
21916 .macro SET_KERNEL_GS reg
21917+
21918+#ifdef CONFIG_CC_STACKPROTECTOR
21919 movl $(__KERNEL_STACK_CANARY), \reg
21920+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
21921+ movl $(__USER_DS), \reg
21922+#else
21923+ xorl \reg, \reg
21924+#endif
21925+
21926 movl \reg, %gs
21927 .endm
21928
21929 #endif /* CONFIG_X86_32_LAZY_GS */
21930
21931-.macro SAVE_ALL
21932+.macro pax_enter_kernel
21933+#ifdef CONFIG_PAX_KERNEXEC
21934+ call pax_enter_kernel
21935+#endif
21936+.endm
21937+
21938+.macro pax_exit_kernel
21939+#ifdef CONFIG_PAX_KERNEXEC
21940+ call pax_exit_kernel
21941+#endif
21942+.endm
21943+
21944+#ifdef CONFIG_PAX_KERNEXEC
21945+ENTRY(pax_enter_kernel)
21946+#ifdef CONFIG_PARAVIRT
21947+ pushl %eax
21948+ pushl %ecx
21949+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
21950+ mov %eax, %esi
21951+#else
21952+ mov %cr0, %esi
21953+#endif
21954+ bts $16, %esi
21955+ jnc 1f
21956+ mov %cs, %esi
21957+ cmp $__KERNEL_CS, %esi
21958+ jz 3f
21959+ ljmp $__KERNEL_CS, $3f
21960+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
21961+2:
21962+#ifdef CONFIG_PARAVIRT
21963+ mov %esi, %eax
21964+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
21965+#else
21966+ mov %esi, %cr0
21967+#endif
21968+3:
21969+#ifdef CONFIG_PARAVIRT
21970+ popl %ecx
21971+ popl %eax
21972+#endif
21973+ ret
21974+ENDPROC(pax_enter_kernel)
21975+
21976+ENTRY(pax_exit_kernel)
21977+#ifdef CONFIG_PARAVIRT
21978+ pushl %eax
21979+ pushl %ecx
21980+#endif
21981+ mov %cs, %esi
21982+ cmp $__KERNEXEC_KERNEL_CS, %esi
21983+ jnz 2f
21984+#ifdef CONFIG_PARAVIRT
21985+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
21986+ mov %eax, %esi
21987+#else
21988+ mov %cr0, %esi
21989+#endif
21990+ btr $16, %esi
21991+ ljmp $__KERNEL_CS, $1f
21992+1:
21993+#ifdef CONFIG_PARAVIRT
21994+ mov %esi, %eax
21995+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
21996+#else
21997+ mov %esi, %cr0
21998+#endif
21999+2:
22000+#ifdef CONFIG_PARAVIRT
22001+ popl %ecx
22002+ popl %eax
22003+#endif
22004+ ret
22005+ENDPROC(pax_exit_kernel)
22006+#endif
22007+
22008+ .macro pax_erase_kstack
22009+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22010+ call pax_erase_kstack
22011+#endif
22012+ .endm
22013+
22014+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22015+/*
22016+ * ebp: thread_info
22017+ */
22018+ENTRY(pax_erase_kstack)
22019+ pushl %edi
22020+ pushl %ecx
22021+ pushl %eax
22022+
22023+ mov TI_lowest_stack(%ebp), %edi
22024+ mov $-0xBEEF, %eax
22025+ std
22026+
22027+1: mov %edi, %ecx
22028+ and $THREAD_SIZE_asm - 1, %ecx
22029+ shr $2, %ecx
22030+ repne scasl
22031+ jecxz 2f
22032+
22033+ cmp $2*16, %ecx
22034+ jc 2f
22035+
22036+ mov $2*16, %ecx
22037+ repe scasl
22038+ jecxz 2f
22039+ jne 1b
22040+
22041+2: cld
22042+ mov %esp, %ecx
22043+ sub %edi, %ecx
22044+
22045+ cmp $THREAD_SIZE_asm, %ecx
22046+ jb 3f
22047+ ud2
22048+3:
22049+
22050+ shr $2, %ecx
22051+ rep stosl
22052+
22053+ mov TI_task_thread_sp0(%ebp), %edi
22054+ sub $128, %edi
22055+ mov %edi, TI_lowest_stack(%ebp)
22056+
22057+ popl %eax
22058+ popl %ecx
22059+ popl %edi
22060+ ret
22061+ENDPROC(pax_erase_kstack)
22062+#endif
22063+
22064+.macro __SAVE_ALL _DS
22065 cld
22066 PUSH_GS
22067 pushl_cfi %fs
22068@@ -206,7 +346,7 @@
22069 CFI_REL_OFFSET ecx, 0
22070 pushl_cfi %ebx
22071 CFI_REL_OFFSET ebx, 0
22072- movl $(__USER_DS), %edx
22073+ movl $\_DS, %edx
22074 movl %edx, %ds
22075 movl %edx, %es
22076 movl $(__KERNEL_PERCPU), %edx
22077@@ -214,6 +354,15 @@
22078 SET_KERNEL_GS %edx
22079 .endm
22080
22081+.macro SAVE_ALL
22082+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22083+ __SAVE_ALL __KERNEL_DS
22084+ pax_enter_kernel
22085+#else
22086+ __SAVE_ALL __USER_DS
22087+#endif
22088+.endm
22089+
22090 .macro RESTORE_INT_REGS
22091 popl_cfi %ebx
22092 CFI_RESTORE ebx
22093@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22094 popfl_cfi
22095 jmp syscall_exit
22096 CFI_ENDPROC
22097-END(ret_from_fork)
22098+ENDPROC(ret_from_fork)
22099
22100 ENTRY(ret_from_kernel_thread)
22101 CFI_STARTPROC
22102@@ -344,7 +493,15 @@ ret_from_intr:
22103 andl $SEGMENT_RPL_MASK, %eax
22104 #endif
22105 cmpl $USER_RPL, %eax
22106+
22107+#ifdef CONFIG_PAX_KERNEXEC
22108+ jae resume_userspace
22109+
22110+ pax_exit_kernel
22111+ jmp resume_kernel
22112+#else
22113 jb resume_kernel # not returning to v8086 or userspace
22114+#endif
22115
22116 ENTRY(resume_userspace)
22117 LOCKDEP_SYS_EXIT
22118@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
22119 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22120 # int/exception return?
22121 jne work_pending
22122- jmp restore_all
22123-END(ret_from_exception)
22124+ jmp restore_all_pax
22125+ENDPROC(ret_from_exception)
22126
22127 #ifdef CONFIG_PREEMPT
22128 ENTRY(resume_kernel)
22129@@ -369,7 +526,7 @@ need_resched:
22130 jz restore_all
22131 call preempt_schedule_irq
22132 jmp need_resched
22133-END(resume_kernel)
22134+ENDPROC(resume_kernel)
22135 #endif
22136 CFI_ENDPROC
22137 /*
22138@@ -403,30 +560,45 @@ sysenter_past_esp:
22139 /*CFI_REL_OFFSET cs, 0*/
22140 /*
22141 * Push current_thread_info()->sysenter_return to the stack.
22142- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22143- * pushed above; +8 corresponds to copy_thread's esp0 setting.
22144 */
22145- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22146+ pushl_cfi $0
22147 CFI_REL_OFFSET eip, 0
22148
22149 pushl_cfi %eax
22150 SAVE_ALL
22151+ GET_THREAD_INFO(%ebp)
22152+ movl TI_sysenter_return(%ebp),%ebp
22153+ movl %ebp,PT_EIP(%esp)
22154 ENABLE_INTERRUPTS(CLBR_NONE)
22155
22156 /*
22157 * Load the potential sixth argument from user stack.
22158 * Careful about security.
22159 */
22160+ movl PT_OLDESP(%esp),%ebp
22161+
22162+#ifdef CONFIG_PAX_MEMORY_UDEREF
22163+ mov PT_OLDSS(%esp),%ds
22164+1: movl %ds:(%ebp),%ebp
22165+ push %ss
22166+ pop %ds
22167+#else
22168 cmpl $__PAGE_OFFSET-3,%ebp
22169 jae syscall_fault
22170 ASM_STAC
22171 1: movl (%ebp),%ebp
22172 ASM_CLAC
22173+#endif
22174+
22175 movl %ebp,PT_EBP(%esp)
22176 _ASM_EXTABLE(1b,syscall_fault)
22177
22178 GET_THREAD_INFO(%ebp)
22179
22180+#ifdef CONFIG_PAX_RANDKSTACK
22181+ pax_erase_kstack
22182+#endif
22183+
22184 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22185 jnz sysenter_audit
22186 sysenter_do_call:
22187@@ -441,12 +613,24 @@ sysenter_do_call:
22188 testl $_TIF_ALLWORK_MASK, %ecx
22189 jne sysexit_audit
22190 sysenter_exit:
22191+
22192+#ifdef CONFIG_PAX_RANDKSTACK
22193+ pushl_cfi %eax
22194+ movl %esp, %eax
22195+ call pax_randomize_kstack
22196+ popl_cfi %eax
22197+#endif
22198+
22199+ pax_erase_kstack
22200+
22201 /* if something modifies registers it must also disable sysexit */
22202 movl PT_EIP(%esp), %edx
22203 movl PT_OLDESP(%esp), %ecx
22204 xorl %ebp,%ebp
22205 TRACE_IRQS_ON
22206 1: mov PT_FS(%esp), %fs
22207+2: mov PT_DS(%esp), %ds
22208+3: mov PT_ES(%esp), %es
22209 PTGS_TO_GS
22210 ENABLE_INTERRUPTS_SYSEXIT
22211
22212@@ -463,6 +647,9 @@ sysenter_audit:
22213 movl %eax,%edx /* 2nd arg: syscall number */
22214 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22215 call __audit_syscall_entry
22216+
22217+ pax_erase_kstack
22218+
22219 pushl_cfi %ebx
22220 movl PT_EAX(%esp),%eax /* reload syscall number */
22221 jmp sysenter_do_call
22222@@ -488,10 +675,16 @@ sysexit_audit:
22223
22224 CFI_ENDPROC
22225 .pushsection .fixup,"ax"
22226-2: movl $0,PT_FS(%esp)
22227+4: movl $0,PT_FS(%esp)
22228+ jmp 1b
22229+5: movl $0,PT_DS(%esp)
22230+ jmp 1b
22231+6: movl $0,PT_ES(%esp)
22232 jmp 1b
22233 .popsection
22234- _ASM_EXTABLE(1b,2b)
22235+ _ASM_EXTABLE(1b,4b)
22236+ _ASM_EXTABLE(2b,5b)
22237+ _ASM_EXTABLE(3b,6b)
22238 PTGS_TO_GS_EX
22239 ENDPROC(ia32_sysenter_target)
22240
22241@@ -506,6 +699,11 @@ ENTRY(system_call)
22242 pushl_cfi %eax # save orig_eax
22243 SAVE_ALL
22244 GET_THREAD_INFO(%ebp)
22245+
22246+#ifdef CONFIG_PAX_RANDKSTACK
22247+ pax_erase_kstack
22248+#endif
22249+
22250 # system call tracing in operation / emulation
22251 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22252 jnz syscall_trace_entry
22253@@ -524,6 +722,15 @@ syscall_exit:
22254 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22255 jne syscall_exit_work
22256
22257+restore_all_pax:
22258+
22259+#ifdef CONFIG_PAX_RANDKSTACK
22260+ movl %esp, %eax
22261+ call pax_randomize_kstack
22262+#endif
22263+
22264+ pax_erase_kstack
22265+
22266 restore_all:
22267 TRACE_IRQS_IRET
22268 restore_all_notrace:
22269@@ -580,14 +787,34 @@ ldt_ss:
22270 * compensating for the offset by changing to the ESPFIX segment with
22271 * a base address that matches for the difference.
22272 */
22273-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22274+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22275 mov %esp, %edx /* load kernel esp */
22276 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22277 mov %dx, %ax /* eax: new kernel esp */
22278 sub %eax, %edx /* offset (low word is 0) */
22279+#ifdef CONFIG_SMP
22280+ movl PER_CPU_VAR(cpu_number), %ebx
22281+ shll $PAGE_SHIFT_asm, %ebx
22282+ addl $cpu_gdt_table, %ebx
22283+#else
22284+ movl $cpu_gdt_table, %ebx
22285+#endif
22286 shr $16, %edx
22287- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22288- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22289+
22290+#ifdef CONFIG_PAX_KERNEXEC
22291+ mov %cr0, %esi
22292+ btr $16, %esi
22293+ mov %esi, %cr0
22294+#endif
22295+
22296+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22297+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22298+
22299+#ifdef CONFIG_PAX_KERNEXEC
22300+ bts $16, %esi
22301+ mov %esi, %cr0
22302+#endif
22303+
22304 pushl_cfi $__ESPFIX_SS
22305 pushl_cfi %eax /* new kernel esp */
22306 /* Disable interrupts, but do not irqtrace this section: we
22307@@ -616,20 +843,18 @@ work_resched:
22308 movl TI_flags(%ebp), %ecx
22309 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22310 # than syscall tracing?
22311- jz restore_all
22312+ jz restore_all_pax
22313 testb $_TIF_NEED_RESCHED, %cl
22314 jnz work_resched
22315
22316 work_notifysig: # deal with pending signals and
22317 # notify-resume requests
22318+ movl %esp, %eax
22319 #ifdef CONFIG_VM86
22320 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22321- movl %esp, %eax
22322 jne work_notifysig_v86 # returning to kernel-space or
22323 # vm86-space
22324 1:
22325-#else
22326- movl %esp, %eax
22327 #endif
22328 TRACE_IRQS_ON
22329 ENABLE_INTERRUPTS(CLBR_NONE)
22330@@ -650,7 +875,7 @@ work_notifysig_v86:
22331 movl %eax, %esp
22332 jmp 1b
22333 #endif
22334-END(work_pending)
22335+ENDPROC(work_pending)
22336
22337 # perform syscall exit tracing
22338 ALIGN
22339@@ -658,11 +883,14 @@ syscall_trace_entry:
22340 movl $-ENOSYS,PT_EAX(%esp)
22341 movl %esp, %eax
22342 call syscall_trace_enter
22343+
22344+ pax_erase_kstack
22345+
22346 /* What it returned is what we'll actually use. */
22347 cmpl $(NR_syscalls), %eax
22348 jnae syscall_call
22349 jmp syscall_exit
22350-END(syscall_trace_entry)
22351+ENDPROC(syscall_trace_entry)
22352
22353 # perform syscall exit tracing
22354 ALIGN
22355@@ -675,21 +903,25 @@ syscall_exit_work:
22356 movl %esp, %eax
22357 call syscall_trace_leave
22358 jmp resume_userspace
22359-END(syscall_exit_work)
22360+ENDPROC(syscall_exit_work)
22361 CFI_ENDPROC
22362
22363 RING0_INT_FRAME # can't unwind into user space anyway
22364 syscall_fault:
22365+#ifdef CONFIG_PAX_MEMORY_UDEREF
22366+ push %ss
22367+ pop %ds
22368+#endif
22369 ASM_CLAC
22370 GET_THREAD_INFO(%ebp)
22371 movl $-EFAULT,PT_EAX(%esp)
22372 jmp resume_userspace
22373-END(syscall_fault)
22374+ENDPROC(syscall_fault)
22375
22376 syscall_badsys:
22377 movl $-ENOSYS,PT_EAX(%esp)
22378 jmp resume_userspace
22379-END(syscall_badsys)
22380+ENDPROC(syscall_badsys)
22381 CFI_ENDPROC
22382 /*
22383 * End of kprobes section
22384@@ -705,8 +937,15 @@ END(syscall_badsys)
22385 * normal stack and adjusts ESP with the matching offset.
22386 */
22387 /* fixup the stack */
22388- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22389- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22390+#ifdef CONFIG_SMP
22391+ movl PER_CPU_VAR(cpu_number), %ebx
22392+ shll $PAGE_SHIFT_asm, %ebx
22393+ addl $cpu_gdt_table, %ebx
22394+#else
22395+ movl $cpu_gdt_table, %ebx
22396+#endif
22397+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22398+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22399 shl $16, %eax
22400 addl %esp, %eax /* the adjusted stack pointer */
22401 pushl_cfi $__KERNEL_DS
22402@@ -759,7 +998,7 @@ vector=vector+1
22403 .endr
22404 2: jmp common_interrupt
22405 .endr
22406-END(irq_entries_start)
22407+ENDPROC(irq_entries_start)
22408
22409 .previous
22410 END(interrupt)
22411@@ -820,7 +1059,7 @@ ENTRY(coprocessor_error)
22412 pushl_cfi $do_coprocessor_error
22413 jmp error_code
22414 CFI_ENDPROC
22415-END(coprocessor_error)
22416+ENDPROC(coprocessor_error)
22417
22418 ENTRY(simd_coprocessor_error)
22419 RING0_INT_FRAME
22420@@ -833,7 +1072,7 @@ ENTRY(simd_coprocessor_error)
22421 .section .altinstructions,"a"
22422 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22423 .previous
22424-.section .altinstr_replacement,"ax"
22425+.section .altinstr_replacement,"a"
22426 663: pushl $do_simd_coprocessor_error
22427 664:
22428 .previous
22429@@ -842,7 +1081,7 @@ ENTRY(simd_coprocessor_error)
22430 #endif
22431 jmp error_code
22432 CFI_ENDPROC
22433-END(simd_coprocessor_error)
22434+ENDPROC(simd_coprocessor_error)
22435
22436 ENTRY(device_not_available)
22437 RING0_INT_FRAME
22438@@ -851,18 +1090,18 @@ ENTRY(device_not_available)
22439 pushl_cfi $do_device_not_available
22440 jmp error_code
22441 CFI_ENDPROC
22442-END(device_not_available)
22443+ENDPROC(device_not_available)
22444
22445 #ifdef CONFIG_PARAVIRT
22446 ENTRY(native_iret)
22447 iret
22448 _ASM_EXTABLE(native_iret, iret_exc)
22449-END(native_iret)
22450+ENDPROC(native_iret)
22451
22452 ENTRY(native_irq_enable_sysexit)
22453 sti
22454 sysexit
22455-END(native_irq_enable_sysexit)
22456+ENDPROC(native_irq_enable_sysexit)
22457 #endif
22458
22459 ENTRY(overflow)
22460@@ -872,7 +1111,7 @@ ENTRY(overflow)
22461 pushl_cfi $do_overflow
22462 jmp error_code
22463 CFI_ENDPROC
22464-END(overflow)
22465+ENDPROC(overflow)
22466
22467 ENTRY(bounds)
22468 RING0_INT_FRAME
22469@@ -881,7 +1120,7 @@ ENTRY(bounds)
22470 pushl_cfi $do_bounds
22471 jmp error_code
22472 CFI_ENDPROC
22473-END(bounds)
22474+ENDPROC(bounds)
22475
22476 ENTRY(invalid_op)
22477 RING0_INT_FRAME
22478@@ -890,7 +1129,7 @@ ENTRY(invalid_op)
22479 pushl_cfi $do_invalid_op
22480 jmp error_code
22481 CFI_ENDPROC
22482-END(invalid_op)
22483+ENDPROC(invalid_op)
22484
22485 ENTRY(coprocessor_segment_overrun)
22486 RING0_INT_FRAME
22487@@ -899,7 +1138,7 @@ ENTRY(coprocessor_segment_overrun)
22488 pushl_cfi $do_coprocessor_segment_overrun
22489 jmp error_code
22490 CFI_ENDPROC
22491-END(coprocessor_segment_overrun)
22492+ENDPROC(coprocessor_segment_overrun)
22493
22494 ENTRY(invalid_TSS)
22495 RING0_EC_FRAME
22496@@ -907,7 +1146,7 @@ ENTRY(invalid_TSS)
22497 pushl_cfi $do_invalid_TSS
22498 jmp error_code
22499 CFI_ENDPROC
22500-END(invalid_TSS)
22501+ENDPROC(invalid_TSS)
22502
22503 ENTRY(segment_not_present)
22504 RING0_EC_FRAME
22505@@ -915,7 +1154,7 @@ ENTRY(segment_not_present)
22506 pushl_cfi $do_segment_not_present
22507 jmp error_code
22508 CFI_ENDPROC
22509-END(segment_not_present)
22510+ENDPROC(segment_not_present)
22511
22512 ENTRY(stack_segment)
22513 RING0_EC_FRAME
22514@@ -923,7 +1162,7 @@ ENTRY(stack_segment)
22515 pushl_cfi $do_stack_segment
22516 jmp error_code
22517 CFI_ENDPROC
22518-END(stack_segment)
22519+ENDPROC(stack_segment)
22520
22521 ENTRY(alignment_check)
22522 RING0_EC_FRAME
22523@@ -931,7 +1170,7 @@ ENTRY(alignment_check)
22524 pushl_cfi $do_alignment_check
22525 jmp error_code
22526 CFI_ENDPROC
22527-END(alignment_check)
22528+ENDPROC(alignment_check)
22529
22530 ENTRY(divide_error)
22531 RING0_INT_FRAME
22532@@ -940,7 +1179,7 @@ ENTRY(divide_error)
22533 pushl_cfi $do_divide_error
22534 jmp error_code
22535 CFI_ENDPROC
22536-END(divide_error)
22537+ENDPROC(divide_error)
22538
22539 #ifdef CONFIG_X86_MCE
22540 ENTRY(machine_check)
22541@@ -950,7 +1189,7 @@ ENTRY(machine_check)
22542 pushl_cfi machine_check_vector
22543 jmp error_code
22544 CFI_ENDPROC
22545-END(machine_check)
22546+ENDPROC(machine_check)
22547 #endif
22548
22549 ENTRY(spurious_interrupt_bug)
22550@@ -960,7 +1199,7 @@ ENTRY(spurious_interrupt_bug)
22551 pushl_cfi $do_spurious_interrupt_bug
22552 jmp error_code
22553 CFI_ENDPROC
22554-END(spurious_interrupt_bug)
22555+ENDPROC(spurious_interrupt_bug)
22556 /*
22557 * End of kprobes section
22558 */
22559@@ -1070,7 +1309,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22560
22561 ENTRY(mcount)
22562 ret
22563-END(mcount)
22564+ENDPROC(mcount)
22565
22566 ENTRY(ftrace_caller)
22567 cmpl $0, function_trace_stop
22568@@ -1103,7 +1342,7 @@ ftrace_graph_call:
22569 .globl ftrace_stub
22570 ftrace_stub:
22571 ret
22572-END(ftrace_caller)
22573+ENDPROC(ftrace_caller)
22574
22575 ENTRY(ftrace_regs_caller)
22576 pushf /* push flags before compare (in cs location) */
22577@@ -1207,7 +1446,7 @@ trace:
22578 popl %ecx
22579 popl %eax
22580 jmp ftrace_stub
22581-END(mcount)
22582+ENDPROC(mcount)
22583 #endif /* CONFIG_DYNAMIC_FTRACE */
22584 #endif /* CONFIG_FUNCTION_TRACER */
22585
22586@@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
22587 popl %ecx
22588 popl %eax
22589 ret
22590-END(ftrace_graph_caller)
22591+ENDPROC(ftrace_graph_caller)
22592
22593 .globl return_to_handler
22594 return_to_handler:
22595@@ -1291,15 +1530,18 @@ error_code:
22596 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22597 REG_TO_PTGS %ecx
22598 SET_KERNEL_GS %ecx
22599- movl $(__USER_DS), %ecx
22600+ movl $(__KERNEL_DS), %ecx
22601 movl %ecx, %ds
22602 movl %ecx, %es
22603+
22604+ pax_enter_kernel
22605+
22606 TRACE_IRQS_OFF
22607 movl %esp,%eax # pt_regs pointer
22608 call *%edi
22609 jmp ret_from_exception
22610 CFI_ENDPROC
22611-END(page_fault)
22612+ENDPROC(page_fault)
22613
22614 /*
22615 * Debug traps and NMI can happen at the one SYSENTER instruction
22616@@ -1342,7 +1584,7 @@ debug_stack_correct:
22617 call do_debug
22618 jmp ret_from_exception
22619 CFI_ENDPROC
22620-END(debug)
22621+ENDPROC(debug)
22622
22623 /*
22624 * NMI is doubly nasty. It can happen _while_ we're handling
22625@@ -1380,6 +1622,9 @@ nmi_stack_correct:
22626 xorl %edx,%edx # zero error code
22627 movl %esp,%eax # pt_regs pointer
22628 call do_nmi
22629+
22630+ pax_exit_kernel
22631+
22632 jmp restore_all_notrace
22633 CFI_ENDPROC
22634
22635@@ -1416,12 +1661,15 @@ nmi_espfix_stack:
22636 FIXUP_ESPFIX_STACK # %eax == %esp
22637 xorl %edx,%edx # zero error code
22638 call do_nmi
22639+
22640+ pax_exit_kernel
22641+
22642 RESTORE_REGS
22643 lss 12+4(%esp), %esp # back to espfix stack
22644 CFI_ADJUST_CFA_OFFSET -24
22645 jmp irq_return
22646 CFI_ENDPROC
22647-END(nmi)
22648+ENDPROC(nmi)
22649
22650 ENTRY(int3)
22651 RING0_INT_FRAME
22652@@ -1434,14 +1682,14 @@ ENTRY(int3)
22653 call do_int3
22654 jmp ret_from_exception
22655 CFI_ENDPROC
22656-END(int3)
22657+ENDPROC(int3)
22658
22659 ENTRY(general_protection)
22660 RING0_EC_FRAME
22661 pushl_cfi $do_general_protection
22662 jmp error_code
22663 CFI_ENDPROC
22664-END(general_protection)
22665+ENDPROC(general_protection)
22666
22667 #ifdef CONFIG_KVM_GUEST
22668 ENTRY(async_page_fault)
22669@@ -1450,7 +1698,7 @@ ENTRY(async_page_fault)
22670 pushl_cfi $do_async_page_fault
22671 jmp error_code
22672 CFI_ENDPROC
22673-END(async_page_fault)
22674+ENDPROC(async_page_fault)
22675 #endif
22676
22677 /*
22678diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22679index 1e96c36..3ff710a 100644
22680--- a/arch/x86/kernel/entry_64.S
22681+++ b/arch/x86/kernel/entry_64.S
22682@@ -59,6 +59,8 @@
22683 #include <asm/context_tracking.h>
22684 #include <asm/smap.h>
22685 #include <linux/err.h>
22686+#include <asm/pgtable.h>
22687+#include <asm/alternative-asm.h>
22688
22689 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22690 #include <linux/elf-em.h>
22691@@ -80,8 +82,9 @@
22692 #ifdef CONFIG_DYNAMIC_FTRACE
22693
22694 ENTRY(function_hook)
22695+ pax_force_retaddr
22696 retq
22697-END(function_hook)
22698+ENDPROC(function_hook)
22699
22700 /* skip is set if stack has been adjusted */
22701 .macro ftrace_caller_setup skip=0
22702@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
22703 #endif
22704
22705 GLOBAL(ftrace_stub)
22706+ pax_force_retaddr
22707 retq
22708-END(ftrace_caller)
22709+ENDPROC(ftrace_caller)
22710
22711 ENTRY(ftrace_regs_caller)
22712 /* Save the current flags before compare (in SS location)*/
22713@@ -191,7 +195,7 @@ ftrace_restore_flags:
22714 popfq
22715 jmp ftrace_stub
22716
22717-END(ftrace_regs_caller)
22718+ENDPROC(ftrace_regs_caller)
22719
22720
22721 #else /* ! CONFIG_DYNAMIC_FTRACE */
22722@@ -212,6 +216,7 @@ ENTRY(function_hook)
22723 #endif
22724
22725 GLOBAL(ftrace_stub)
22726+ pax_force_retaddr
22727 retq
22728
22729 trace:
22730@@ -225,12 +230,13 @@ trace:
22731 #endif
22732 subq $MCOUNT_INSN_SIZE, %rdi
22733
22734+ pax_force_fptr ftrace_trace_function
22735 call *ftrace_trace_function
22736
22737 MCOUNT_RESTORE_FRAME
22738
22739 jmp ftrace_stub
22740-END(function_hook)
22741+ENDPROC(function_hook)
22742 #endif /* CONFIG_DYNAMIC_FTRACE */
22743 #endif /* CONFIG_FUNCTION_TRACER */
22744
22745@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
22746
22747 MCOUNT_RESTORE_FRAME
22748
22749+ pax_force_retaddr
22750 retq
22751-END(ftrace_graph_caller)
22752+ENDPROC(ftrace_graph_caller)
22753
22754 GLOBAL(return_to_handler)
22755 subq $24, %rsp
22756@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
22757 movq 8(%rsp), %rdx
22758 movq (%rsp), %rax
22759 addq $24, %rsp
22760+ pax_force_fptr %rdi
22761 jmp *%rdi
22762+ENDPROC(return_to_handler)
22763 #endif
22764
22765
22766@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
22767 ENDPROC(native_usergs_sysret64)
22768 #endif /* CONFIG_PARAVIRT */
22769
22770+ .macro ljmpq sel, off
22771+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22772+ .byte 0x48; ljmp *1234f(%rip)
22773+ .pushsection .rodata
22774+ .align 16
22775+ 1234: .quad \off; .word \sel
22776+ .popsection
22777+#else
22778+ pushq $\sel
22779+ pushq $\off
22780+ lretq
22781+#endif
22782+ .endm
22783+
22784+ .macro pax_enter_kernel
22785+ pax_set_fptr_mask
22786+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22787+ call pax_enter_kernel
22788+#endif
22789+ .endm
22790+
22791+ .macro pax_exit_kernel
22792+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22793+ call pax_exit_kernel
22794+#endif
22795+
22796+ .endm
22797+
22798+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22799+ENTRY(pax_enter_kernel)
22800+ pushq %rdi
22801+
22802+#ifdef CONFIG_PARAVIRT
22803+ PV_SAVE_REGS(CLBR_RDI)
22804+#endif
22805+
22806+#ifdef CONFIG_PAX_KERNEXEC
22807+ GET_CR0_INTO_RDI
22808+ bts $16,%rdi
22809+ jnc 3f
22810+ mov %cs,%edi
22811+ cmp $__KERNEL_CS,%edi
22812+ jnz 2f
22813+1:
22814+#endif
22815+
22816+#ifdef CONFIG_PAX_MEMORY_UDEREF
22817+ 661: jmp 111f
22818+ .pushsection .altinstr_replacement, "a"
22819+ 662: ASM_NOP2
22820+ .popsection
22821+ .pushsection .altinstructions, "a"
22822+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22823+ .popsection
22824+ GET_CR3_INTO_RDI
22825+ cmp $0,%dil
22826+ jnz 112f
22827+ mov $__KERNEL_DS,%edi
22828+ mov %edi,%ss
22829+ jmp 111f
22830+112: cmp $1,%dil
22831+ jz 113f
22832+ ud2
22833+113: sub $4097,%rdi
22834+ bts $63,%rdi
22835+ SET_RDI_INTO_CR3
22836+ mov $__UDEREF_KERNEL_DS,%edi
22837+ mov %edi,%ss
22838+111:
22839+#endif
22840+
22841+#ifdef CONFIG_PARAVIRT
22842+ PV_RESTORE_REGS(CLBR_RDI)
22843+#endif
22844+
22845+ popq %rdi
22846+ pax_force_retaddr
22847+ retq
22848+
22849+#ifdef CONFIG_PAX_KERNEXEC
22850+2: ljmpq __KERNEL_CS,1b
22851+3: ljmpq __KERNEXEC_KERNEL_CS,4f
22852+4: SET_RDI_INTO_CR0
22853+ jmp 1b
22854+#endif
22855+ENDPROC(pax_enter_kernel)
22856+
22857+ENTRY(pax_exit_kernel)
22858+ pushq %rdi
22859+
22860+#ifdef CONFIG_PARAVIRT
22861+ PV_SAVE_REGS(CLBR_RDI)
22862+#endif
22863+
22864+#ifdef CONFIG_PAX_KERNEXEC
22865+ mov %cs,%rdi
22866+ cmp $__KERNEXEC_KERNEL_CS,%edi
22867+ jz 2f
22868+ GET_CR0_INTO_RDI
22869+ bts $16,%rdi
22870+ jnc 4f
22871+1:
22872+#endif
22873+
22874+#ifdef CONFIG_PAX_MEMORY_UDEREF
22875+ 661: jmp 111f
22876+ .pushsection .altinstr_replacement, "a"
22877+ 662: ASM_NOP2
22878+ .popsection
22879+ .pushsection .altinstructions, "a"
22880+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22881+ .popsection
22882+ mov %ss,%edi
22883+ cmp $__UDEREF_KERNEL_DS,%edi
22884+ jnz 111f
22885+ GET_CR3_INTO_RDI
22886+ cmp $0,%dil
22887+ jz 112f
22888+ ud2
22889+112: add $4097,%rdi
22890+ bts $63,%rdi
22891+ SET_RDI_INTO_CR3
22892+ mov $__KERNEL_DS,%edi
22893+ mov %edi,%ss
22894+111:
22895+#endif
22896+
22897+#ifdef CONFIG_PARAVIRT
22898+ PV_RESTORE_REGS(CLBR_RDI);
22899+#endif
22900+
22901+ popq %rdi
22902+ pax_force_retaddr
22903+ retq
22904+
22905+#ifdef CONFIG_PAX_KERNEXEC
22906+2: GET_CR0_INTO_RDI
22907+ btr $16,%rdi
22908+ jnc 4f
22909+ ljmpq __KERNEL_CS,3f
22910+3: SET_RDI_INTO_CR0
22911+ jmp 1b
22912+4: ud2
22913+ jmp 4b
22914+#endif
22915+ENDPROC(pax_exit_kernel)
22916+#endif
22917+
22918+ .macro pax_enter_kernel_user
22919+ pax_set_fptr_mask
22920+#ifdef CONFIG_PAX_MEMORY_UDEREF
22921+ call pax_enter_kernel_user
22922+#endif
22923+ .endm
22924+
22925+ .macro pax_exit_kernel_user
22926+#ifdef CONFIG_PAX_MEMORY_UDEREF
22927+ call pax_exit_kernel_user
22928+#endif
22929+#ifdef CONFIG_PAX_RANDKSTACK
22930+ pushq %rax
22931+ pushq %r11
22932+ call pax_randomize_kstack
22933+ popq %r11
22934+ popq %rax
22935+#endif
22936+ .endm
22937+
22938+#ifdef CONFIG_PAX_MEMORY_UDEREF
22939+ENTRY(pax_enter_kernel_user)
22940+ pushq %rdi
22941+ pushq %rbx
22942+
22943+#ifdef CONFIG_PARAVIRT
22944+ PV_SAVE_REGS(CLBR_RDI)
22945+#endif
22946+
22947+ 661: jmp 111f
22948+ .pushsection .altinstr_replacement, "a"
22949+ 662: ASM_NOP2
22950+ .popsection
22951+ .pushsection .altinstructions, "a"
22952+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22953+ .popsection
22954+ GET_CR3_INTO_RDI
22955+ cmp $1,%dil
22956+ jnz 4f
22957+ sub $4097,%rdi
22958+ bts $63,%rdi
22959+ SET_RDI_INTO_CR3
22960+ jmp 3f
22961+111:
22962+
22963+ GET_CR3_INTO_RDI
22964+ mov %rdi,%rbx
22965+ add $__START_KERNEL_map,%rbx
22966+ sub phys_base(%rip),%rbx
22967+
22968+#ifdef CONFIG_PARAVIRT
22969+ cmpl $0, pv_info+PARAVIRT_enabled
22970+ jz 1f
22971+ pushq %rdi
22972+ i = 0
22973+ .rept USER_PGD_PTRS
22974+ mov i*8(%rbx),%rsi
22975+ mov $0,%sil
22976+ lea i*8(%rbx),%rdi
22977+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22978+ i = i + 1
22979+ .endr
22980+ popq %rdi
22981+ jmp 2f
22982+1:
22983+#endif
22984+
22985+ i = 0
22986+ .rept USER_PGD_PTRS
22987+ movb $0,i*8(%rbx)
22988+ i = i + 1
22989+ .endr
22990+
22991+2: SET_RDI_INTO_CR3
22992+
22993+#ifdef CONFIG_PAX_KERNEXEC
22994+ GET_CR0_INTO_RDI
22995+ bts $16,%rdi
22996+ SET_RDI_INTO_CR0
22997+#endif
22998+
22999+3:
23000+
23001+#ifdef CONFIG_PARAVIRT
23002+ PV_RESTORE_REGS(CLBR_RDI)
23003+#endif
23004+
23005+ popq %rbx
23006+ popq %rdi
23007+ pax_force_retaddr
23008+ retq
23009+4: ud2
23010+ENDPROC(pax_enter_kernel_user)
23011+
23012+ENTRY(pax_exit_kernel_user)
23013+ pushq %rdi
23014+ pushq %rbx
23015+
23016+#ifdef CONFIG_PARAVIRT
23017+ PV_SAVE_REGS(CLBR_RDI)
23018+#endif
23019+
23020+ GET_CR3_INTO_RDI
23021+ 661: jmp 1f
23022+ .pushsection .altinstr_replacement, "a"
23023+ 662: ASM_NOP2
23024+ .popsection
23025+ .pushsection .altinstructions, "a"
23026+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23027+ .popsection
23028+ cmp $0,%dil
23029+ jnz 3f
23030+ add $4097,%rdi
23031+ bts $63,%rdi
23032+ SET_RDI_INTO_CR3
23033+ jmp 2f
23034+1:
23035+
23036+ mov %rdi,%rbx
23037+
23038+#ifdef CONFIG_PAX_KERNEXEC
23039+ GET_CR0_INTO_RDI
23040+ btr $16,%rdi
23041+ jnc 3f
23042+ SET_RDI_INTO_CR0
23043+#endif
23044+
23045+ add $__START_KERNEL_map,%rbx
23046+ sub phys_base(%rip),%rbx
23047+
23048+#ifdef CONFIG_PARAVIRT
23049+ cmpl $0, pv_info+PARAVIRT_enabled
23050+ jz 1f
23051+ i = 0
23052+ .rept USER_PGD_PTRS
23053+ mov i*8(%rbx),%rsi
23054+ mov $0x67,%sil
23055+ lea i*8(%rbx),%rdi
23056+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23057+ i = i + 1
23058+ .endr
23059+ jmp 2f
23060+1:
23061+#endif
23062+
23063+ i = 0
23064+ .rept USER_PGD_PTRS
23065+ movb $0x67,i*8(%rbx)
23066+ i = i + 1
23067+ .endr
23068+2:
23069+
23070+#ifdef CONFIG_PARAVIRT
23071+ PV_RESTORE_REGS(CLBR_RDI)
23072+#endif
23073+
23074+ popq %rbx
23075+ popq %rdi
23076+ pax_force_retaddr
23077+ retq
23078+3: ud2
23079+ENDPROC(pax_exit_kernel_user)
23080+#endif
23081+
23082+ .macro pax_enter_kernel_nmi
23083+ pax_set_fptr_mask
23084+
23085+#ifdef CONFIG_PAX_KERNEXEC
23086+ GET_CR0_INTO_RDI
23087+ bts $16,%rdi
23088+ jc 110f
23089+ SET_RDI_INTO_CR0
23090+ or $2,%ebx
23091+110:
23092+#endif
23093+
23094+#ifdef CONFIG_PAX_MEMORY_UDEREF
23095+ 661: jmp 111f
23096+ .pushsection .altinstr_replacement, "a"
23097+ 662: ASM_NOP2
23098+ .popsection
23099+ .pushsection .altinstructions, "a"
23100+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23101+ .popsection
23102+ GET_CR3_INTO_RDI
23103+ cmp $0,%dil
23104+ jz 111f
23105+ sub $4097,%rdi
23106+ or $4,%ebx
23107+ bts $63,%rdi
23108+ SET_RDI_INTO_CR3
23109+ mov $__UDEREF_KERNEL_DS,%edi
23110+ mov %edi,%ss
23111+111:
23112+#endif
23113+ .endm
23114+
23115+ .macro pax_exit_kernel_nmi
23116+#ifdef CONFIG_PAX_KERNEXEC
23117+ btr $1,%ebx
23118+ jnc 110f
23119+ GET_CR0_INTO_RDI
23120+ btr $16,%rdi
23121+ SET_RDI_INTO_CR0
23122+110:
23123+#endif
23124+
23125+#ifdef CONFIG_PAX_MEMORY_UDEREF
23126+ btr $2,%ebx
23127+ jnc 111f
23128+ GET_CR3_INTO_RDI
23129+ add $4097,%rdi
23130+ bts $63,%rdi
23131+ SET_RDI_INTO_CR3
23132+ mov $__KERNEL_DS,%edi
23133+ mov %edi,%ss
23134+111:
23135+#endif
23136+ .endm
23137+
23138+ .macro pax_erase_kstack
23139+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23140+ call pax_erase_kstack
23141+#endif
23142+ .endm
23143+
23144+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23145+ENTRY(pax_erase_kstack)
23146+ pushq %rdi
23147+ pushq %rcx
23148+ pushq %rax
23149+ pushq %r11
23150+
23151+ GET_THREAD_INFO(%r11)
23152+ mov TI_lowest_stack(%r11), %rdi
23153+ mov $-0xBEEF, %rax
23154+ std
23155+
23156+1: mov %edi, %ecx
23157+ and $THREAD_SIZE_asm - 1, %ecx
23158+ shr $3, %ecx
23159+ repne scasq
23160+ jecxz 2f
23161+
23162+ cmp $2*8, %ecx
23163+ jc 2f
23164+
23165+ mov $2*8, %ecx
23166+ repe scasq
23167+ jecxz 2f
23168+ jne 1b
23169+
23170+2: cld
23171+ mov %esp, %ecx
23172+ sub %edi, %ecx
23173+
23174+ cmp $THREAD_SIZE_asm, %rcx
23175+ jb 3f
23176+ ud2
23177+3:
23178+
23179+ shr $3, %ecx
23180+ rep stosq
23181+
23182+ mov TI_task_thread_sp0(%r11), %rdi
23183+ sub $256, %rdi
23184+ mov %rdi, TI_lowest_stack(%r11)
23185+
23186+ popq %r11
23187+ popq %rax
23188+ popq %rcx
23189+ popq %rdi
23190+ pax_force_retaddr
23191+ ret
23192+ENDPROC(pax_erase_kstack)
23193+#endif
23194
23195 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23196 #ifdef CONFIG_TRACE_IRQFLAGS
23197@@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
23198 .endm
23199
23200 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23201- bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23202+ bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23203 jnc 1f
23204 TRACE_IRQS_ON_DEBUG
23205 1:
23206@@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
23207 movq \tmp,R11+\offset(%rsp)
23208 .endm
23209
23210- .macro FAKE_STACK_FRAME child_rip
23211- /* push in order ss, rsp, eflags, cs, rip */
23212- xorl %eax, %eax
23213- pushq_cfi $__KERNEL_DS /* ss */
23214- /*CFI_REL_OFFSET ss,0*/
23215- pushq_cfi %rax /* rsp */
23216- CFI_REL_OFFSET rsp,0
23217- pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23218- /*CFI_REL_OFFSET rflags,0*/
23219- pushq_cfi $__KERNEL_CS /* cs */
23220- /*CFI_REL_OFFSET cs,0*/
23221- pushq_cfi \child_rip /* rip */
23222- CFI_REL_OFFSET rip,0
23223- pushq_cfi %rax /* orig rax */
23224- .endm
23225-
23226- .macro UNFAKE_STACK_FRAME
23227- addq $8*6, %rsp
23228- CFI_ADJUST_CFA_OFFSET -(6*8)
23229- .endm
23230-
23231 /*
23232 * initial frame state for interrupts (and exceptions without error code)
23233 */
23234@@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
23235 /* save partial stack frame */
23236 .macro SAVE_ARGS_IRQ
23237 cld
23238- /* start from rbp in pt_regs and jump over */
23239- movq_cfi rdi, (RDI-RBP)
23240- movq_cfi rsi, (RSI-RBP)
23241- movq_cfi rdx, (RDX-RBP)
23242- movq_cfi rcx, (RCX-RBP)
23243- movq_cfi rax, (RAX-RBP)
23244- movq_cfi r8, (R8-RBP)
23245- movq_cfi r9, (R9-RBP)
23246- movq_cfi r10, (R10-RBP)
23247- movq_cfi r11, (R11-RBP)
23248+ /* start from r15 in pt_regs and jump over */
23249+ movq_cfi rdi, RDI
23250+ movq_cfi rsi, RSI
23251+ movq_cfi rdx, RDX
23252+ movq_cfi rcx, RCX
23253+ movq_cfi rax, RAX
23254+ movq_cfi r8, R8
23255+ movq_cfi r9, R9
23256+ movq_cfi r10, R10
23257+ movq_cfi r11, R11
23258+ movq_cfi r12, R12
23259
23260 /* Save rbp so that we can unwind from get_irq_regs() */
23261- movq_cfi rbp, 0
23262+ movq_cfi rbp, RBP
23263
23264 /* Save previous stack value */
23265 movq %rsp, %rsi
23266
23267- leaq -RBP(%rsp),%rdi /* arg1 for handler */
23268- testl $3, CS-RBP(%rsi)
23269+ movq %rsp,%rdi /* arg1 for handler */
23270+ testb $3, CS(%rsi)
23271 je 1f
23272 SWAPGS
23273 /*
23274@@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
23275 0x06 /* DW_OP_deref */, \
23276 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23277 0x22 /* DW_OP_plus */
23278+
23279+#ifdef CONFIG_PAX_MEMORY_UDEREF
23280+ testb $3, CS(%rdi)
23281+ jnz 1f
23282+ pax_enter_kernel
23283+ jmp 2f
23284+1: pax_enter_kernel_user
23285+2:
23286+#else
23287+ pax_enter_kernel
23288+#endif
23289+
23290 /* We entered an interrupt context - irqs are off: */
23291 TRACE_IRQS_OFF
23292 .endm
23293@@ -514,9 +939,52 @@ ENTRY(save_paranoid)
23294 js 1f /* negative -> in kernel */
23295 SWAPGS
23296 xorl %ebx,%ebx
23297-1: ret
23298+1:
23299+#ifdef CONFIG_PAX_MEMORY_UDEREF
23300+ testb $3, CS+8(%rsp)
23301+ jnz 1f
23302+ pax_enter_kernel
23303+ jmp 2f
23304+1: pax_enter_kernel_user
23305+2:
23306+#else
23307+ pax_enter_kernel
23308+#endif
23309+ pax_force_retaddr
23310+ ret
23311 CFI_ENDPROC
23312-END(save_paranoid)
23313+ENDPROC(save_paranoid)
23314+
23315+ENTRY(save_paranoid_nmi)
23316+ XCPT_FRAME 1 RDI+8
23317+ cld
23318+ movq_cfi rdi, RDI+8
23319+ movq_cfi rsi, RSI+8
23320+ movq_cfi rdx, RDX+8
23321+ movq_cfi rcx, RCX+8
23322+ movq_cfi rax, RAX+8
23323+ movq_cfi r8, R8+8
23324+ movq_cfi r9, R9+8
23325+ movq_cfi r10, R10+8
23326+ movq_cfi r11, R11+8
23327+ movq_cfi rbx, RBX+8
23328+ movq_cfi rbp, RBP+8
23329+ movq_cfi r12, R12+8
23330+ movq_cfi r13, R13+8
23331+ movq_cfi r14, R14+8
23332+ movq_cfi r15, R15+8
23333+ movl $1,%ebx
23334+ movl $MSR_GS_BASE,%ecx
23335+ rdmsr
23336+ testl %edx,%edx
23337+ js 1f /* negative -> in kernel */
23338+ SWAPGS
23339+ xorl %ebx,%ebx
23340+1: pax_enter_kernel_nmi
23341+ pax_force_retaddr
23342+ ret
23343+ CFI_ENDPROC
23344+ENDPROC(save_paranoid_nmi)
23345 .popsection
23346
23347 /*
23348@@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
23349
23350 RESTORE_REST
23351
23352- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23353+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23354 jz 1f
23355
23356 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23357@@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
23358 jmp ret_from_sys_call # go to the SYSRET fastpath
23359
23360 1:
23361- subq $REST_SKIP, %rsp # leave space for volatiles
23362- CFI_ADJUST_CFA_OFFSET REST_SKIP
23363 movq %rbp, %rdi
23364 call *%rbx
23365 movl $0, RAX(%rsp)
23366 RESTORE_REST
23367 jmp int_ret_from_sys_call
23368 CFI_ENDPROC
23369-END(ret_from_fork)
23370+ENDPROC(ret_from_fork)
23371
23372 /*
23373 * System call entry. Up to 6 arguments in registers are supported.
23374@@ -593,7 +1059,7 @@ END(ret_from_fork)
23375 ENTRY(system_call)
23376 CFI_STARTPROC simple
23377 CFI_SIGNAL_FRAME
23378- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23379+ CFI_DEF_CFA rsp,0
23380 CFI_REGISTER rip,rcx
23381 /*CFI_REGISTER rflags,r11*/
23382 SWAPGS_UNSAFE_STACK
23383@@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
23384
23385 movq %rsp,PER_CPU_VAR(old_rsp)
23386 movq PER_CPU_VAR(kernel_stack),%rsp
23387+ SAVE_ARGS 8*6,0
23388+ pax_enter_kernel_user
23389+
23390+#ifdef CONFIG_PAX_RANDKSTACK
23391+ pax_erase_kstack
23392+#endif
23393+
23394 /*
23395 * No need to follow this irqs off/on section - it's straight
23396 * and short:
23397 */
23398 ENABLE_INTERRUPTS(CLBR_NONE)
23399- SAVE_ARGS 8,0
23400 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23401 movq %rcx,RIP-ARGOFFSET(%rsp)
23402 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23403- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23404+ GET_THREAD_INFO(%rcx)
23405+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23406 jnz tracesys
23407 system_call_fastpath:
23408 #if __SYSCALL_MASK == ~0
23409@@ -639,10 +1112,13 @@ sysret_check:
23410 LOCKDEP_SYS_EXIT
23411 DISABLE_INTERRUPTS(CLBR_NONE)
23412 TRACE_IRQS_OFF
23413- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23414+ GET_THREAD_INFO(%rcx)
23415+ movl TI_flags(%rcx),%edx
23416 andl %edi,%edx
23417 jnz sysret_careful
23418 CFI_REMEMBER_STATE
23419+ pax_exit_kernel_user
23420+ pax_erase_kstack
23421 /*
23422 * sysretq will re-enable interrupts:
23423 */
23424@@ -701,6 +1177,9 @@ auditsys:
23425 movq %rax,%rsi /* 2nd arg: syscall number */
23426 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23427 call __audit_syscall_entry
23428+
23429+ pax_erase_kstack
23430+
23431 LOAD_ARGS 0 /* reload call-clobbered registers */
23432 jmp system_call_fastpath
23433
23434@@ -722,7 +1201,7 @@ sysret_audit:
23435 /* Do syscall tracing */
23436 tracesys:
23437 #ifdef CONFIG_AUDITSYSCALL
23438- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23439+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23440 jz auditsys
23441 #endif
23442 SAVE_REST
23443@@ -730,12 +1209,15 @@ tracesys:
23444 FIXUP_TOP_OF_STACK %rdi
23445 movq %rsp,%rdi
23446 call syscall_trace_enter
23447+
23448+ pax_erase_kstack
23449+
23450 /*
23451 * Reload arg registers from stack in case ptrace changed them.
23452 * We don't reload %rax because syscall_trace_enter() returned
23453 * the value it wants us to use in the table lookup.
23454 */
23455- LOAD_ARGS ARGOFFSET, 1
23456+ LOAD_ARGS 1
23457 RESTORE_REST
23458 #if __SYSCALL_MASK == ~0
23459 cmpq $__NR_syscall_max,%rax
23460@@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
23461 andl %edi,%edx
23462 jnz int_careful
23463 andl $~TS_COMPAT,TI_status(%rcx)
23464- jmp retint_swapgs
23465+ pax_exit_kernel_user
23466+ pax_erase_kstack
23467+ jmp retint_swapgs_pax
23468
23469 /* Either reschedule or signal or syscall exit tracking needed. */
23470 /* First do a reschedule test. */
23471@@ -811,7 +1295,7 @@ int_restore_rest:
23472 TRACE_IRQS_OFF
23473 jmp int_with_check
23474 CFI_ENDPROC
23475-END(system_call)
23476+ENDPROC(system_call)
23477
23478 .macro FORK_LIKE func
23479 ENTRY(stub_\func)
23480@@ -824,9 +1308,10 @@ ENTRY(stub_\func)
23481 DEFAULT_FRAME 0 8 /* offset 8: return address */
23482 call sys_\func
23483 RESTORE_TOP_OF_STACK %r11, 8
23484- ret $REST_SKIP /* pop extended registers */
23485+ pax_force_retaddr
23486+ ret
23487 CFI_ENDPROC
23488-END(stub_\func)
23489+ENDPROC(stub_\func)
23490 .endm
23491
23492 .macro FIXED_FRAME label,func
23493@@ -836,9 +1321,10 @@ ENTRY(\label)
23494 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23495 call \func
23496 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23497+ pax_force_retaddr
23498 ret
23499 CFI_ENDPROC
23500-END(\label)
23501+ENDPROC(\label)
23502 .endm
23503
23504 FORK_LIKE clone
23505@@ -846,19 +1332,6 @@ END(\label)
23506 FORK_LIKE vfork
23507 FIXED_FRAME stub_iopl, sys_iopl
23508
23509-ENTRY(ptregscall_common)
23510- DEFAULT_FRAME 1 8 /* offset 8: return address */
23511- RESTORE_TOP_OF_STACK %r11, 8
23512- movq_cfi_restore R15+8, r15
23513- movq_cfi_restore R14+8, r14
23514- movq_cfi_restore R13+8, r13
23515- movq_cfi_restore R12+8, r12
23516- movq_cfi_restore RBP+8, rbp
23517- movq_cfi_restore RBX+8, rbx
23518- ret $REST_SKIP /* pop extended registers */
23519- CFI_ENDPROC
23520-END(ptregscall_common)
23521-
23522 ENTRY(stub_execve)
23523 CFI_STARTPROC
23524 addq $8, %rsp
23525@@ -870,7 +1343,7 @@ ENTRY(stub_execve)
23526 RESTORE_REST
23527 jmp int_ret_from_sys_call
23528 CFI_ENDPROC
23529-END(stub_execve)
23530+ENDPROC(stub_execve)
23531
23532 /*
23533 * sigreturn is special because it needs to restore all registers on return.
23534@@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
23535 RESTORE_REST
23536 jmp int_ret_from_sys_call
23537 CFI_ENDPROC
23538-END(stub_rt_sigreturn)
23539+ENDPROC(stub_rt_sigreturn)
23540
23541 #ifdef CONFIG_X86_X32_ABI
23542 ENTRY(stub_x32_rt_sigreturn)
23543@@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
23544 RESTORE_REST
23545 jmp int_ret_from_sys_call
23546 CFI_ENDPROC
23547-END(stub_x32_rt_sigreturn)
23548+ENDPROC(stub_x32_rt_sigreturn)
23549
23550 ENTRY(stub_x32_execve)
23551 CFI_STARTPROC
23552@@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
23553 RESTORE_REST
23554 jmp int_ret_from_sys_call
23555 CFI_ENDPROC
23556-END(stub_x32_execve)
23557+ENDPROC(stub_x32_execve)
23558
23559 #endif
23560
23561@@ -952,7 +1425,7 @@ vector=vector+1
23562 2: jmp common_interrupt
23563 .endr
23564 CFI_ENDPROC
23565-END(irq_entries_start)
23566+ENDPROC(irq_entries_start)
23567
23568 .previous
23569 END(interrupt)
23570@@ -969,8 +1442,8 @@ END(interrupt)
23571 /* 0(%rsp): ~(interrupt number) */
23572 .macro interrupt func
23573 /* reserve pt_regs for scratch regs and rbp */
23574- subq $ORIG_RAX-RBP, %rsp
23575- CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23576+ subq $ORIG_RAX, %rsp
23577+ CFI_ADJUST_CFA_OFFSET ORIG_RAX
23578 SAVE_ARGS_IRQ
23579 call \func
23580 .endm
23581@@ -997,14 +1470,14 @@ ret_from_intr:
23582
23583 /* Restore saved previous stack */
23584 popq %rsi
23585- CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23586- leaq ARGOFFSET-RBP(%rsi), %rsp
23587+ CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23588+ movq %rsi, %rsp
23589 CFI_DEF_CFA_REGISTER rsp
23590- CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23591+ CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23592
23593 exit_intr:
23594 GET_THREAD_INFO(%rcx)
23595- testl $3,CS-ARGOFFSET(%rsp)
23596+ testb $3,CS-ARGOFFSET(%rsp)
23597 je retint_kernel
23598
23599 /* Interrupt came from user space */
23600@@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
23601 * The iretq could re-enable interrupts:
23602 */
23603 DISABLE_INTERRUPTS(CLBR_ANY)
23604+ pax_exit_kernel_user
23605+retint_swapgs_pax:
23606 TRACE_IRQS_IRETQ
23607 SWAPGS
23608 jmp restore_args
23609
23610 retint_restore_args: /* return to kernel space */
23611 DISABLE_INTERRUPTS(CLBR_ANY)
23612+ pax_exit_kernel
23613+ pax_force_retaddr (RIP-ARGOFFSET)
23614 /*
23615 * The iretq could re-enable interrupts:
23616 */
23617@@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
23618 #endif
23619
23620 CFI_ENDPROC
23621-END(common_interrupt)
23622+ENDPROC(common_interrupt)
23623 /*
23624 * End of kprobes section
23625 */
23626@@ -1130,7 +1607,7 @@ ENTRY(\sym)
23627 interrupt \do_sym
23628 jmp ret_from_intr
23629 CFI_ENDPROC
23630-END(\sym)
23631+ENDPROC(\sym)
23632 .endm
23633
23634 #ifdef CONFIG_TRACING
23635@@ -1218,7 +1695,7 @@ ENTRY(\sym)
23636 call \do_sym
23637 jmp error_exit /* %ebx: no swapgs flag */
23638 CFI_ENDPROC
23639-END(\sym)
23640+ENDPROC(\sym)
23641 .endm
23642
23643 .macro paranoidzeroentry sym do_sym
23644@@ -1236,10 +1713,10 @@ ENTRY(\sym)
23645 call \do_sym
23646 jmp paranoid_exit /* %ebx: no swapgs flag */
23647 CFI_ENDPROC
23648-END(\sym)
23649+ENDPROC(\sym)
23650 .endm
23651
23652-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23653+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23654 .macro paranoidzeroentry_ist sym do_sym ist
23655 ENTRY(\sym)
23656 INTR_FRAME
23657@@ -1252,12 +1729,18 @@ ENTRY(\sym)
23658 TRACE_IRQS_OFF_DEBUG
23659 movq %rsp,%rdi /* pt_regs pointer */
23660 xorl %esi,%esi /* no error code */
23661+#ifdef CONFIG_SMP
23662+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23663+ lea init_tss(%r13), %r13
23664+#else
23665+ lea init_tss(%rip), %r13
23666+#endif
23667 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23668 call \do_sym
23669 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23670 jmp paranoid_exit /* %ebx: no swapgs flag */
23671 CFI_ENDPROC
23672-END(\sym)
23673+ENDPROC(\sym)
23674 .endm
23675
23676 .macro errorentry sym do_sym
23677@@ -1275,7 +1758,7 @@ ENTRY(\sym)
23678 call \do_sym
23679 jmp error_exit /* %ebx: no swapgs flag */
23680 CFI_ENDPROC
23681-END(\sym)
23682+ENDPROC(\sym)
23683 .endm
23684
23685 #ifdef CONFIG_TRACING
23686@@ -1306,7 +1789,7 @@ ENTRY(\sym)
23687 call \do_sym
23688 jmp paranoid_exit /* %ebx: no swapgs flag */
23689 CFI_ENDPROC
23690-END(\sym)
23691+ENDPROC(\sym)
23692 .endm
23693
23694 zeroentry divide_error do_divide_error
23695@@ -1336,9 +1819,10 @@ gs_change:
23696 2: mfence /* workaround */
23697 SWAPGS
23698 popfq_cfi
23699+ pax_force_retaddr
23700 ret
23701 CFI_ENDPROC
23702-END(native_load_gs_index)
23703+ENDPROC(native_load_gs_index)
23704
23705 _ASM_EXTABLE(gs_change,bad_gs)
23706 .section .fixup,"ax"
23707@@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
23708 CFI_DEF_CFA_REGISTER rsp
23709 CFI_ADJUST_CFA_OFFSET -8
23710 decl PER_CPU_VAR(irq_count)
23711+ pax_force_retaddr
23712 ret
23713 CFI_ENDPROC
23714-END(do_softirq_own_stack)
23715+ENDPROC(do_softirq_own_stack)
23716
23717 #ifdef CONFIG_XEN
23718 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23719@@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23720 decl PER_CPU_VAR(irq_count)
23721 jmp error_exit
23722 CFI_ENDPROC
23723-END(xen_do_hypervisor_callback)
23724+ENDPROC(xen_do_hypervisor_callback)
23725
23726 /*
23727 * Hypervisor uses this for application faults while it executes.
23728@@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
23729 SAVE_ALL
23730 jmp error_exit
23731 CFI_ENDPROC
23732-END(xen_failsafe_callback)
23733+ENDPROC(xen_failsafe_callback)
23734
23735 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23736 xen_hvm_callback_vector xen_evtchn_do_upcall
23737@@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
23738 DEFAULT_FRAME
23739 DISABLE_INTERRUPTS(CLBR_NONE)
23740 TRACE_IRQS_OFF_DEBUG
23741- testl %ebx,%ebx /* swapgs needed? */
23742+ testl $1,%ebx /* swapgs needed? */
23743 jnz paranoid_restore
23744- testl $3,CS(%rsp)
23745+ testb $3,CS(%rsp)
23746 jnz paranoid_userspace
23747+#ifdef CONFIG_PAX_MEMORY_UDEREF
23748+ pax_exit_kernel
23749+ TRACE_IRQS_IRETQ 0
23750+ SWAPGS_UNSAFE_STACK
23751+ RESTORE_ALL 8
23752+ pax_force_retaddr_bts
23753+ jmp irq_return
23754+#endif
23755 paranoid_swapgs:
23756+#ifdef CONFIG_PAX_MEMORY_UDEREF
23757+ pax_exit_kernel_user
23758+#else
23759+ pax_exit_kernel
23760+#endif
23761 TRACE_IRQS_IRETQ 0
23762 SWAPGS_UNSAFE_STACK
23763 RESTORE_ALL 8
23764 jmp irq_return
23765 paranoid_restore:
23766+ pax_exit_kernel
23767 TRACE_IRQS_IRETQ_DEBUG 0
23768 RESTORE_ALL 8
23769+ pax_force_retaddr_bts
23770 jmp irq_return
23771 paranoid_userspace:
23772 GET_THREAD_INFO(%rcx)
23773@@ -1557,7 +2057,7 @@ paranoid_schedule:
23774 TRACE_IRQS_OFF
23775 jmp paranoid_userspace
23776 CFI_ENDPROC
23777-END(paranoid_exit)
23778+ENDPROC(paranoid_exit)
23779
23780 /*
23781 * Exception entry point. This expects an error code/orig_rax on the stack.
23782@@ -1584,12 +2084,23 @@ ENTRY(error_entry)
23783 movq_cfi r14, R14+8
23784 movq_cfi r15, R15+8
23785 xorl %ebx,%ebx
23786- testl $3,CS+8(%rsp)
23787+ testb $3,CS+8(%rsp)
23788 je error_kernelspace
23789 error_swapgs:
23790 SWAPGS
23791 error_sti:
23792+#ifdef CONFIG_PAX_MEMORY_UDEREF
23793+ testb $3, CS+8(%rsp)
23794+ jnz 1f
23795+ pax_enter_kernel
23796+ jmp 2f
23797+1: pax_enter_kernel_user
23798+2:
23799+#else
23800+ pax_enter_kernel
23801+#endif
23802 TRACE_IRQS_OFF
23803+ pax_force_retaddr
23804 ret
23805
23806 /*
23807@@ -1616,7 +2127,7 @@ bstep_iret:
23808 movq %rcx,RIP+8(%rsp)
23809 jmp error_swapgs
23810 CFI_ENDPROC
23811-END(error_entry)
23812+ENDPROC(error_entry)
23813
23814
23815 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23816@@ -1627,7 +2138,7 @@ ENTRY(error_exit)
23817 DISABLE_INTERRUPTS(CLBR_NONE)
23818 TRACE_IRQS_OFF
23819 GET_THREAD_INFO(%rcx)
23820- testl %eax,%eax
23821+ testl $1,%eax
23822 jne retint_kernel
23823 LOCKDEP_SYS_EXIT_IRQ
23824 movl TI_flags(%rcx),%edx
23825@@ -1636,7 +2147,7 @@ ENTRY(error_exit)
23826 jnz retint_careful
23827 jmp retint_swapgs
23828 CFI_ENDPROC
23829-END(error_exit)
23830+ENDPROC(error_exit)
23831
23832 /*
23833 * Test if a given stack is an NMI stack or not.
23834@@ -1694,9 +2205,11 @@ ENTRY(nmi)
23835 * If %cs was not the kernel segment, then the NMI triggered in user
23836 * space, which means it is definitely not nested.
23837 */
23838+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23839+ je 1f
23840 cmpl $__KERNEL_CS, 16(%rsp)
23841 jne first_nmi
23842-
23843+1:
23844 /*
23845 * Check the special variable on the stack to see if NMIs are
23846 * executing.
23847@@ -1730,8 +2243,7 @@ nested_nmi:
23848
23849 1:
23850 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
23851- leaq -1*8(%rsp), %rdx
23852- movq %rdx, %rsp
23853+ subq $8, %rsp
23854 CFI_ADJUST_CFA_OFFSET 1*8
23855 leaq -10*8(%rsp), %rdx
23856 pushq_cfi $__KERNEL_DS
23857@@ -1749,6 +2261,7 @@ nested_nmi_out:
23858 CFI_RESTORE rdx
23859
23860 /* No need to check faults here */
23861+# pax_force_retaddr_bts
23862 INTERRUPT_RETURN
23863
23864 CFI_RESTORE_STATE
23865@@ -1845,13 +2358,13 @@ end_repeat_nmi:
23866 subq $ORIG_RAX-R15, %rsp
23867 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
23868 /*
23869- * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
23870+ * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
23871 * as we should not be calling schedule in NMI context.
23872 * Even with normal interrupts enabled. An NMI should not be
23873 * setting NEED_RESCHED or anything that normal interrupts and
23874 * exceptions might do.
23875 */
23876- call save_paranoid
23877+ call save_paranoid_nmi
23878 DEFAULT_FRAME 0
23879
23880 /*
23881@@ -1861,9 +2374,9 @@ end_repeat_nmi:
23882 * NMI itself takes a page fault, the page fault that was preempted
23883 * will read the information from the NMI page fault and not the
23884 * origin fault. Save it off and restore it if it changes.
23885- * Use the r12 callee-saved register.
23886+ * Use the r13 callee-saved register.
23887 */
23888- movq %cr2, %r12
23889+ movq %cr2, %r13
23890
23891 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
23892 movq %rsp,%rdi
23893@@ -1872,31 +2385,36 @@ end_repeat_nmi:
23894
23895 /* Did the NMI take a page fault? Restore cr2 if it did */
23896 movq %cr2, %rcx
23897- cmpq %rcx, %r12
23898+ cmpq %rcx, %r13
23899 je 1f
23900- movq %r12, %cr2
23901+ movq %r13, %cr2
23902 1:
23903
23904- testl %ebx,%ebx /* swapgs needed? */
23905+ testl $1,%ebx /* swapgs needed? */
23906 jnz nmi_restore
23907 nmi_swapgs:
23908 SWAPGS_UNSAFE_STACK
23909 nmi_restore:
23910+ pax_exit_kernel_nmi
23911 /* Pop the extra iret frame at once */
23912 RESTORE_ALL 6*8
23913+ testb $3, 8(%rsp)
23914+ jnz 1f
23915+ pax_force_retaddr_bts
23916+1:
23917
23918 /* Clear the NMI executing stack variable */
23919 movq $0, 5*8(%rsp)
23920 jmp irq_return
23921 CFI_ENDPROC
23922-END(nmi)
23923+ENDPROC(nmi)
23924
23925 ENTRY(ignore_sysret)
23926 CFI_STARTPROC
23927 mov $-ENOSYS,%eax
23928 sysret
23929 CFI_ENDPROC
23930-END(ignore_sysret)
23931+ENDPROC(ignore_sysret)
23932
23933 /*
23934 * End of kprobes section
23935diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
23936index e625319..b9abb9d 100644
23937--- a/arch/x86/kernel/ftrace.c
23938+++ b/arch/x86/kernel/ftrace.c
23939@@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
23940 {
23941 unsigned char replaced[MCOUNT_INSN_SIZE];
23942
23943+ ip = ktla_ktva(ip);
23944+
23945 /*
23946 * Note: Due to modules and __init, code can
23947 * disappear and change, we need to protect against faulting
23948@@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
23949 unsigned char old[MCOUNT_INSN_SIZE];
23950 int ret;
23951
23952- memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
23953+ memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
23954
23955 ftrace_update_func = ip;
23956 /* Make sure the breakpoints see the ftrace_update_func update */
23957@@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
23958 * kernel identity mapping to modify code.
23959 */
23960 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
23961- ip = (unsigned long)__va(__pa_symbol(ip));
23962+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
23963
23964 return probe_kernel_write((void *)ip, val, size);
23965 }
23966@@ -316,7 +318,7 @@ static int add_break(unsigned long ip, const char *old)
23967 unsigned char replaced[MCOUNT_INSN_SIZE];
23968 unsigned char brk = BREAKPOINT_INSTRUCTION;
23969
23970- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
23971+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
23972 return -EFAULT;
23973
23974 /* Make sure it is what we expect it to be */
23975@@ -664,7 +666,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
23976 return ret;
23977
23978 fail_update:
23979- probe_kernel_write((void *)ip, &old_code[0], 1);
23980+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
23981 goto out;
23982 }
23983
23984diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
23985index 85126cc..1bbce17 100644
23986--- a/arch/x86/kernel/head64.c
23987+++ b/arch/x86/kernel/head64.c
23988@@ -67,12 +67,12 @@ again:
23989 pgd = *pgd_p;
23990
23991 /*
23992- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
23993- * critical -- __PAGE_OFFSET would point us back into the dynamic
23994+ * The use of __early_va rather than __va here is critical:
23995+ * __va would point us back into the dynamic
23996 * range and we might end up looping forever...
23997 */
23998 if (pgd)
23999- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24000+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24001 else {
24002 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24003 reset_early_page_tables();
24004@@ -82,13 +82,13 @@ again:
24005 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24006 for (i = 0; i < PTRS_PER_PUD; i++)
24007 pud_p[i] = 0;
24008- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24009+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24010 }
24011 pud_p += pud_index(address);
24012 pud = *pud_p;
24013
24014 if (pud)
24015- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24016+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24017 else {
24018 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24019 reset_early_page_tables();
24020@@ -98,7 +98,7 @@ again:
24021 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24022 for (i = 0; i < PTRS_PER_PMD; i++)
24023 pmd_p[i] = 0;
24024- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24025+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24026 }
24027 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24028 pmd_p[pmd_index(address)] = pmd;
24029@@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
24030 if (console_loglevel == 10)
24031 early_printk("Kernel alive\n");
24032
24033- clear_page(init_level4_pgt);
24034 /* set init_level4_pgt kernel high mapping*/
24035 init_level4_pgt[511] = early_level4_pgt[511];
24036
24037diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24038index f36bd42..56ee1534 100644
24039--- a/arch/x86/kernel/head_32.S
24040+++ b/arch/x86/kernel/head_32.S
24041@@ -26,6 +26,12 @@
24042 /* Physical address */
24043 #define pa(X) ((X) - __PAGE_OFFSET)
24044
24045+#ifdef CONFIG_PAX_KERNEXEC
24046+#define ta(X) (X)
24047+#else
24048+#define ta(X) ((X) - __PAGE_OFFSET)
24049+#endif
24050+
24051 /*
24052 * References to members of the new_cpu_data structure.
24053 */
24054@@ -55,11 +61,7 @@
24055 * and small than max_low_pfn, otherwise will waste some page table entries
24056 */
24057
24058-#if PTRS_PER_PMD > 1
24059-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24060-#else
24061-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24062-#endif
24063+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24064
24065 /* Number of possible pages in the lowmem region */
24066 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24067@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24068 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24069
24070 /*
24071+ * Real beginning of normal "text" segment
24072+ */
24073+ENTRY(stext)
24074+ENTRY(_stext)
24075+
24076+/*
24077 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24078 * %esi points to the real-mode code as a 32-bit pointer.
24079 * CS and DS must be 4 GB flat segments, but we don't depend on
24080@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24081 * can.
24082 */
24083 __HEAD
24084+
24085+#ifdef CONFIG_PAX_KERNEXEC
24086+ jmp startup_32
24087+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24088+.fill PAGE_SIZE-5,1,0xcc
24089+#endif
24090+
24091 ENTRY(startup_32)
24092 movl pa(stack_start),%ecx
24093
24094@@ -106,6 +121,59 @@ ENTRY(startup_32)
24095 2:
24096 leal -__PAGE_OFFSET(%ecx),%esp
24097
24098+#ifdef CONFIG_SMP
24099+ movl $pa(cpu_gdt_table),%edi
24100+ movl $__per_cpu_load,%eax
24101+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24102+ rorl $16,%eax
24103+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24104+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24105+ movl $__per_cpu_end - 1,%eax
24106+ subl $__per_cpu_start,%eax
24107+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24108+#endif
24109+
24110+#ifdef CONFIG_PAX_MEMORY_UDEREF
24111+ movl $NR_CPUS,%ecx
24112+ movl $pa(cpu_gdt_table),%edi
24113+1:
24114+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24115+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24116+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24117+ addl $PAGE_SIZE_asm,%edi
24118+ loop 1b
24119+#endif
24120+
24121+#ifdef CONFIG_PAX_KERNEXEC
24122+ movl $pa(boot_gdt),%edi
24123+ movl $__LOAD_PHYSICAL_ADDR,%eax
24124+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24125+ rorl $16,%eax
24126+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24127+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24128+ rorl $16,%eax
24129+
24130+ ljmp $(__BOOT_CS),$1f
24131+1:
24132+
24133+ movl $NR_CPUS,%ecx
24134+ movl $pa(cpu_gdt_table),%edi
24135+ addl $__PAGE_OFFSET,%eax
24136+1:
24137+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24138+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24139+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24140+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24141+ rorl $16,%eax
24142+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24143+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24144+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24145+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24146+ rorl $16,%eax
24147+ addl $PAGE_SIZE_asm,%edi
24148+ loop 1b
24149+#endif
24150+
24151 /*
24152 * Clear BSS first so that there are no surprises...
24153 */
24154@@ -201,8 +269,11 @@ ENTRY(startup_32)
24155 movl %eax, pa(max_pfn_mapped)
24156
24157 /* Do early initialization of the fixmap area */
24158- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24159- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24160+#ifdef CONFIG_COMPAT_VDSO
24161+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24162+#else
24163+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24164+#endif
24165 #else /* Not PAE */
24166
24167 page_pde_offset = (__PAGE_OFFSET >> 20);
24168@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24169 movl %eax, pa(max_pfn_mapped)
24170
24171 /* Do early initialization of the fixmap area */
24172- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24173- movl %eax,pa(initial_page_table+0xffc)
24174+#ifdef CONFIG_COMPAT_VDSO
24175+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24176+#else
24177+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24178+#endif
24179 #endif
24180
24181 #ifdef CONFIG_PARAVIRT
24182@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24183 cmpl $num_subarch_entries, %eax
24184 jae bad_subarch
24185
24186- movl pa(subarch_entries)(,%eax,4), %eax
24187- subl $__PAGE_OFFSET, %eax
24188- jmp *%eax
24189+ jmp *pa(subarch_entries)(,%eax,4)
24190
24191 bad_subarch:
24192 WEAK(lguest_entry)
24193@@ -261,10 +333,10 @@ WEAK(xen_entry)
24194 __INITDATA
24195
24196 subarch_entries:
24197- .long default_entry /* normal x86/PC */
24198- .long lguest_entry /* lguest hypervisor */
24199- .long xen_entry /* Xen hypervisor */
24200- .long default_entry /* Moorestown MID */
24201+ .long ta(default_entry) /* normal x86/PC */
24202+ .long ta(lguest_entry) /* lguest hypervisor */
24203+ .long ta(xen_entry) /* Xen hypervisor */
24204+ .long ta(default_entry) /* Moorestown MID */
24205 num_subarch_entries = (. - subarch_entries) / 4
24206 .previous
24207 #else
24208@@ -354,6 +426,7 @@ default_entry:
24209 movl pa(mmu_cr4_features),%eax
24210 movl %eax,%cr4
24211
24212+#ifdef CONFIG_X86_PAE
24213 testb $X86_CR4_PAE, %al # check if PAE is enabled
24214 jz enable_paging
24215
24216@@ -382,6 +455,9 @@ default_entry:
24217 /* Make changes effective */
24218 wrmsr
24219
24220+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24221+#endif
24222+
24223 enable_paging:
24224
24225 /*
24226@@ -449,14 +525,20 @@ is486:
24227 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24228 movl %eax,%ss # after changing gdt.
24229
24230- movl $(__USER_DS),%eax # DS/ES contains default USER segment
24231+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24232 movl %eax,%ds
24233 movl %eax,%es
24234
24235 movl $(__KERNEL_PERCPU), %eax
24236 movl %eax,%fs # set this cpu's percpu
24237
24238+#ifdef CONFIG_CC_STACKPROTECTOR
24239 movl $(__KERNEL_STACK_CANARY),%eax
24240+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24241+ movl $(__USER_DS),%eax
24242+#else
24243+ xorl %eax,%eax
24244+#endif
24245 movl %eax,%gs
24246
24247 xorl %eax,%eax # Clear LDT
24248@@ -512,8 +594,11 @@ setup_once:
24249 * relocation. Manually set base address in stack canary
24250 * segment descriptor.
24251 */
24252- movl $gdt_page,%eax
24253+ movl $cpu_gdt_table,%eax
24254 movl $stack_canary,%ecx
24255+#ifdef CONFIG_SMP
24256+ addl $__per_cpu_load,%ecx
24257+#endif
24258 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24259 shrl $16, %ecx
24260 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24261@@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24262 cmpl $2,(%esp) # X86_TRAP_NMI
24263 je is_nmi # Ignore NMI
24264
24265- cmpl $2,%ss:early_recursion_flag
24266+ cmpl $1,%ss:early_recursion_flag
24267 je hlt_loop
24268 incl %ss:early_recursion_flag
24269
24270@@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24271 pushl (20+6*4)(%esp) /* trapno */
24272 pushl $fault_msg
24273 call printk
24274-#endif
24275 call dump_stack
24276+#endif
24277 hlt_loop:
24278 hlt
24279 jmp hlt_loop
24280@@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24281 /* This is the default interrupt "handler" :-) */
24282 ALIGN
24283 ignore_int:
24284- cld
24285 #ifdef CONFIG_PRINTK
24286+ cmpl $2,%ss:early_recursion_flag
24287+ je hlt_loop
24288+ incl %ss:early_recursion_flag
24289+ cld
24290 pushl %eax
24291 pushl %ecx
24292 pushl %edx
24293@@ -617,9 +705,6 @@ ignore_int:
24294 movl $(__KERNEL_DS),%eax
24295 movl %eax,%ds
24296 movl %eax,%es
24297- cmpl $2,early_recursion_flag
24298- je hlt_loop
24299- incl early_recursion_flag
24300 pushl 16(%esp)
24301 pushl 24(%esp)
24302 pushl 32(%esp)
24303@@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24304 /*
24305 * BSS section
24306 */
24307-__PAGE_ALIGNED_BSS
24308- .align PAGE_SIZE
24309 #ifdef CONFIG_X86_PAE
24310+.section .initial_pg_pmd,"a",@progbits
24311 initial_pg_pmd:
24312 .fill 1024*KPMDS,4,0
24313 #else
24314+.section .initial_page_table,"a",@progbits
24315 ENTRY(initial_page_table)
24316 .fill 1024,4,0
24317 #endif
24318+.section .initial_pg_fixmap,"a",@progbits
24319 initial_pg_fixmap:
24320 .fill 1024,4,0
24321+.section .empty_zero_page,"a",@progbits
24322 ENTRY(empty_zero_page)
24323 .fill 4096,1,0
24324+.section .swapper_pg_dir,"a",@progbits
24325 ENTRY(swapper_pg_dir)
24326+#ifdef CONFIG_X86_PAE
24327+ .fill 4,8,0
24328+#else
24329 .fill 1024,4,0
24330+#endif
24331
24332 /*
24333 * This starts the data section.
24334 */
24335 #ifdef CONFIG_X86_PAE
24336-__PAGE_ALIGNED_DATA
24337- /* Page-aligned for the benefit of paravirt? */
24338- .align PAGE_SIZE
24339+.section .initial_page_table,"a",@progbits
24340 ENTRY(initial_page_table)
24341 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24342 # if KPMDS == 3
24343@@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24344 # error "Kernel PMDs should be 1, 2 or 3"
24345 # endif
24346 .align PAGE_SIZE /* needs to be page-sized too */
24347+
24348+#ifdef CONFIG_PAX_PER_CPU_PGD
24349+ENTRY(cpu_pgd)
24350+ .rept 2*NR_CPUS
24351+ .fill 4,8,0
24352+ .endr
24353+#endif
24354+
24355 #endif
24356
24357 .data
24358 .balign 4
24359 ENTRY(stack_start)
24360- .long init_thread_union+THREAD_SIZE
24361+ .long init_thread_union+THREAD_SIZE-8
24362
24363 __INITRODATA
24364 int_msg:
24365@@ -727,7 +825,7 @@ fault_msg:
24366 * segment size, and 32-bit linear address value:
24367 */
24368
24369- .data
24370+.section .rodata,"a",@progbits
24371 .globl boot_gdt_descr
24372 .globl idt_descr
24373
24374@@ -736,7 +834,7 @@ fault_msg:
24375 .word 0 # 32 bit align gdt_desc.address
24376 boot_gdt_descr:
24377 .word __BOOT_DS+7
24378- .long boot_gdt - __PAGE_OFFSET
24379+ .long pa(boot_gdt)
24380
24381 .word 0 # 32-bit align idt_desc.address
24382 idt_descr:
24383@@ -747,7 +845,7 @@ idt_descr:
24384 .word 0 # 32 bit align gdt_desc.address
24385 ENTRY(early_gdt_descr)
24386 .word GDT_ENTRIES*8-1
24387- .long gdt_page /* Overwritten for secondary CPUs */
24388+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
24389
24390 /*
24391 * The boot_gdt must mirror the equivalent in setup.S and is
24392@@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24393 .align L1_CACHE_BYTES
24394 ENTRY(boot_gdt)
24395 .fill GDT_ENTRY_BOOT_CS,8,0
24396- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24397- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24398+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24399+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24400+
24401+ .align PAGE_SIZE_asm
24402+ENTRY(cpu_gdt_table)
24403+ .rept NR_CPUS
24404+ .quad 0x0000000000000000 /* NULL descriptor */
24405+ .quad 0x0000000000000000 /* 0x0b reserved */
24406+ .quad 0x0000000000000000 /* 0x13 reserved */
24407+ .quad 0x0000000000000000 /* 0x1b reserved */
24408+
24409+#ifdef CONFIG_PAX_KERNEXEC
24410+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24411+#else
24412+ .quad 0x0000000000000000 /* 0x20 unused */
24413+#endif
24414+
24415+ .quad 0x0000000000000000 /* 0x28 unused */
24416+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24417+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24418+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24419+ .quad 0x0000000000000000 /* 0x4b reserved */
24420+ .quad 0x0000000000000000 /* 0x53 reserved */
24421+ .quad 0x0000000000000000 /* 0x5b reserved */
24422+
24423+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24424+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24425+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24426+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24427+
24428+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24429+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24430+
24431+ /*
24432+ * Segments used for calling PnP BIOS have byte granularity.
24433+ * The code segments and data segments have fixed 64k limits,
24434+ * the transfer segment sizes are set at run time.
24435+ */
24436+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
24437+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
24438+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
24439+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
24440+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
24441+
24442+ /*
24443+ * The APM segments have byte granularity and their bases
24444+ * are set at run time. All have 64k limits.
24445+ */
24446+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24447+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24448+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
24449+
24450+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
24451+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24452+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24453+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24454+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24455+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24456+
24457+ /* Be sure this is zeroed to avoid false validations in Xen */
24458+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24459+ .endr
24460diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24461index a468c0a..c7dec74 100644
24462--- a/arch/x86/kernel/head_64.S
24463+++ b/arch/x86/kernel/head_64.S
24464@@ -20,6 +20,8 @@
24465 #include <asm/processor-flags.h>
24466 #include <asm/percpu.h>
24467 #include <asm/nops.h>
24468+#include <asm/cpufeature.h>
24469+#include <asm/alternative-asm.h>
24470
24471 #ifdef CONFIG_PARAVIRT
24472 #include <asm/asm-offsets.h>
24473@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24474 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24475 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24476 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24477+L4_VMALLOC_START = pgd_index(VMALLOC_START)
24478+L3_VMALLOC_START = pud_index(VMALLOC_START)
24479+L4_VMALLOC_END = pgd_index(VMALLOC_END)
24480+L3_VMALLOC_END = pud_index(VMALLOC_END)
24481+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24482+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24483
24484 .text
24485 __HEAD
24486@@ -89,11 +97,24 @@ startup_64:
24487 * Fixup the physical addresses in the page table
24488 */
24489 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24490+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24491+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24492+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24493+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24494+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24495
24496- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24497- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24498+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
24499+#ifndef CONFIG_XEN
24500+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
24501+#endif
24502+
24503+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24504+
24505+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24506+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24507
24508 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24509+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24510
24511 /*
24512 * Set up the identity mapping for the switchover. These
24513@@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24514 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24515 1:
24516
24517- /* Enable PAE mode and PGE */
24518- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24519+ /* Enable PAE mode and PSE/PGE */
24520+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24521 movq %rcx, %cr4
24522
24523 /* Setup early boot stage 4 level pagetables. */
24524@@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24525 movl $MSR_EFER, %ecx
24526 rdmsr
24527 btsl $_EFER_SCE, %eax /* Enable System Call */
24528- btl $20,%edi /* No Execute supported? */
24529+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24530 jnc 1f
24531 btsl $_EFER_NX, %eax
24532 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24533+#ifndef CONFIG_EFI
24534+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24535+#endif
24536+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24537+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24538+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24539+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24540+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24541+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24542 1: wrmsr /* Make changes effective */
24543
24544 /* Setup cr0 */
24545@@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24546 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24547 * address given in m16:64.
24548 */
24549+ pax_set_fptr_mask
24550 movq initial_code(%rip),%rax
24551 pushq $0 # fake return address to stop unwinder
24552 pushq $__KERNEL_CS # set correct cs
24553@@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
24554 .quad INIT_PER_CPU_VAR(irq_stack_union)
24555
24556 GLOBAL(stack_start)
24557- .quad init_thread_union+THREAD_SIZE-8
24558+ .quad init_thread_union+THREAD_SIZE-16
24559 .word 0
24560 __FINITDATA
24561
24562@@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
24563 call dump_stack
24564 #ifdef CONFIG_KALLSYMS
24565 leaq early_idt_ripmsg(%rip),%rdi
24566- movq 40(%rsp),%rsi # %rip again
24567+ movq 88(%rsp),%rsi # %rip again
24568 call __print_symbol
24569 #endif
24570 #endif /* EARLY_PRINTK */
24571@@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
24572 early_recursion_flag:
24573 .long 0
24574
24575+ .section .rodata,"a",@progbits
24576 #ifdef CONFIG_EARLY_PRINTK
24577 early_idt_msg:
24578 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24579@@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
24580 NEXT_PAGE(early_dynamic_pgts)
24581 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24582
24583- .data
24584+ .section .rodata,"a",@progbits
24585
24586-#ifndef CONFIG_XEN
24587 NEXT_PAGE(init_level4_pgt)
24588- .fill 512,8,0
24589-#else
24590-NEXT_PAGE(init_level4_pgt)
24591- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24592 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24593 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24594+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
24595+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24596+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
24597+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24598+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24599+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24600 .org init_level4_pgt + L4_START_KERNEL*8, 0
24601 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24602 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24603
24604+#ifdef CONFIG_PAX_PER_CPU_PGD
24605+NEXT_PAGE(cpu_pgd)
24606+ .rept 2*NR_CPUS
24607+ .fill 512,8,0
24608+ .endr
24609+#endif
24610+
24611 NEXT_PAGE(level3_ident_pgt)
24612 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24613+#ifdef CONFIG_XEN
24614 .fill 511, 8, 0
24615+#else
24616+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24617+ .fill 510,8,0
24618+#endif
24619+
24620+NEXT_PAGE(level3_vmalloc_start_pgt)
24621+ .fill 512,8,0
24622+
24623+NEXT_PAGE(level3_vmalloc_end_pgt)
24624+ .fill 512,8,0
24625+
24626+NEXT_PAGE(level3_vmemmap_pgt)
24627+ .fill L3_VMEMMAP_START,8,0
24628+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24629+
24630 NEXT_PAGE(level2_ident_pgt)
24631- /* Since I easily can, map the first 1G.
24632+ /* Since I easily can, map the first 2G.
24633 * Don't set NX because code runs from these pages.
24634 */
24635- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24636-#endif
24637+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24638
24639 NEXT_PAGE(level3_kernel_pgt)
24640 .fill L3_START_KERNEL,8,0
24641@@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
24642 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24643 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24644
24645+NEXT_PAGE(level2_vmemmap_pgt)
24646+ .fill 512,8,0
24647+
24648 NEXT_PAGE(level2_kernel_pgt)
24649 /*
24650 * 512 MB kernel mapping. We spend a full page on this pagetable
24651@@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
24652 NEXT_PAGE(level2_fixmap_pgt)
24653 .fill 506,8,0
24654 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24655- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24656- .fill 5,8,0
24657+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24658+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24659+ .fill 4,8,0
24660
24661 NEXT_PAGE(level1_fixmap_pgt)
24662 .fill 512,8,0
24663
24664+NEXT_PAGE(level1_vsyscall_pgt)
24665+ .fill 512,8,0
24666+
24667 #undef PMDS
24668
24669- .data
24670+ .align PAGE_SIZE
24671+ENTRY(cpu_gdt_table)
24672+ .rept NR_CPUS
24673+ .quad 0x0000000000000000 /* NULL descriptor */
24674+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24675+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
24676+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
24677+ .quad 0x00cffb000000ffff /* __USER32_CS */
24678+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24679+ .quad 0x00affb000000ffff /* __USER_CS */
24680+
24681+#ifdef CONFIG_PAX_KERNEXEC
24682+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24683+#else
24684+ .quad 0x0 /* unused */
24685+#endif
24686+
24687+ .quad 0,0 /* TSS */
24688+ .quad 0,0 /* LDT */
24689+ .quad 0,0,0 /* three TLS descriptors */
24690+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
24691+ /* asm/segment.h:GDT_ENTRIES must match this */
24692+
24693+#ifdef CONFIG_PAX_MEMORY_UDEREF
24694+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24695+#else
24696+ .quad 0x0 /* unused */
24697+#endif
24698+
24699+ /* zero the remaining page */
24700+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24701+ .endr
24702+
24703 .align 16
24704 .globl early_gdt_descr
24705 early_gdt_descr:
24706 .word GDT_ENTRIES*8-1
24707 early_gdt_descr_base:
24708- .quad INIT_PER_CPU_VAR(gdt_page)
24709+ .quad cpu_gdt_table
24710
24711 ENTRY(phys_base)
24712 /* This must match the first entry in level2_kernel_pgt */
24713 .quad 0x0000000000000000
24714
24715 #include "../../x86/xen/xen-head.S"
24716-
24717- __PAGE_ALIGNED_BSS
24718+
24719+ .section .rodata,"a",@progbits
24720 NEXT_PAGE(empty_zero_page)
24721 .skip PAGE_SIZE
24722diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24723index 05fd74f..c3548b1 100644
24724--- a/arch/x86/kernel/i386_ksyms_32.c
24725+++ b/arch/x86/kernel/i386_ksyms_32.c
24726@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24727 EXPORT_SYMBOL(cmpxchg8b_emu);
24728 #endif
24729
24730+EXPORT_SYMBOL_GPL(cpu_gdt_table);
24731+
24732 /* Networking helper routines. */
24733 EXPORT_SYMBOL(csum_partial_copy_generic);
24734+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24735+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24736
24737 EXPORT_SYMBOL(__get_user_1);
24738 EXPORT_SYMBOL(__get_user_2);
24739@@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
24740 EXPORT_SYMBOL(___preempt_schedule_context);
24741 #endif
24742 #endif
24743+
24744+#ifdef CONFIG_PAX_KERNEXEC
24745+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24746+#endif
24747+
24748+#ifdef CONFIG_PAX_PER_CPU_PGD
24749+EXPORT_SYMBOL(cpu_pgd);
24750+#endif
24751diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24752index d5dd808..b6432cf 100644
24753--- a/arch/x86/kernel/i387.c
24754+++ b/arch/x86/kernel/i387.c
24755@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24756 static inline bool interrupted_user_mode(void)
24757 {
24758 struct pt_regs *regs = get_irq_regs();
24759- return regs && user_mode_vm(regs);
24760+ return regs && user_mode(regs);
24761 }
24762
24763 /*
24764diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24765index 2e977b5..5f2c273 100644
24766--- a/arch/x86/kernel/i8259.c
24767+++ b/arch/x86/kernel/i8259.c
24768@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24769 static void make_8259A_irq(unsigned int irq)
24770 {
24771 disable_irq_nosync(irq);
24772- io_apic_irqs &= ~(1<<irq);
24773+ io_apic_irqs &= ~(1UL<<irq);
24774 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24775 i8259A_chip.name);
24776 enable_irq(irq);
24777@@ -209,7 +209,7 @@ spurious_8259A_irq:
24778 "spurious 8259A interrupt: IRQ%d.\n", irq);
24779 spurious_irq_mask |= irqmask;
24780 }
24781- atomic_inc(&irq_err_count);
24782+ atomic_inc_unchecked(&irq_err_count);
24783 /*
24784 * Theoretically we do not have to handle this IRQ,
24785 * but in Linux this does not cause problems and is
24786@@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
24787 /* (slave's support for AEOI in flat mode is to be investigated) */
24788 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24789
24790+ pax_open_kernel();
24791 if (auto_eoi)
24792 /*
24793 * In AEOI mode we just have to mask the interrupt
24794 * when acking.
24795 */
24796- i8259A_chip.irq_mask_ack = disable_8259A_irq;
24797+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24798 else
24799- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24800+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24801+ pax_close_kernel();
24802
24803 udelay(100); /* wait for 8259A to initialize */
24804
24805diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24806index a979b5b..1d6db75 100644
24807--- a/arch/x86/kernel/io_delay.c
24808+++ b/arch/x86/kernel/io_delay.c
24809@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24810 * Quirk table for systems that misbehave (lock up, etc.) if port
24811 * 0x80 is used:
24812 */
24813-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24814+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24815 {
24816 .callback = dmi_io_delay_0xed_port,
24817 .ident = "Compaq Presario V6000",
24818diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24819index 4ddaf66..49d5c18 100644
24820--- a/arch/x86/kernel/ioport.c
24821+++ b/arch/x86/kernel/ioport.c
24822@@ -6,6 +6,7 @@
24823 #include <linux/sched.h>
24824 #include <linux/kernel.h>
24825 #include <linux/capability.h>
24826+#include <linux/security.h>
24827 #include <linux/errno.h>
24828 #include <linux/types.h>
24829 #include <linux/ioport.h>
24830@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24831 return -EINVAL;
24832 if (turn_on && !capable(CAP_SYS_RAWIO))
24833 return -EPERM;
24834+#ifdef CONFIG_GRKERNSEC_IO
24835+ if (turn_on && grsec_disable_privio) {
24836+ gr_handle_ioperm();
24837+ return -ENODEV;
24838+ }
24839+#endif
24840
24841 /*
24842 * If it's the first ioperm() call in this thread's lifetime, set the
24843@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24844 * because the ->io_bitmap_max value must match the bitmap
24845 * contents:
24846 */
24847- tss = &per_cpu(init_tss, get_cpu());
24848+ tss = init_tss + get_cpu();
24849
24850 if (turn_on)
24851 bitmap_clear(t->io_bitmap_ptr, from, num);
24852@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
24853 if (level > old) {
24854 if (!capable(CAP_SYS_RAWIO))
24855 return -EPERM;
24856+#ifdef CONFIG_GRKERNSEC_IO
24857+ if (grsec_disable_privio) {
24858+ gr_handle_iopl();
24859+ return -ENODEV;
24860+ }
24861+#endif
24862 }
24863 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
24864 t->iopl = level << 12;
24865diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
24866index 22d0687..e07b2a5 100644
24867--- a/arch/x86/kernel/irq.c
24868+++ b/arch/x86/kernel/irq.c
24869@@ -21,7 +21,7 @@
24870 #define CREATE_TRACE_POINTS
24871 #include <asm/trace/irq_vectors.h>
24872
24873-atomic_t irq_err_count;
24874+atomic_unchecked_t irq_err_count;
24875
24876 /* Function pointer for generic interrupt vector handling */
24877 void (*x86_platform_ipi_callback)(void) = NULL;
24878@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
24879 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
24880 seq_printf(p, " Machine check polls\n");
24881 #endif
24882- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
24883+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
24884 #if defined(CONFIG_X86_IO_APIC)
24885- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
24886+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
24887 #endif
24888 return 0;
24889 }
24890@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
24891
24892 u64 arch_irq_stat(void)
24893 {
24894- u64 sum = atomic_read(&irq_err_count);
24895+ u64 sum = atomic_read_unchecked(&irq_err_count);
24896 return sum;
24897 }
24898
24899diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
24900index d7fcbed..1f747f7 100644
24901--- a/arch/x86/kernel/irq_32.c
24902+++ b/arch/x86/kernel/irq_32.c
24903@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
24904 __asm__ __volatile__("andl %%esp,%0" :
24905 "=r" (sp) : "0" (THREAD_SIZE - 1));
24906
24907- return sp < (sizeof(struct thread_info) + STACK_WARN);
24908+ return sp < STACK_WARN;
24909 }
24910
24911 static void print_stack_overflow(void)
24912@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
24913 * per-CPU IRQ handling contexts (thread information and stack)
24914 */
24915 union irq_ctx {
24916- struct thread_info tinfo;
24917- u32 stack[THREAD_SIZE/sizeof(u32)];
24918+ unsigned long previous_esp;
24919+ u32 stack[THREAD_SIZE/sizeof(u32)];
24920 } __attribute__((aligned(THREAD_SIZE)));
24921
24922 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
24923@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
24924 static inline int
24925 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24926 {
24927- union irq_ctx *curctx, *irqctx;
24928+ union irq_ctx *irqctx;
24929 u32 *isp, arg1, arg2;
24930
24931- curctx = (union irq_ctx *) current_thread_info();
24932 irqctx = __this_cpu_read(hardirq_ctx);
24933
24934 /*
24935@@ -92,13 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24936 * handler) we can't do that and just have to keep using the
24937 * current stack (which is the irq stack already after all)
24938 */
24939- if (unlikely(curctx == irqctx))
24940+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
24941 return 0;
24942
24943 /* build the stack frame on the IRQ stack */
24944- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24945- irqctx->tinfo.task = curctx->tinfo.task;
24946- irqctx->tinfo.previous_esp = current_stack_pointer;
24947+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24948+ irqctx->previous_esp = current_stack_pointer;
24949+
24950+#ifdef CONFIG_PAX_MEMORY_UDEREF
24951+ __set_fs(MAKE_MM_SEG(0));
24952+#endif
24953
24954 if (unlikely(overflow))
24955 call_on_stack(print_stack_overflow, isp);
24956@@ -110,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24957 : "0" (irq), "1" (desc), "2" (isp),
24958 "D" (desc->handle_irq)
24959 : "memory", "cc", "ecx");
24960+
24961+#ifdef CONFIG_PAX_MEMORY_UDEREF
24962+ __set_fs(current_thread_info()->addr_limit);
24963+#endif
24964+
24965 return 1;
24966 }
24967
24968@@ -118,48 +125,34 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24969 */
24970 void irq_ctx_init(int cpu)
24971 {
24972- union irq_ctx *irqctx;
24973-
24974 if (per_cpu(hardirq_ctx, cpu))
24975 return;
24976
24977- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24978- THREADINFO_GFP,
24979- THREAD_SIZE_ORDER));
24980- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24981- irqctx->tinfo.cpu = cpu;
24982- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24983-
24984- per_cpu(hardirq_ctx, cpu) = irqctx;
24985-
24986- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24987- THREADINFO_GFP,
24988- THREAD_SIZE_ORDER));
24989- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24990- irqctx->tinfo.cpu = cpu;
24991- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24992-
24993- per_cpu(softirq_ctx, cpu) = irqctx;
24994-
24995- printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
24996- cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
24997+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24998+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24999 }
25000
25001 void do_softirq_own_stack(void)
25002 {
25003- struct thread_info *curctx;
25004 union irq_ctx *irqctx;
25005 u32 *isp;
25006
25007- curctx = current_thread_info();
25008 irqctx = __this_cpu_read(softirq_ctx);
25009- irqctx->tinfo.task = curctx->task;
25010- irqctx->tinfo.previous_esp = current_stack_pointer;
25011+ irqctx->previous_esp = current_stack_pointer;
25012
25013 /* build the stack frame on the softirq stack */
25014- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
25015+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
25016+
25017+#ifdef CONFIG_PAX_MEMORY_UDEREF
25018+ __set_fs(MAKE_MM_SEG(0));
25019+#endif
25020
25021 call_on_stack(__do_softirq, isp);
25022+
25023+#ifdef CONFIG_PAX_MEMORY_UDEREF
25024+ __set_fs(current_thread_info()->addr_limit);
25025+#endif
25026+
25027 }
25028
25029 bool handle_irq(unsigned irq, struct pt_regs *regs)
25030@@ -173,7 +166,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25031 if (unlikely(!desc))
25032 return false;
25033
25034- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25035+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25036 if (unlikely(overflow))
25037 print_stack_overflow();
25038 desc->handle_irq(irq, desc);
25039diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25040index 4d1c746..232961d 100644
25041--- a/arch/x86/kernel/irq_64.c
25042+++ b/arch/x86/kernel/irq_64.c
25043@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25044 u64 estack_top, estack_bottom;
25045 u64 curbase = (u64)task_stack_page(current);
25046
25047- if (user_mode_vm(regs))
25048+ if (user_mode(regs))
25049 return;
25050
25051 if (regs->sp >= curbase + sizeof(struct thread_info) +
25052diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25053index 26d5a55..a01160a 100644
25054--- a/arch/x86/kernel/jump_label.c
25055+++ b/arch/x86/kernel/jump_label.c
25056@@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25057 * Jump label is enabled for the first time.
25058 * So we expect a default_nop...
25059 */
25060- if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25061+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25062 != 0))
25063 bug_at((void *)entry->code, __LINE__);
25064 } else {
25065@@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25066 * ...otherwise expect an ideal_nop. Otherwise
25067 * something went horribly wrong.
25068 */
25069- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25070+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25071 != 0))
25072 bug_at((void *)entry->code, __LINE__);
25073 }
25074@@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25075 * are converting the default nop to the ideal nop.
25076 */
25077 if (init) {
25078- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25079+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25080 bug_at((void *)entry->code, __LINE__);
25081 } else {
25082 code.jump = 0xe9;
25083 code.offset = entry->target -
25084 (entry->code + JUMP_LABEL_NOP_SIZE);
25085- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25086+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25087 bug_at((void *)entry->code, __LINE__);
25088 }
25089 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25090diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25091index 836f832..a8bda67 100644
25092--- a/arch/x86/kernel/kgdb.c
25093+++ b/arch/x86/kernel/kgdb.c
25094@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25095 #ifdef CONFIG_X86_32
25096 switch (regno) {
25097 case GDB_SS:
25098- if (!user_mode_vm(regs))
25099+ if (!user_mode(regs))
25100 *(unsigned long *)mem = __KERNEL_DS;
25101 break;
25102 case GDB_SP:
25103- if (!user_mode_vm(regs))
25104+ if (!user_mode(regs))
25105 *(unsigned long *)mem = kernel_stack_pointer(regs);
25106 break;
25107 case GDB_GS:
25108@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
25109 bp->attr.bp_addr = breakinfo[breakno].addr;
25110 bp->attr.bp_len = breakinfo[breakno].len;
25111 bp->attr.bp_type = breakinfo[breakno].type;
25112- info->address = breakinfo[breakno].addr;
25113+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25114+ info->address = ktla_ktva(breakinfo[breakno].addr);
25115+ else
25116+ info->address = breakinfo[breakno].addr;
25117 info->len = breakinfo[breakno].len;
25118 info->type = breakinfo[breakno].type;
25119 val = arch_install_hw_breakpoint(bp);
25120@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25121 case 'k':
25122 /* clear the trace bit */
25123 linux_regs->flags &= ~X86_EFLAGS_TF;
25124- atomic_set(&kgdb_cpu_doing_single_step, -1);
25125+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25126
25127 /* set the trace bit if we're stepping */
25128 if (remcomInBuffer[0] == 's') {
25129 linux_regs->flags |= X86_EFLAGS_TF;
25130- atomic_set(&kgdb_cpu_doing_single_step,
25131+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25132 raw_smp_processor_id());
25133 }
25134
25135@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25136
25137 switch (cmd) {
25138 case DIE_DEBUG:
25139- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25140+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25141 if (user_mode(regs))
25142 return single_step_cont(regs, args);
25143 break;
25144@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25145 #endif /* CONFIG_DEBUG_RODATA */
25146
25147 bpt->type = BP_BREAKPOINT;
25148- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25149+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25150 BREAK_INSTR_SIZE);
25151 if (err)
25152 return err;
25153- err = probe_kernel_write((char *)bpt->bpt_addr,
25154+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25155 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25156 #ifdef CONFIG_DEBUG_RODATA
25157 if (!err)
25158@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25159 return -EBUSY;
25160 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25161 BREAK_INSTR_SIZE);
25162- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25163+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25164 if (err)
25165 return err;
25166 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25167@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25168 if (mutex_is_locked(&text_mutex))
25169 goto knl_write;
25170 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25171- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25172+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25173 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25174 goto knl_write;
25175 return err;
25176 knl_write:
25177 #endif /* CONFIG_DEBUG_RODATA */
25178- return probe_kernel_write((char *)bpt->bpt_addr,
25179+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25180 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25181 }
25182
25183diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25184index 79a3f96..6ba030a 100644
25185--- a/arch/x86/kernel/kprobes/core.c
25186+++ b/arch/x86/kernel/kprobes/core.c
25187@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
25188 s32 raddr;
25189 } __packed *insn;
25190
25191- insn = (struct __arch_relative_insn *)from;
25192+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
25193+
25194+ pax_open_kernel();
25195 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25196 insn->op = op;
25197+ pax_close_kernel();
25198 }
25199
25200 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25201@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
25202 kprobe_opcode_t opcode;
25203 kprobe_opcode_t *orig_opcodes = opcodes;
25204
25205- if (search_exception_tables((unsigned long)opcodes))
25206+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25207 return 0; /* Page fault may occur on this address. */
25208
25209 retry:
25210@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25211 * for the first byte, we can recover the original instruction
25212 * from it and kp->opcode.
25213 */
25214- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25215+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25216 buf[0] = kp->opcode;
25217- return (unsigned long)buf;
25218+ return ktva_ktla((unsigned long)buf);
25219 }
25220
25221 /*
25222@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25223 /* Another subsystem puts a breakpoint, failed to recover */
25224 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25225 return 0;
25226+ pax_open_kernel();
25227 memcpy(dest, insn.kaddr, insn.length);
25228+ pax_close_kernel();
25229
25230 #ifdef CONFIG_X86_64
25231 if (insn_rip_relative(&insn)) {
25232@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25233 return 0;
25234 }
25235 disp = (u8 *) dest + insn_offset_displacement(&insn);
25236+ pax_open_kernel();
25237 *(s32 *) disp = (s32) newdisp;
25238+ pax_close_kernel();
25239 }
25240 #endif
25241 return insn.length;
25242@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25243 * nor set current_kprobe, because it doesn't use single
25244 * stepping.
25245 */
25246- regs->ip = (unsigned long)p->ainsn.insn;
25247+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25248 preempt_enable_no_resched();
25249 return;
25250 }
25251@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25252 regs->flags &= ~X86_EFLAGS_IF;
25253 /* single step inline if the instruction is an int3 */
25254 if (p->opcode == BREAKPOINT_INSTRUCTION)
25255- regs->ip = (unsigned long)p->addr;
25256+ regs->ip = ktla_ktva((unsigned long)p->addr);
25257 else
25258- regs->ip = (unsigned long)p->ainsn.insn;
25259+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25260 }
25261
25262 /*
25263@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
25264 setup_singlestep(p, regs, kcb, 0);
25265 return 1;
25266 }
25267- } else if (*addr != BREAKPOINT_INSTRUCTION) {
25268+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25269 /*
25270 * The breakpoint instruction was removed right
25271 * after we hit it. Another cpu has removed
25272@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
25273 " movq %rax, 152(%rsp)\n"
25274 RESTORE_REGS_STRING
25275 " popfq\n"
25276+#ifdef KERNEXEC_PLUGIN
25277+ " btsq $63,(%rsp)\n"
25278+#endif
25279 #else
25280 " pushf\n"
25281 SAVE_REGS_STRING
25282@@ -779,7 +789,7 @@ static void __kprobes
25283 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
25284 {
25285 unsigned long *tos = stack_addr(regs);
25286- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25287+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25288 unsigned long orig_ip = (unsigned long)p->addr;
25289 kprobe_opcode_t *insn = p->ainsn.insn;
25290
25291@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
25292 struct die_args *args = data;
25293 int ret = NOTIFY_DONE;
25294
25295- if (args->regs && user_mode_vm(args->regs))
25296+ if (args->regs && user_mode(args->regs))
25297 return ret;
25298
25299 switch (val) {
25300diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25301index 898160b..758cde8 100644
25302--- a/arch/x86/kernel/kprobes/opt.c
25303+++ b/arch/x86/kernel/kprobes/opt.c
25304@@ -79,6 +79,7 @@ found:
25305 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25306 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25307 {
25308+ pax_open_kernel();
25309 #ifdef CONFIG_X86_64
25310 *addr++ = 0x48;
25311 *addr++ = 0xbf;
25312@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
25313 *addr++ = 0xb8;
25314 #endif
25315 *(unsigned long *)addr = val;
25316+ pax_close_kernel();
25317 }
25318
25319 asm (
25320@@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25321 * Verify if the address gap is in 2GB range, because this uses
25322 * a relative jump.
25323 */
25324- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25325+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25326 if (abs(rel) > 0x7fffffff)
25327 return -ERANGE;
25328
25329@@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25330 op->optinsn.size = ret;
25331
25332 /* Copy arch-dep-instance from template */
25333- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25334+ pax_open_kernel();
25335+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25336+ pax_close_kernel();
25337
25338 /* Set probe information */
25339 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25340
25341 /* Set probe function call */
25342- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25343+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25344
25345 /* Set returning jmp instruction at the tail of out-of-line buffer */
25346- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25347+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25348 (u8 *)op->kp.addr + op->optinsn.size);
25349
25350 flush_icache_range((unsigned long) buf,
25351@@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
25352 WARN_ON(kprobe_disabled(&op->kp));
25353
25354 /* Backup instructions which will be replaced by jump address */
25355- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25356+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25357 RELATIVE_ADDR_SIZE);
25358
25359 insn_buf[0] = RELATIVEJUMP_OPCODE;
25360@@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25361 /* This kprobe is really able to run optimized path. */
25362 op = container_of(p, struct optimized_kprobe, kp);
25363 /* Detour through copied instructions */
25364- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25365+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25366 if (!reenter)
25367 reset_current_kprobe();
25368 preempt_enable_no_resched();
25369diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25370index ebc9873..1b9724b 100644
25371--- a/arch/x86/kernel/ldt.c
25372+++ b/arch/x86/kernel/ldt.c
25373@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25374 if (reload) {
25375 #ifdef CONFIG_SMP
25376 preempt_disable();
25377- load_LDT(pc);
25378+ load_LDT_nolock(pc);
25379 if (!cpumask_equal(mm_cpumask(current->mm),
25380 cpumask_of(smp_processor_id())))
25381 smp_call_function(flush_ldt, current->mm, 1);
25382 preempt_enable();
25383 #else
25384- load_LDT(pc);
25385+ load_LDT_nolock(pc);
25386 #endif
25387 }
25388 if (oldsize) {
25389@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25390 return err;
25391
25392 for (i = 0; i < old->size; i++)
25393- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25394+ write_ldt_entry(new->ldt, i, old->ldt + i);
25395 return 0;
25396 }
25397
25398@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25399 retval = copy_ldt(&mm->context, &old_mm->context);
25400 mutex_unlock(&old_mm->context.lock);
25401 }
25402+
25403+ if (tsk == current) {
25404+ mm->context.vdso = 0;
25405+
25406+#ifdef CONFIG_X86_32
25407+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25408+ mm->context.user_cs_base = 0UL;
25409+ mm->context.user_cs_limit = ~0UL;
25410+
25411+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25412+ cpus_clear(mm->context.cpu_user_cs_mask);
25413+#endif
25414+
25415+#endif
25416+#endif
25417+
25418+ }
25419+
25420 return retval;
25421 }
25422
25423@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25424 }
25425 }
25426
25427+#ifdef CONFIG_PAX_SEGMEXEC
25428+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25429+ error = -EINVAL;
25430+ goto out_unlock;
25431+ }
25432+#endif
25433+
25434 fill_ldt(&ldt, &ldt_info);
25435 if (oldmode)
25436 ldt.avl = 0;
25437diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25438index 5b19e4d..6476a76 100644
25439--- a/arch/x86/kernel/machine_kexec_32.c
25440+++ b/arch/x86/kernel/machine_kexec_32.c
25441@@ -26,7 +26,7 @@
25442 #include <asm/cacheflush.h>
25443 #include <asm/debugreg.h>
25444
25445-static void set_idt(void *newidt, __u16 limit)
25446+static void set_idt(struct desc_struct *newidt, __u16 limit)
25447 {
25448 struct desc_ptr curidt;
25449
25450@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
25451 }
25452
25453
25454-static void set_gdt(void *newgdt, __u16 limit)
25455+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25456 {
25457 struct desc_ptr curgdt;
25458
25459@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
25460 }
25461
25462 control_page = page_address(image->control_code_page);
25463- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25464+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25465
25466 relocate_kernel_ptr = control_page;
25467 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25468diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
25469index 15c9876..0a43909 100644
25470--- a/arch/x86/kernel/microcode_core.c
25471+++ b/arch/x86/kernel/microcode_core.c
25472@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
25473 return NOTIFY_OK;
25474 }
25475
25476-static struct notifier_block __refdata mc_cpu_notifier = {
25477+static struct notifier_block mc_cpu_notifier = {
25478 .notifier_call = mc_cpu_callback,
25479 };
25480
25481diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
25482index 5fb2ceb..3ae90bb 100644
25483--- a/arch/x86/kernel/microcode_intel.c
25484+++ b/arch/x86/kernel/microcode_intel.c
25485@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
25486
25487 static int get_ucode_user(void *to, const void *from, size_t n)
25488 {
25489- return copy_from_user(to, from, n);
25490+ return copy_from_user(to, (const void __force_user *)from, n);
25491 }
25492
25493 static enum ucode_state
25494 request_microcode_user(int cpu, const void __user *buf, size_t size)
25495 {
25496- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
25497+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
25498 }
25499
25500 static void microcode_fini_cpu(int cpu)
25501diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25502index 18be189..4a9fe40 100644
25503--- a/arch/x86/kernel/module.c
25504+++ b/arch/x86/kernel/module.c
25505@@ -43,15 +43,60 @@ do { \
25506 } while (0)
25507 #endif
25508
25509-void *module_alloc(unsigned long size)
25510+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25511 {
25512- if (PAGE_ALIGN(size) > MODULES_LEN)
25513+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25514 return NULL;
25515 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
25516- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
25517+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
25518 NUMA_NO_NODE, __builtin_return_address(0));
25519 }
25520
25521+void *module_alloc(unsigned long size)
25522+{
25523+
25524+#ifdef CONFIG_PAX_KERNEXEC
25525+ return __module_alloc(size, PAGE_KERNEL);
25526+#else
25527+ return __module_alloc(size, PAGE_KERNEL_EXEC);
25528+#endif
25529+
25530+}
25531+
25532+#ifdef CONFIG_PAX_KERNEXEC
25533+#ifdef CONFIG_X86_32
25534+void *module_alloc_exec(unsigned long size)
25535+{
25536+ struct vm_struct *area;
25537+
25538+ if (size == 0)
25539+ return NULL;
25540+
25541+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25542+ return area ? area->addr : NULL;
25543+}
25544+EXPORT_SYMBOL(module_alloc_exec);
25545+
25546+void module_free_exec(struct module *mod, void *module_region)
25547+{
25548+ vunmap(module_region);
25549+}
25550+EXPORT_SYMBOL(module_free_exec);
25551+#else
25552+void module_free_exec(struct module *mod, void *module_region)
25553+{
25554+ module_free(mod, module_region);
25555+}
25556+EXPORT_SYMBOL(module_free_exec);
25557+
25558+void *module_alloc_exec(unsigned long size)
25559+{
25560+ return __module_alloc(size, PAGE_KERNEL_RX);
25561+}
25562+EXPORT_SYMBOL(module_alloc_exec);
25563+#endif
25564+#endif
25565+
25566 #ifdef CONFIG_X86_32
25567 int apply_relocate(Elf32_Shdr *sechdrs,
25568 const char *strtab,
25569@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25570 unsigned int i;
25571 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25572 Elf32_Sym *sym;
25573- uint32_t *location;
25574+ uint32_t *plocation, location;
25575
25576 DEBUGP("Applying relocate section %u to %u\n",
25577 relsec, sechdrs[relsec].sh_info);
25578 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25579 /* This is where to make the change */
25580- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25581- + rel[i].r_offset;
25582+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25583+ location = (uint32_t)plocation;
25584+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25585+ plocation = ktla_ktva((void *)plocation);
25586 /* This is the symbol it is referring to. Note that all
25587 undefined symbols have been resolved. */
25588 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
25589@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25590 switch (ELF32_R_TYPE(rel[i].r_info)) {
25591 case R_386_32:
25592 /* We add the value into the location given */
25593- *location += sym->st_value;
25594+ pax_open_kernel();
25595+ *plocation += sym->st_value;
25596+ pax_close_kernel();
25597 break;
25598 case R_386_PC32:
25599 /* Add the value, subtract its position */
25600- *location += sym->st_value - (uint32_t)location;
25601+ pax_open_kernel();
25602+ *plocation += sym->st_value - location;
25603+ pax_close_kernel();
25604 break;
25605 default:
25606 pr_err("%s: Unknown relocation: %u\n",
25607@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
25608 case R_X86_64_NONE:
25609 break;
25610 case R_X86_64_64:
25611+ pax_open_kernel();
25612 *(u64 *)loc = val;
25613+ pax_close_kernel();
25614 break;
25615 case R_X86_64_32:
25616+ pax_open_kernel();
25617 *(u32 *)loc = val;
25618+ pax_close_kernel();
25619 if (val != *(u32 *)loc)
25620 goto overflow;
25621 break;
25622 case R_X86_64_32S:
25623+ pax_open_kernel();
25624 *(s32 *)loc = val;
25625+ pax_close_kernel();
25626 if ((s64)val != *(s32 *)loc)
25627 goto overflow;
25628 break;
25629 case R_X86_64_PC32:
25630 val -= (u64)loc;
25631+ pax_open_kernel();
25632 *(u32 *)loc = val;
25633+ pax_close_kernel();
25634+
25635 #if 0
25636 if ((s64)val != *(s32 *)loc)
25637 goto overflow;
25638diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
25639index 05266b5..3432443 100644
25640--- a/arch/x86/kernel/msr.c
25641+++ b/arch/x86/kernel/msr.c
25642@@ -37,6 +37,7 @@
25643 #include <linux/notifier.h>
25644 #include <linux/uaccess.h>
25645 #include <linux/gfp.h>
25646+#include <linux/grsecurity.h>
25647
25648 #include <asm/processor.h>
25649 #include <asm/msr.h>
25650@@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
25651 int err = 0;
25652 ssize_t bytes = 0;
25653
25654+#ifdef CONFIG_GRKERNSEC_KMEM
25655+ gr_handle_msr_write();
25656+ return -EPERM;
25657+#endif
25658+
25659 if (count % 8)
25660 return -EINVAL; /* Invalid chunk size */
25661
25662@@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
25663 err = -EBADF;
25664 break;
25665 }
25666+#ifdef CONFIG_GRKERNSEC_KMEM
25667+ gr_handle_msr_write();
25668+ return -EPERM;
25669+#endif
25670 if (copy_from_user(&regs, uregs, sizeof regs)) {
25671 err = -EFAULT;
25672 break;
25673@@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
25674 return notifier_from_errno(err);
25675 }
25676
25677-static struct notifier_block __refdata msr_class_cpu_notifier = {
25678+static struct notifier_block msr_class_cpu_notifier = {
25679 .notifier_call = msr_class_cpu_callback,
25680 };
25681
25682diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
25683index 6fcb49c..5b3f4ff 100644
25684--- a/arch/x86/kernel/nmi.c
25685+++ b/arch/x86/kernel/nmi.c
25686@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25687 return handled;
25688 }
25689
25690-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25691+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
25692 {
25693 struct nmi_desc *desc = nmi_to_desc(type);
25694 unsigned long flags;
25695@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25696 * event confuses some handlers (kdump uses this flag)
25697 */
25698 if (action->flags & NMI_FLAG_FIRST)
25699- list_add_rcu(&action->list, &desc->head);
25700+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25701 else
25702- list_add_tail_rcu(&action->list, &desc->head);
25703+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25704
25705 spin_unlock_irqrestore(&desc->lock, flags);
25706 return 0;
25707@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25708 if (!strcmp(n->name, name)) {
25709 WARN(in_nmi(),
25710 "Trying to free NMI (%s) from NMI context!\n", n->name);
25711- list_del_rcu(&n->list);
25712+ pax_list_del_rcu((struct list_head *)&n->list);
25713 break;
25714 }
25715 }
25716@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
25717 dotraplinkage notrace __kprobes void
25718 do_nmi(struct pt_regs *regs, long error_code)
25719 {
25720+
25721+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25722+ if (!user_mode(regs)) {
25723+ unsigned long cs = regs->cs & 0xFFFF;
25724+ unsigned long ip = ktva_ktla(regs->ip);
25725+
25726+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25727+ regs->ip = ip;
25728+ }
25729+#endif
25730+
25731 nmi_nesting_preprocess(regs);
25732
25733 nmi_enter();
25734diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25735index 6d9582e..f746287 100644
25736--- a/arch/x86/kernel/nmi_selftest.c
25737+++ b/arch/x86/kernel/nmi_selftest.c
25738@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25739 {
25740 /* trap all the unknown NMIs we may generate */
25741 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25742- __initdata);
25743+ __initconst);
25744 }
25745
25746 static void __init cleanup_nmi_testsuite(void)
25747@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25748 unsigned long timeout;
25749
25750 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25751- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25752+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25753 nmi_fail = FAILURE;
25754 return;
25755 }
25756diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25757index bbb6c73..24a58ef 100644
25758--- a/arch/x86/kernel/paravirt-spinlocks.c
25759+++ b/arch/x86/kernel/paravirt-spinlocks.c
25760@@ -8,7 +8,7 @@
25761
25762 #include <asm/paravirt.h>
25763
25764-struct pv_lock_ops pv_lock_ops = {
25765+struct pv_lock_ops pv_lock_ops __read_only = {
25766 #ifdef CONFIG_SMP
25767 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25768 .unlock_kick = paravirt_nop,
25769diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25770index 1b10af8..0b58cbc 100644
25771--- a/arch/x86/kernel/paravirt.c
25772+++ b/arch/x86/kernel/paravirt.c
25773@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25774 {
25775 return x;
25776 }
25777+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25778+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25779+#endif
25780
25781 void __init default_banner(void)
25782 {
25783@@ -142,15 +145,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25784 if (opfunc == NULL)
25785 /* If there's no function, patch it with a ud2a (BUG) */
25786 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25787- else if (opfunc == _paravirt_nop)
25788+ else if (opfunc == (void *)_paravirt_nop)
25789 /* If the operation is a nop, then nop the callsite */
25790 ret = paravirt_patch_nop();
25791
25792 /* identity functions just return their single argument */
25793- else if (opfunc == _paravirt_ident_32)
25794+ else if (opfunc == (void *)_paravirt_ident_32)
25795 ret = paravirt_patch_ident_32(insnbuf, len);
25796- else if (opfunc == _paravirt_ident_64)
25797+ else if (opfunc == (void *)_paravirt_ident_64)
25798 ret = paravirt_patch_ident_64(insnbuf, len);
25799+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25800+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
25801+ ret = paravirt_patch_ident_64(insnbuf, len);
25802+#endif
25803
25804 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
25805 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
25806@@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
25807 if (insn_len > len || start == NULL)
25808 insn_len = len;
25809 else
25810- memcpy(insnbuf, start, insn_len);
25811+ memcpy(insnbuf, ktla_ktva(start), insn_len);
25812
25813 return insn_len;
25814 }
25815@@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
25816 return this_cpu_read(paravirt_lazy_mode);
25817 }
25818
25819-struct pv_info pv_info = {
25820+struct pv_info pv_info __read_only = {
25821 .name = "bare hardware",
25822 .paravirt_enabled = 0,
25823 .kernel_rpl = 0,
25824@@ -310,16 +317,16 @@ struct pv_info pv_info = {
25825 #endif
25826 };
25827
25828-struct pv_init_ops pv_init_ops = {
25829+struct pv_init_ops pv_init_ops __read_only = {
25830 .patch = native_patch,
25831 };
25832
25833-struct pv_time_ops pv_time_ops = {
25834+struct pv_time_ops pv_time_ops __read_only = {
25835 .sched_clock = native_sched_clock,
25836 .steal_clock = native_steal_clock,
25837 };
25838
25839-__visible struct pv_irq_ops pv_irq_ops = {
25840+__visible struct pv_irq_ops pv_irq_ops __read_only = {
25841 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
25842 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
25843 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
25844@@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
25845 #endif
25846 };
25847
25848-__visible struct pv_cpu_ops pv_cpu_ops = {
25849+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
25850 .cpuid = native_cpuid,
25851 .get_debugreg = native_get_debugreg,
25852 .set_debugreg = native_set_debugreg,
25853@@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
25854 .end_context_switch = paravirt_nop,
25855 };
25856
25857-struct pv_apic_ops pv_apic_ops = {
25858+struct pv_apic_ops pv_apic_ops __read_only= {
25859 #ifdef CONFIG_X86_LOCAL_APIC
25860 .startup_ipi_hook = paravirt_nop,
25861 #endif
25862 };
25863
25864-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
25865+#ifdef CONFIG_X86_32
25866+#ifdef CONFIG_X86_PAE
25867+/* 64-bit pagetable entries */
25868+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
25869+#else
25870 /* 32-bit pagetable entries */
25871 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
25872+#endif
25873 #else
25874 /* 64-bit pagetable entries */
25875 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
25876 #endif
25877
25878-struct pv_mmu_ops pv_mmu_ops = {
25879+struct pv_mmu_ops pv_mmu_ops __read_only = {
25880
25881 .read_cr2 = native_read_cr2,
25882 .write_cr2 = native_write_cr2,
25883@@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
25884 .make_pud = PTE_IDENT,
25885
25886 .set_pgd = native_set_pgd,
25887+ .set_pgd_batched = native_set_pgd_batched,
25888 #endif
25889 #endif /* PAGETABLE_LEVELS >= 3 */
25890
25891@@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
25892 },
25893
25894 .set_fixmap = native_set_fixmap,
25895+
25896+#ifdef CONFIG_PAX_KERNEXEC
25897+ .pax_open_kernel = native_pax_open_kernel,
25898+ .pax_close_kernel = native_pax_close_kernel,
25899+#endif
25900+
25901 };
25902
25903 EXPORT_SYMBOL_GPL(pv_time_ops);
25904diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
25905index 299d493..2ccb0ee 100644
25906--- a/arch/x86/kernel/pci-calgary_64.c
25907+++ b/arch/x86/kernel/pci-calgary_64.c
25908@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
25909 tce_space = be64_to_cpu(readq(target));
25910 tce_space = tce_space & TAR_SW_BITS;
25911
25912- tce_space = tce_space & (~specified_table_size);
25913+ tce_space = tce_space & (~(unsigned long)specified_table_size);
25914 info->tce_space = (u64 *)__va(tce_space);
25915 }
25916 }
25917diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
25918index 35ccf75..7a15747 100644
25919--- a/arch/x86/kernel/pci-iommu_table.c
25920+++ b/arch/x86/kernel/pci-iommu_table.c
25921@@ -2,7 +2,7 @@
25922 #include <asm/iommu_table.h>
25923 #include <linux/string.h>
25924 #include <linux/kallsyms.h>
25925-
25926+#include <linux/sched.h>
25927
25928 #define DEBUG 1
25929
25930diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
25931index 6c483ba..d10ce2f 100644
25932--- a/arch/x86/kernel/pci-swiotlb.c
25933+++ b/arch/x86/kernel/pci-swiotlb.c
25934@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
25935 void *vaddr, dma_addr_t dma_addr,
25936 struct dma_attrs *attrs)
25937 {
25938- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
25939+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
25940 }
25941
25942 static struct dma_map_ops swiotlb_dma_ops = {
25943diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
25944index ca7f0d5..8996469 100644
25945--- a/arch/x86/kernel/preempt.S
25946+++ b/arch/x86/kernel/preempt.S
25947@@ -3,12 +3,14 @@
25948 #include <asm/dwarf2.h>
25949 #include <asm/asm.h>
25950 #include <asm/calling.h>
25951+#include <asm/alternative-asm.h>
25952
25953 ENTRY(___preempt_schedule)
25954 CFI_STARTPROC
25955 SAVE_ALL
25956 call preempt_schedule
25957 RESTORE_ALL
25958+ pax_force_retaddr
25959 ret
25960 CFI_ENDPROC
25961
25962@@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
25963 SAVE_ALL
25964 call preempt_schedule_context
25965 RESTORE_ALL
25966+ pax_force_retaddr
25967 ret
25968 CFI_ENDPROC
25969
25970diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
25971index 3fb8d95..254dc51 100644
25972--- a/arch/x86/kernel/process.c
25973+++ b/arch/x86/kernel/process.c
25974@@ -36,7 +36,8 @@
25975 * section. Since TSS's are completely CPU-local, we want them
25976 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
25977 */
25978-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
25979+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
25980+EXPORT_SYMBOL(init_tss);
25981
25982 #ifdef CONFIG_X86_64
25983 static DEFINE_PER_CPU(unsigned char, is_idle);
25984@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
25985 task_xstate_cachep =
25986 kmem_cache_create("task_xstate", xstate_size,
25987 __alignof__(union thread_xstate),
25988- SLAB_PANIC | SLAB_NOTRACK, NULL);
25989+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
25990 }
25991
25992 /*
25993@@ -105,7 +106,7 @@ void exit_thread(void)
25994 unsigned long *bp = t->io_bitmap_ptr;
25995
25996 if (bp) {
25997- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
25998+ struct tss_struct *tss = init_tss + get_cpu();
25999
26000 t->io_bitmap_ptr = NULL;
26001 clear_thread_flag(TIF_IO_BITMAP);
26002@@ -125,6 +126,9 @@ void flush_thread(void)
26003 {
26004 struct task_struct *tsk = current;
26005
26006+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26007+ loadsegment(gs, 0);
26008+#endif
26009 flush_ptrace_hw_breakpoint(tsk);
26010 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26011 drop_init_fpu(tsk);
26012@@ -271,7 +275,7 @@ static void __exit_idle(void)
26013 void exit_idle(void)
26014 {
26015 /* idle loop has pid 0 */
26016- if (current->pid)
26017+ if (task_pid_nr(current))
26018 return;
26019 __exit_idle();
26020 }
26021@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
26022 return ret;
26023 }
26024 #endif
26025-void stop_this_cpu(void *dummy)
26026+__noreturn void stop_this_cpu(void *dummy)
26027 {
26028 local_irq_disable();
26029 /*
26030@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
26031 }
26032 early_param("idle", idle_setup);
26033
26034-unsigned long arch_align_stack(unsigned long sp)
26035+#ifdef CONFIG_PAX_RANDKSTACK
26036+void pax_randomize_kstack(struct pt_regs *regs)
26037 {
26038- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26039- sp -= get_random_int() % 8192;
26040- return sp & ~0xf;
26041-}
26042+ struct thread_struct *thread = &current->thread;
26043+ unsigned long time;
26044
26045-unsigned long arch_randomize_brk(struct mm_struct *mm)
26046-{
26047- unsigned long range_end = mm->brk + 0x02000000;
26048- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26049-}
26050+ if (!randomize_va_space)
26051+ return;
26052+
26053+ if (v8086_mode(regs))
26054+ return;
26055
26056+ rdtscl(time);
26057+
26058+ /* P4 seems to return a 0 LSB, ignore it */
26059+#ifdef CONFIG_MPENTIUM4
26060+ time &= 0x3EUL;
26061+ time <<= 2;
26062+#elif defined(CONFIG_X86_64)
26063+ time &= 0xFUL;
26064+ time <<= 4;
26065+#else
26066+ time &= 0x1FUL;
26067+ time <<= 3;
26068+#endif
26069+
26070+ thread->sp0 ^= time;
26071+ load_sp0(init_tss + smp_processor_id(), thread);
26072+
26073+#ifdef CONFIG_X86_64
26074+ this_cpu_write(kernel_stack, thread->sp0);
26075+#endif
26076+}
26077+#endif
26078diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26079index 6f1236c..fd448d4 100644
26080--- a/arch/x86/kernel/process_32.c
26081+++ b/arch/x86/kernel/process_32.c
26082@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26083 unsigned long thread_saved_pc(struct task_struct *tsk)
26084 {
26085 return ((unsigned long *)tsk->thread.sp)[3];
26086+//XXX return tsk->thread.eip;
26087 }
26088
26089 void __show_regs(struct pt_regs *regs, int all)
26090@@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
26091 unsigned long sp;
26092 unsigned short ss, gs;
26093
26094- if (user_mode_vm(regs)) {
26095+ if (user_mode(regs)) {
26096 sp = regs->sp;
26097 ss = regs->ss & 0xffff;
26098- gs = get_user_gs(regs);
26099 } else {
26100 sp = kernel_stack_pointer(regs);
26101 savesegment(ss, ss);
26102- savesegment(gs, gs);
26103 }
26104+ gs = get_user_gs(regs);
26105
26106 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26107 (u16)regs->cs, regs->ip, regs->flags,
26108- smp_processor_id());
26109+ raw_smp_processor_id());
26110 print_symbol("EIP is at %s\n", regs->ip);
26111
26112 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26113@@ -133,20 +133,21 @@ void release_thread(struct task_struct *dead_task)
26114 int copy_thread(unsigned long clone_flags, unsigned long sp,
26115 unsigned long arg, struct task_struct *p)
26116 {
26117- struct pt_regs *childregs = task_pt_regs(p);
26118+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26119 struct task_struct *tsk;
26120 int err;
26121
26122 p->thread.sp = (unsigned long) childregs;
26123 p->thread.sp0 = (unsigned long) (childregs+1);
26124+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26125
26126 if (unlikely(p->flags & PF_KTHREAD)) {
26127 /* kernel thread */
26128 memset(childregs, 0, sizeof(struct pt_regs));
26129 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26130- task_user_gs(p) = __KERNEL_STACK_CANARY;
26131- childregs->ds = __USER_DS;
26132- childregs->es = __USER_DS;
26133+ savesegment(gs, childregs->gs);
26134+ childregs->ds = __KERNEL_DS;
26135+ childregs->es = __KERNEL_DS;
26136 childregs->fs = __KERNEL_PERCPU;
26137 childregs->bx = sp; /* function */
26138 childregs->bp = arg;
26139@@ -253,7 +254,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26140 struct thread_struct *prev = &prev_p->thread,
26141 *next = &next_p->thread;
26142 int cpu = smp_processor_id();
26143- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26144+ struct tss_struct *tss = init_tss + cpu;
26145 fpu_switch_t fpu;
26146
26147 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26148@@ -277,6 +278,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26149 */
26150 lazy_save_gs(prev->gs);
26151
26152+#ifdef CONFIG_PAX_MEMORY_UDEREF
26153+ __set_fs(task_thread_info(next_p)->addr_limit);
26154+#endif
26155+
26156 /*
26157 * Load the per-thread Thread-Local Storage descriptor.
26158 */
26159@@ -315,6 +320,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26160 */
26161 arch_end_context_switch(next_p);
26162
26163+ this_cpu_write(current_task, next_p);
26164+ this_cpu_write(current_tinfo, &next_p->tinfo);
26165+
26166 /*
26167 * Restore %gs if needed (which is common)
26168 */
26169@@ -323,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26170
26171 switch_fpu_finish(next_p, fpu);
26172
26173- this_cpu_write(current_task, next_p);
26174-
26175 return prev_p;
26176 }
26177
26178@@ -354,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
26179 } while (count++ < 16);
26180 return 0;
26181 }
26182-
26183diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26184index 9c0280f..5bbb1c0 100644
26185--- a/arch/x86/kernel/process_64.c
26186+++ b/arch/x86/kernel/process_64.c
26187@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26188 struct pt_regs *childregs;
26189 struct task_struct *me = current;
26190
26191- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26192+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26193 childregs = task_pt_regs(p);
26194 p->thread.sp = (unsigned long) childregs;
26195 p->thread.usersp = me->thread.usersp;
26196+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26197 set_tsk_thread_flag(p, TIF_FORK);
26198 p->thread.fpu_counter = 0;
26199 p->thread.io_bitmap_ptr = NULL;
26200@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26201 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26202 savesegment(es, p->thread.es);
26203 savesegment(ds, p->thread.ds);
26204+ savesegment(ss, p->thread.ss);
26205+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26206 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26207
26208 if (unlikely(p->flags & PF_KTHREAD)) {
26209@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26210 struct thread_struct *prev = &prev_p->thread;
26211 struct thread_struct *next = &next_p->thread;
26212 int cpu = smp_processor_id();
26213- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26214+ struct tss_struct *tss = init_tss + cpu;
26215 unsigned fsindex, gsindex;
26216 fpu_switch_t fpu;
26217
26218@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26219 if (unlikely(next->ds | prev->ds))
26220 loadsegment(ds, next->ds);
26221
26222+ savesegment(ss, prev->ss);
26223+ if (unlikely(next->ss != prev->ss))
26224+ loadsegment(ss, next->ss);
26225
26226 /* We must save %fs and %gs before load_TLS() because
26227 * %fs and %gs may be cleared by load_TLS().
26228@@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26229 prev->usersp = this_cpu_read(old_rsp);
26230 this_cpu_write(old_rsp, next->usersp);
26231 this_cpu_write(current_task, next_p);
26232+ this_cpu_write(current_tinfo, &next_p->tinfo);
26233
26234 /*
26235 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26236@@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26237 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26238 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26239
26240- this_cpu_write(kernel_stack,
26241- (unsigned long)task_stack_page(next_p) +
26242- THREAD_SIZE - KERNEL_STACK_OFFSET);
26243+ this_cpu_write(kernel_stack, next->sp0);
26244
26245 /*
26246 * Now maybe reload the debug registers and handle I/O bitmaps
26247@@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
26248 if (!p || p == current || p->state == TASK_RUNNING)
26249 return 0;
26250 stack = (unsigned long)task_stack_page(p);
26251- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26252+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26253 return 0;
26254 fp = *(u64 *)(p->thread.sp);
26255 do {
26256- if (fp < (unsigned long)stack ||
26257- fp >= (unsigned long)stack+THREAD_SIZE)
26258+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26259 return 0;
26260 ip = *(u64 *)(fp+8);
26261 if (!in_sched_functions(ip))
26262diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26263index 7461f50..1334029 100644
26264--- a/arch/x86/kernel/ptrace.c
26265+++ b/arch/x86/kernel/ptrace.c
26266@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26267 {
26268 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
26269 unsigned long sp = (unsigned long)&regs->sp;
26270- struct thread_info *tinfo;
26271
26272- if (context == (sp & ~(THREAD_SIZE - 1)))
26273+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26274 return sp;
26275
26276- tinfo = (struct thread_info *)context;
26277- if (tinfo->previous_esp)
26278- return tinfo->previous_esp;
26279+ sp = *(unsigned long *)context;
26280+ if (sp)
26281+ return sp;
26282
26283 return (unsigned long)regs;
26284 }
26285@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
26286 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26287 {
26288 int i;
26289- int dr7 = 0;
26290+ unsigned long dr7 = 0;
26291 struct arch_hw_breakpoint *info;
26292
26293 for (i = 0; i < HBP_NUM; i++) {
26294@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
26295 unsigned long addr, unsigned long data)
26296 {
26297 int ret;
26298- unsigned long __user *datap = (unsigned long __user *)data;
26299+ unsigned long __user *datap = (__force unsigned long __user *)data;
26300
26301 switch (request) {
26302 /* read the word at location addr in the USER area. */
26303@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
26304 if ((int) addr < 0)
26305 return -EIO;
26306 ret = do_get_thread_area(child, addr,
26307- (struct user_desc __user *)data);
26308+ (__force struct user_desc __user *) data);
26309 break;
26310
26311 case PTRACE_SET_THREAD_AREA:
26312 if ((int) addr < 0)
26313 return -EIO;
26314 ret = do_set_thread_area(child, addr,
26315- (struct user_desc __user *)data, 0);
26316+ (__force struct user_desc __user *) data, 0);
26317 break;
26318 #endif
26319
26320@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26321
26322 #ifdef CONFIG_X86_64
26323
26324-static struct user_regset x86_64_regsets[] __read_mostly = {
26325+static user_regset_no_const x86_64_regsets[] __read_only = {
26326 [REGSET_GENERAL] = {
26327 .core_note_type = NT_PRSTATUS,
26328 .n = sizeof(struct user_regs_struct) / sizeof(long),
26329@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
26330 #endif /* CONFIG_X86_64 */
26331
26332 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26333-static struct user_regset x86_32_regsets[] __read_mostly = {
26334+static user_regset_no_const x86_32_regsets[] __read_only = {
26335 [REGSET_GENERAL] = {
26336 .core_note_type = NT_PRSTATUS,
26337 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26338@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
26339 */
26340 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26341
26342-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26343+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26344 {
26345 #ifdef CONFIG_X86_64
26346 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26347@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26348 memset(info, 0, sizeof(*info));
26349 info->si_signo = SIGTRAP;
26350 info->si_code = si_code;
26351- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26352+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26353 }
26354
26355 void user_single_step_siginfo(struct task_struct *tsk,
26356@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
26357 # define IS_IA32 0
26358 #endif
26359
26360+#ifdef CONFIG_GRKERNSEC_SETXID
26361+extern void gr_delayed_cred_worker(void);
26362+#endif
26363+
26364 /*
26365 * We must return the syscall number to actually look up in the table.
26366 * This can be -1L to skip running any syscall at all.
26367@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
26368
26369 user_exit();
26370
26371+#ifdef CONFIG_GRKERNSEC_SETXID
26372+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26373+ gr_delayed_cred_worker();
26374+#endif
26375+
26376 /*
26377 * If we stepped into a sysenter/syscall insn, it trapped in
26378 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26379@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26380 */
26381 user_exit();
26382
26383+#ifdef CONFIG_GRKERNSEC_SETXID
26384+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26385+ gr_delayed_cred_worker();
26386+#endif
26387+
26388 audit_syscall_exit(regs);
26389
26390 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26391diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26392index 2f355d2..e75ed0a 100644
26393--- a/arch/x86/kernel/pvclock.c
26394+++ b/arch/x86/kernel/pvclock.c
26395@@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26396 reset_hung_task_detector();
26397 }
26398
26399-static atomic64_t last_value = ATOMIC64_INIT(0);
26400+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26401
26402 void pvclock_resume(void)
26403 {
26404- atomic64_set(&last_value, 0);
26405+ atomic64_set_unchecked(&last_value, 0);
26406 }
26407
26408 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26409@@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26410 * updating at the same time, and one of them could be slightly behind,
26411 * making the assumption that last_value always go forward fail to hold.
26412 */
26413- last = atomic64_read(&last_value);
26414+ last = atomic64_read_unchecked(&last_value);
26415 do {
26416 if (ret < last)
26417 return last;
26418- last = atomic64_cmpxchg(&last_value, last, ret);
26419+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26420 } while (unlikely(last != ret));
26421
26422 return ret;
26423diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26424index c752cb4..866c432 100644
26425--- a/arch/x86/kernel/reboot.c
26426+++ b/arch/x86/kernel/reboot.c
26427@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26428
26429 void __noreturn machine_real_restart(unsigned int type)
26430 {
26431+
26432+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26433+ struct desc_struct *gdt;
26434+#endif
26435+
26436 local_irq_disable();
26437
26438 /*
26439@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
26440
26441 /* Jump to the identity-mapped low memory code */
26442 #ifdef CONFIG_X86_32
26443- asm volatile("jmpl *%0" : :
26444+
26445+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26446+ gdt = get_cpu_gdt_table(smp_processor_id());
26447+ pax_open_kernel();
26448+#ifdef CONFIG_PAX_MEMORY_UDEREF
26449+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26450+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26451+ loadsegment(ds, __KERNEL_DS);
26452+ loadsegment(es, __KERNEL_DS);
26453+ loadsegment(ss, __KERNEL_DS);
26454+#endif
26455+#ifdef CONFIG_PAX_KERNEXEC
26456+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26457+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26458+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26459+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26460+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26461+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26462+#endif
26463+ pax_close_kernel();
26464+#endif
26465+
26466+ asm volatile("ljmpl *%0" : :
26467 "rm" (real_mode_header->machine_real_restart_asm),
26468 "a" (type));
26469 #else
26470@@ -470,7 +497,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26471 * try to force a triple fault and then cycle between hitting the keyboard
26472 * controller and doing that
26473 */
26474-static void native_machine_emergency_restart(void)
26475+static void __noreturn native_machine_emergency_restart(void)
26476 {
26477 int i;
26478 int attempt = 0;
26479@@ -593,13 +620,13 @@ void native_machine_shutdown(void)
26480 #endif
26481 }
26482
26483-static void __machine_emergency_restart(int emergency)
26484+static void __noreturn __machine_emergency_restart(int emergency)
26485 {
26486 reboot_emergency = emergency;
26487 machine_ops.emergency_restart();
26488 }
26489
26490-static void native_machine_restart(char *__unused)
26491+static void __noreturn native_machine_restart(char *__unused)
26492 {
26493 pr_notice("machine restart\n");
26494
26495@@ -608,7 +635,7 @@ static void native_machine_restart(char *__unused)
26496 __machine_emergency_restart(0);
26497 }
26498
26499-static void native_machine_halt(void)
26500+static void __noreturn native_machine_halt(void)
26501 {
26502 /* Stop other cpus and apics */
26503 machine_shutdown();
26504@@ -618,7 +645,7 @@ static void native_machine_halt(void)
26505 stop_this_cpu(NULL);
26506 }
26507
26508-static void native_machine_power_off(void)
26509+static void __noreturn native_machine_power_off(void)
26510 {
26511 if (pm_power_off) {
26512 if (!reboot_force)
26513@@ -627,9 +654,10 @@ static void native_machine_power_off(void)
26514 }
26515 /* A fallback in case there is no PM info available */
26516 tboot_shutdown(TB_SHUTDOWN_HALT);
26517+ unreachable();
26518 }
26519
26520-struct machine_ops machine_ops = {
26521+struct machine_ops machine_ops __read_only = {
26522 .power_off = native_machine_power_off,
26523 .shutdown = native_machine_shutdown,
26524 .emergency_restart = native_machine_emergency_restart,
26525diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26526index c8e41e9..64049ef 100644
26527--- a/arch/x86/kernel/reboot_fixups_32.c
26528+++ b/arch/x86/kernel/reboot_fixups_32.c
26529@@ -57,7 +57,7 @@ struct device_fixup {
26530 unsigned int vendor;
26531 unsigned int device;
26532 void (*reboot_fixup)(struct pci_dev *);
26533-};
26534+} __do_const;
26535
26536 /*
26537 * PCI ids solely used for fixups_table go here
26538diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26539index 3fd2c69..a444264 100644
26540--- a/arch/x86/kernel/relocate_kernel_64.S
26541+++ b/arch/x86/kernel/relocate_kernel_64.S
26542@@ -96,8 +96,7 @@ relocate_kernel:
26543
26544 /* jump to identity mapped page */
26545 addq $(identity_mapped - relocate_kernel), %r8
26546- pushq %r8
26547- ret
26548+ jmp *%r8
26549
26550 identity_mapped:
26551 /* set return address to 0 if not preserving context */
26552diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26553index cb233bc..23b4879 100644
26554--- a/arch/x86/kernel/setup.c
26555+++ b/arch/x86/kernel/setup.c
26556@@ -110,6 +110,7 @@
26557 #include <asm/mce.h>
26558 #include <asm/alternative.h>
26559 #include <asm/prom.h>
26560+#include <asm/boot.h>
26561
26562 /*
26563 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26564@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26565 #endif
26566
26567
26568-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26569-__visible unsigned long mmu_cr4_features;
26570+#ifdef CONFIG_X86_64
26571+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26572+#elif defined(CONFIG_X86_PAE)
26573+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26574 #else
26575-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
26576+__visible unsigned long mmu_cr4_features __read_only;
26577 #endif
26578
26579+void set_in_cr4(unsigned long mask)
26580+{
26581+ unsigned long cr4 = read_cr4();
26582+
26583+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
26584+ return;
26585+
26586+ pax_open_kernel();
26587+ mmu_cr4_features |= mask;
26588+ pax_close_kernel();
26589+
26590+ if (trampoline_cr4_features)
26591+ *trampoline_cr4_features = mmu_cr4_features;
26592+ cr4 |= mask;
26593+ write_cr4(cr4);
26594+}
26595+EXPORT_SYMBOL(set_in_cr4);
26596+
26597+void clear_in_cr4(unsigned long mask)
26598+{
26599+ unsigned long cr4 = read_cr4();
26600+
26601+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
26602+ return;
26603+
26604+ pax_open_kernel();
26605+ mmu_cr4_features &= ~mask;
26606+ pax_close_kernel();
26607+
26608+ if (trampoline_cr4_features)
26609+ *trampoline_cr4_features = mmu_cr4_features;
26610+ cr4 &= ~mask;
26611+ write_cr4(cr4);
26612+}
26613+EXPORT_SYMBOL(clear_in_cr4);
26614+
26615 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
26616 int bootloader_type, bootloader_version;
26617
26618@@ -768,7 +807,7 @@ static void __init trim_bios_range(void)
26619 * area (640->1Mb) as ram even though it is not.
26620 * take them out.
26621 */
26622- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
26623+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
26624
26625 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
26626 }
26627@@ -776,7 +815,7 @@ static void __init trim_bios_range(void)
26628 /* called before trim_bios_range() to spare extra sanitize */
26629 static void __init e820_add_kernel_range(void)
26630 {
26631- u64 start = __pa_symbol(_text);
26632+ u64 start = __pa_symbol(ktla_ktva(_text));
26633 u64 size = __pa_symbol(_end) - start;
26634
26635 /*
26636@@ -838,8 +877,12 @@ static void __init trim_low_memory_range(void)
26637
26638 void __init setup_arch(char **cmdline_p)
26639 {
26640+#ifdef CONFIG_X86_32
26641+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
26642+#else
26643 memblock_reserve(__pa_symbol(_text),
26644 (unsigned long)__bss_stop - (unsigned long)_text);
26645+#endif
26646
26647 early_reserve_initrd();
26648
26649@@ -931,14 +974,14 @@ void __init setup_arch(char **cmdline_p)
26650
26651 if (!boot_params.hdr.root_flags)
26652 root_mountflags &= ~MS_RDONLY;
26653- init_mm.start_code = (unsigned long) _text;
26654- init_mm.end_code = (unsigned long) _etext;
26655+ init_mm.start_code = ktla_ktva((unsigned long) _text);
26656+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
26657 init_mm.end_data = (unsigned long) _edata;
26658 init_mm.brk = _brk_end;
26659
26660- code_resource.start = __pa_symbol(_text);
26661- code_resource.end = __pa_symbol(_etext)-1;
26662- data_resource.start = __pa_symbol(_etext);
26663+ code_resource.start = __pa_symbol(ktla_ktva(_text));
26664+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
26665+ data_resource.start = __pa_symbol(_sdata);
26666 data_resource.end = __pa_symbol(_edata)-1;
26667 bss_resource.start = __pa_symbol(__bss_start);
26668 bss_resource.end = __pa_symbol(__bss_stop)-1;
26669diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
26670index 5cdff03..80fa283 100644
26671--- a/arch/x86/kernel/setup_percpu.c
26672+++ b/arch/x86/kernel/setup_percpu.c
26673@@ -21,19 +21,17 @@
26674 #include <asm/cpu.h>
26675 #include <asm/stackprotector.h>
26676
26677-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
26678+#ifdef CONFIG_SMP
26679+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
26680 EXPORT_PER_CPU_SYMBOL(cpu_number);
26681+#endif
26682
26683-#ifdef CONFIG_X86_64
26684 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
26685-#else
26686-#define BOOT_PERCPU_OFFSET 0
26687-#endif
26688
26689 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
26690 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
26691
26692-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
26693+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
26694 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
26695 };
26696 EXPORT_SYMBOL(__per_cpu_offset);
26697@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
26698 {
26699 #ifdef CONFIG_NEED_MULTIPLE_NODES
26700 pg_data_t *last = NULL;
26701- unsigned int cpu;
26702+ int cpu;
26703
26704 for_each_possible_cpu(cpu) {
26705 int node = early_cpu_to_node(cpu);
26706@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
26707 {
26708 #ifdef CONFIG_X86_32
26709 struct desc_struct gdt;
26710+ unsigned long base = per_cpu_offset(cpu);
26711
26712- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
26713- 0x2 | DESCTYPE_S, 0x8);
26714- gdt.s = 1;
26715+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26716+ 0x83 | DESCTYPE_S, 0xC);
26717 write_gdt_entry(get_cpu_gdt_table(cpu),
26718 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26719 #endif
26720@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26721 /* alrighty, percpu areas up and running */
26722 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26723 for_each_possible_cpu(cpu) {
26724+#ifdef CONFIG_CC_STACKPROTECTOR
26725+#ifdef CONFIG_X86_32
26726+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
26727+#endif
26728+#endif
26729 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26730 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26731 per_cpu(cpu_number, cpu) = cpu;
26732@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26733 */
26734 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26735 #endif
26736+#ifdef CONFIG_CC_STACKPROTECTOR
26737+#ifdef CONFIG_X86_32
26738+ if (!cpu)
26739+ per_cpu(stack_canary.canary, cpu) = canary;
26740+#endif
26741+#endif
26742 /*
26743 * Up to this point, the boot CPU has been using .init.data
26744 * area. Reload any changed state for the boot CPU.
26745diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26746index 9e5de68..16c53cb 100644
26747--- a/arch/x86/kernel/signal.c
26748+++ b/arch/x86/kernel/signal.c
26749@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26750 * Align the stack pointer according to the i386 ABI,
26751 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26752 */
26753- sp = ((sp + 4) & -16ul) - 4;
26754+ sp = ((sp - 12) & -16ul) - 4;
26755 #else /* !CONFIG_X86_32 */
26756 sp = round_down(sp, 16) - 8;
26757 #endif
26758@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26759 }
26760
26761 if (current->mm->context.vdso)
26762- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26763+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26764 else
26765- restorer = &frame->retcode;
26766+ restorer = (void __user *)&frame->retcode;
26767 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26768 restorer = ksig->ka.sa.sa_restorer;
26769
26770@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26771 * reasons and because gdb uses it as a signature to notice
26772 * signal handler stack frames.
26773 */
26774- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26775+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26776
26777 if (err)
26778 return -EFAULT;
26779@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26780 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
26781
26782 /* Set up to return from userspace. */
26783- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26784+ if (current->mm->context.vdso)
26785+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26786+ else
26787+ restorer = (void __user *)&frame->retcode;
26788 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26789 restorer = ksig->ka.sa.sa_restorer;
26790 put_user_ex(restorer, &frame->pretcode);
26791@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26792 * reasons and because gdb uses it as a signature to notice
26793 * signal handler stack frames.
26794 */
26795- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
26796+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
26797 } put_user_catch(err);
26798
26799 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
26800@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26801 {
26802 int usig = signr_convert(ksig->sig);
26803 sigset_t *set = sigmask_to_save();
26804- compat_sigset_t *cset = (compat_sigset_t *) set;
26805+ sigset_t sigcopy;
26806+ compat_sigset_t *cset;
26807+
26808+ sigcopy = *set;
26809+
26810+ cset = (compat_sigset_t *) &sigcopy;
26811
26812 /* Set up the stack frame */
26813 if (is_ia32_frame()) {
26814@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26815 } else if (is_x32_frame()) {
26816 return x32_setup_rt_frame(ksig, cset, regs);
26817 } else {
26818- return __setup_rt_frame(ksig->sig, ksig, set, regs);
26819+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
26820 }
26821 }
26822
26823diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
26824index 7c3a5a6..f0a8961 100644
26825--- a/arch/x86/kernel/smp.c
26826+++ b/arch/x86/kernel/smp.c
26827@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
26828
26829 __setup("nonmi_ipi", nonmi_ipi_setup);
26830
26831-struct smp_ops smp_ops = {
26832+struct smp_ops smp_ops __read_only = {
26833 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
26834 .smp_prepare_cpus = native_smp_prepare_cpus,
26835 .smp_cpus_done = native_smp_cpus_done,
26836diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
26837index 85dc05a..f8c96f6 100644
26838--- a/arch/x86/kernel/smpboot.c
26839+++ b/arch/x86/kernel/smpboot.c
26840@@ -229,14 +229,18 @@ static void notrace start_secondary(void *unused)
26841
26842 enable_start_cpu0 = 0;
26843
26844-#ifdef CONFIG_X86_32
26845- /* switch away from the initial page table */
26846- load_cr3(swapper_pg_dir);
26847- __flush_tlb_all();
26848-#endif
26849-
26850 /* otherwise gcc will move up smp_processor_id before the cpu_init */
26851 barrier();
26852+
26853+ /* switch away from the initial page table */
26854+#ifdef CONFIG_PAX_PER_CPU_PGD
26855+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
26856+ __flush_tlb_all();
26857+#elif defined(CONFIG_X86_32)
26858+ load_cr3(swapper_pg_dir);
26859+ __flush_tlb_all();
26860+#endif
26861+
26862 /*
26863 * Check TSC synchronization with the BP:
26864 */
26865@@ -749,8 +753,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26866 alternatives_enable_smp();
26867
26868 idle->thread.sp = (unsigned long) (((struct pt_regs *)
26869- (THREAD_SIZE + task_stack_page(idle))) - 1);
26870+ (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
26871 per_cpu(current_task, cpu) = idle;
26872+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
26873
26874 #ifdef CONFIG_X86_32
26875 /* Stack for startup_32 can be just as for start_secondary onwards */
26876@@ -758,11 +763,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26877 #else
26878 clear_tsk_thread_flag(idle, TIF_FORK);
26879 initial_gs = per_cpu_offset(cpu);
26880- per_cpu(kernel_stack, cpu) =
26881- (unsigned long)task_stack_page(idle) -
26882- KERNEL_STACK_OFFSET + THREAD_SIZE;
26883+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26884 #endif
26885+
26886+ pax_open_kernel();
26887 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
26888+ pax_close_kernel();
26889+
26890 initial_code = (unsigned long)start_secondary;
26891 stack_start = idle->thread.sp;
26892
26893@@ -911,6 +918,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
26894 /* the FPU context is blank, nobody can own it */
26895 __cpu_disable_lazy_restore(cpu);
26896
26897+#ifdef CONFIG_PAX_PER_CPU_PGD
26898+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
26899+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26900+ KERNEL_PGD_PTRS);
26901+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
26902+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26903+ KERNEL_PGD_PTRS);
26904+#endif
26905+
26906 err = do_boot_cpu(apicid, cpu, tidle);
26907 if (err) {
26908 pr_debug("do_boot_cpu failed %d\n", err);
26909diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
26910index 9b4d51d..5d28b58 100644
26911--- a/arch/x86/kernel/step.c
26912+++ b/arch/x86/kernel/step.c
26913@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26914 struct desc_struct *desc;
26915 unsigned long base;
26916
26917- seg &= ~7UL;
26918+ seg >>= 3;
26919
26920 mutex_lock(&child->mm->context.lock);
26921- if (unlikely((seg >> 3) >= child->mm->context.size))
26922+ if (unlikely(seg >= child->mm->context.size))
26923 addr = -1L; /* bogus selector, access would fault */
26924 else {
26925 desc = child->mm->context.ldt + seg;
26926@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26927 addr += base;
26928 }
26929 mutex_unlock(&child->mm->context.lock);
26930- }
26931+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
26932+ addr = ktla_ktva(addr);
26933
26934 return addr;
26935 }
26936@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
26937 unsigned char opcode[15];
26938 unsigned long addr = convert_ip_to_linear(child, regs);
26939
26940+ if (addr == -EINVAL)
26941+ return 0;
26942+
26943 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
26944 for (i = 0; i < copied; i++) {
26945 switch (opcode[i]) {
26946diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
26947new file mode 100644
26948index 0000000..5877189
26949--- /dev/null
26950+++ b/arch/x86/kernel/sys_i386_32.c
26951@@ -0,0 +1,189 @@
26952+/*
26953+ * This file contains various random system calls that
26954+ * have a non-standard calling sequence on the Linux/i386
26955+ * platform.
26956+ */
26957+
26958+#include <linux/errno.h>
26959+#include <linux/sched.h>
26960+#include <linux/mm.h>
26961+#include <linux/fs.h>
26962+#include <linux/smp.h>
26963+#include <linux/sem.h>
26964+#include <linux/msg.h>
26965+#include <linux/shm.h>
26966+#include <linux/stat.h>
26967+#include <linux/syscalls.h>
26968+#include <linux/mman.h>
26969+#include <linux/file.h>
26970+#include <linux/utsname.h>
26971+#include <linux/ipc.h>
26972+#include <linux/elf.h>
26973+
26974+#include <linux/uaccess.h>
26975+#include <linux/unistd.h>
26976+
26977+#include <asm/syscalls.h>
26978+
26979+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
26980+{
26981+ unsigned long pax_task_size = TASK_SIZE;
26982+
26983+#ifdef CONFIG_PAX_SEGMEXEC
26984+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
26985+ pax_task_size = SEGMEXEC_TASK_SIZE;
26986+#endif
26987+
26988+ if (flags & MAP_FIXED)
26989+ if (len > pax_task_size || addr > pax_task_size - len)
26990+ return -EINVAL;
26991+
26992+ return 0;
26993+}
26994+
26995+/*
26996+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
26997+ */
26998+static unsigned long get_align_mask(void)
26999+{
27000+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27001+ return 0;
27002+
27003+ if (!(current->flags & PF_RANDOMIZE))
27004+ return 0;
27005+
27006+ return va_align.mask;
27007+}
27008+
27009+unsigned long
27010+arch_get_unmapped_area(struct file *filp, unsigned long addr,
27011+ unsigned long len, unsigned long pgoff, unsigned long flags)
27012+{
27013+ struct mm_struct *mm = current->mm;
27014+ struct vm_area_struct *vma;
27015+ unsigned long pax_task_size = TASK_SIZE;
27016+ struct vm_unmapped_area_info info;
27017+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27018+
27019+#ifdef CONFIG_PAX_SEGMEXEC
27020+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27021+ pax_task_size = SEGMEXEC_TASK_SIZE;
27022+#endif
27023+
27024+ pax_task_size -= PAGE_SIZE;
27025+
27026+ if (len > pax_task_size)
27027+ return -ENOMEM;
27028+
27029+ if (flags & MAP_FIXED)
27030+ return addr;
27031+
27032+#ifdef CONFIG_PAX_RANDMMAP
27033+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27034+#endif
27035+
27036+ if (addr) {
27037+ addr = PAGE_ALIGN(addr);
27038+ if (pax_task_size - len >= addr) {
27039+ vma = find_vma(mm, addr);
27040+ if (check_heap_stack_gap(vma, addr, len, offset))
27041+ return addr;
27042+ }
27043+ }
27044+
27045+ info.flags = 0;
27046+ info.length = len;
27047+ info.align_mask = filp ? get_align_mask() : 0;
27048+ info.align_offset = pgoff << PAGE_SHIFT;
27049+ info.threadstack_offset = offset;
27050+
27051+#ifdef CONFIG_PAX_PAGEEXEC
27052+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27053+ info.low_limit = 0x00110000UL;
27054+ info.high_limit = mm->start_code;
27055+
27056+#ifdef CONFIG_PAX_RANDMMAP
27057+ if (mm->pax_flags & MF_PAX_RANDMMAP)
27058+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27059+#endif
27060+
27061+ if (info.low_limit < info.high_limit) {
27062+ addr = vm_unmapped_area(&info);
27063+ if (!IS_ERR_VALUE(addr))
27064+ return addr;
27065+ }
27066+ } else
27067+#endif
27068+
27069+ info.low_limit = mm->mmap_base;
27070+ info.high_limit = pax_task_size;
27071+
27072+ return vm_unmapped_area(&info);
27073+}
27074+
27075+unsigned long
27076+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27077+ const unsigned long len, const unsigned long pgoff,
27078+ const unsigned long flags)
27079+{
27080+ struct vm_area_struct *vma;
27081+ struct mm_struct *mm = current->mm;
27082+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27083+ struct vm_unmapped_area_info info;
27084+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27085+
27086+#ifdef CONFIG_PAX_SEGMEXEC
27087+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27088+ pax_task_size = SEGMEXEC_TASK_SIZE;
27089+#endif
27090+
27091+ pax_task_size -= PAGE_SIZE;
27092+
27093+ /* requested length too big for entire address space */
27094+ if (len > pax_task_size)
27095+ return -ENOMEM;
27096+
27097+ if (flags & MAP_FIXED)
27098+ return addr;
27099+
27100+#ifdef CONFIG_PAX_PAGEEXEC
27101+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27102+ goto bottomup;
27103+#endif
27104+
27105+#ifdef CONFIG_PAX_RANDMMAP
27106+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27107+#endif
27108+
27109+ /* requesting a specific address */
27110+ if (addr) {
27111+ addr = PAGE_ALIGN(addr);
27112+ if (pax_task_size - len >= addr) {
27113+ vma = find_vma(mm, addr);
27114+ if (check_heap_stack_gap(vma, addr, len, offset))
27115+ return addr;
27116+ }
27117+ }
27118+
27119+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27120+ info.length = len;
27121+ info.low_limit = PAGE_SIZE;
27122+ info.high_limit = mm->mmap_base;
27123+ info.align_mask = filp ? get_align_mask() : 0;
27124+ info.align_offset = pgoff << PAGE_SHIFT;
27125+ info.threadstack_offset = offset;
27126+
27127+ addr = vm_unmapped_area(&info);
27128+ if (!(addr & ~PAGE_MASK))
27129+ return addr;
27130+ VM_BUG_ON(addr != -ENOMEM);
27131+
27132+bottomup:
27133+ /*
27134+ * A failed mmap() very likely causes application failure,
27135+ * so fall back to the bottom-up function here. This scenario
27136+ * can happen with large stack limits and large mmap()
27137+ * allocations.
27138+ */
27139+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27140+}
27141diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27142index 30277e2..5664a29 100644
27143--- a/arch/x86/kernel/sys_x86_64.c
27144+++ b/arch/x86/kernel/sys_x86_64.c
27145@@ -81,8 +81,8 @@ out:
27146 return error;
27147 }
27148
27149-static void find_start_end(unsigned long flags, unsigned long *begin,
27150- unsigned long *end)
27151+static void find_start_end(struct mm_struct *mm, unsigned long flags,
27152+ unsigned long *begin, unsigned long *end)
27153 {
27154 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27155 unsigned long new_begin;
27156@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27157 *begin = new_begin;
27158 }
27159 } else {
27160- *begin = current->mm->mmap_legacy_base;
27161+ *begin = mm->mmap_legacy_base;
27162 *end = TASK_SIZE;
27163 }
27164 }
27165@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27166 struct vm_area_struct *vma;
27167 struct vm_unmapped_area_info info;
27168 unsigned long begin, end;
27169+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27170
27171 if (flags & MAP_FIXED)
27172 return addr;
27173
27174- find_start_end(flags, &begin, &end);
27175+ find_start_end(mm, flags, &begin, &end);
27176
27177 if (len > end)
27178 return -ENOMEM;
27179
27180+#ifdef CONFIG_PAX_RANDMMAP
27181+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27182+#endif
27183+
27184 if (addr) {
27185 addr = PAGE_ALIGN(addr);
27186 vma = find_vma(mm, addr);
27187- if (end - len >= addr &&
27188- (!vma || addr + len <= vma->vm_start))
27189+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27190 return addr;
27191 }
27192
27193@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27194 info.high_limit = end;
27195 info.align_mask = filp ? get_align_mask() : 0;
27196 info.align_offset = pgoff << PAGE_SHIFT;
27197+ info.threadstack_offset = offset;
27198 return vm_unmapped_area(&info);
27199 }
27200
27201@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27202 struct mm_struct *mm = current->mm;
27203 unsigned long addr = addr0;
27204 struct vm_unmapped_area_info info;
27205+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27206
27207 /* requested length too big for entire address space */
27208 if (len > TASK_SIZE)
27209@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27210 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27211 goto bottomup;
27212
27213+#ifdef CONFIG_PAX_RANDMMAP
27214+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27215+#endif
27216+
27217 /* requesting a specific address */
27218 if (addr) {
27219 addr = PAGE_ALIGN(addr);
27220 vma = find_vma(mm, addr);
27221- if (TASK_SIZE - len >= addr &&
27222- (!vma || addr + len <= vma->vm_start))
27223+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27224 return addr;
27225 }
27226
27227@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27228 info.high_limit = mm->mmap_base;
27229 info.align_mask = filp ? get_align_mask() : 0;
27230 info.align_offset = pgoff << PAGE_SHIFT;
27231+ info.threadstack_offset = offset;
27232 addr = vm_unmapped_area(&info);
27233 if (!(addr & ~PAGE_MASK))
27234 return addr;
27235diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27236index 91a4496..bb87552 100644
27237--- a/arch/x86/kernel/tboot.c
27238+++ b/arch/x86/kernel/tboot.c
27239@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27240
27241 void tboot_shutdown(u32 shutdown_type)
27242 {
27243- void (*shutdown)(void);
27244+ void (* __noreturn shutdown)(void);
27245
27246 if (!tboot_enabled())
27247 return;
27248@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27249
27250 switch_to_tboot_pt();
27251
27252- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27253+ shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27254 shutdown();
27255
27256 /* should not reach here */
27257@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27258 return -ENODEV;
27259 }
27260
27261-static atomic_t ap_wfs_count;
27262+static atomic_unchecked_t ap_wfs_count;
27263
27264 static int tboot_wait_for_aps(int num_aps)
27265 {
27266@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27267 {
27268 switch (action) {
27269 case CPU_DYING:
27270- atomic_inc(&ap_wfs_count);
27271+ atomic_inc_unchecked(&ap_wfs_count);
27272 if (num_online_cpus() == 1)
27273- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27274+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27275 return NOTIFY_BAD;
27276 break;
27277 }
27278@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27279
27280 tboot_create_trampoline();
27281
27282- atomic_set(&ap_wfs_count, 0);
27283+ atomic_set_unchecked(&ap_wfs_count, 0);
27284 register_hotcpu_notifier(&tboot_cpu_notifier);
27285
27286 #ifdef CONFIG_DEBUG_FS
27287diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27288index 24d3c91..d06b473 100644
27289--- a/arch/x86/kernel/time.c
27290+++ b/arch/x86/kernel/time.c
27291@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27292 {
27293 unsigned long pc = instruction_pointer(regs);
27294
27295- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27296+ if (!user_mode(regs) && in_lock_functions(pc)) {
27297 #ifdef CONFIG_FRAME_POINTER
27298- return *(unsigned long *)(regs->bp + sizeof(long));
27299+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27300 #else
27301 unsigned long *sp =
27302 (unsigned long *)kernel_stack_pointer(regs);
27303@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27304 * or above a saved flags. Eflags has bits 22-31 zero,
27305 * kernel addresses don't.
27306 */
27307+
27308+#ifdef CONFIG_PAX_KERNEXEC
27309+ return ktla_ktva(sp[0]);
27310+#else
27311 if (sp[0] >> 22)
27312 return sp[0];
27313 if (sp[1] >> 22)
27314 return sp[1];
27315 #endif
27316+
27317+#endif
27318 }
27319 return pc;
27320 }
27321diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27322index f7fec09..9991981 100644
27323--- a/arch/x86/kernel/tls.c
27324+++ b/arch/x86/kernel/tls.c
27325@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27326 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27327 return -EINVAL;
27328
27329+#ifdef CONFIG_PAX_SEGMEXEC
27330+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27331+ return -EINVAL;
27332+#endif
27333+
27334 set_tls_desc(p, idx, &info, 1);
27335
27336 return 0;
27337@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27338
27339 if (kbuf)
27340 info = kbuf;
27341- else if (__copy_from_user(infobuf, ubuf, count))
27342+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27343 return -EFAULT;
27344 else
27345 info = infobuf;
27346diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27347index 1c113db..287b42e 100644
27348--- a/arch/x86/kernel/tracepoint.c
27349+++ b/arch/x86/kernel/tracepoint.c
27350@@ -9,11 +9,11 @@
27351 #include <linux/atomic.h>
27352
27353 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27354-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27355+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27356 (unsigned long) trace_idt_table };
27357
27358 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27359-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27360+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27361
27362 static int trace_irq_vector_refcount;
27363 static DEFINE_MUTEX(irq_vector_mutex);
27364diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27365index b857ed8..51ae4cb 100644
27366--- a/arch/x86/kernel/traps.c
27367+++ b/arch/x86/kernel/traps.c
27368@@ -66,7 +66,7 @@
27369 #include <asm/proto.h>
27370
27371 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27372-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27373+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27374 #else
27375 #include <asm/processor-flags.h>
27376 #include <asm/setup.h>
27377@@ -75,7 +75,7 @@ asmlinkage int system_call(void);
27378 #endif
27379
27380 /* Must be page-aligned because the real IDT is used in a fixmap. */
27381-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27382+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27383
27384 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27385 EXPORT_SYMBOL_GPL(used_vectors);
27386@@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27387 }
27388
27389 static int __kprobes
27390-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27391+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27392 struct pt_regs *regs, long error_code)
27393 {
27394 #ifdef CONFIG_X86_32
27395- if (regs->flags & X86_VM_MASK) {
27396+ if (v8086_mode(regs)) {
27397 /*
27398 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27399 * On nmi (interrupt 2), do_trap should not be called.
27400@@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27401 return -1;
27402 }
27403 #endif
27404- if (!user_mode(regs)) {
27405+ if (!user_mode_novm(regs)) {
27406 if (!fixup_exception(regs)) {
27407 tsk->thread.error_code = error_code;
27408 tsk->thread.trap_nr = trapnr;
27409+
27410+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27411+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27412+ str = "PAX: suspicious stack segment fault";
27413+#endif
27414+
27415 die(str, regs, error_code);
27416 }
27417+
27418+#ifdef CONFIG_PAX_REFCOUNT
27419+ if (trapnr == 4)
27420+ pax_report_refcount_overflow(regs);
27421+#endif
27422+
27423 return 0;
27424 }
27425
27426@@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27427 }
27428
27429 static void __kprobes
27430-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27431+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27432 long error_code, siginfo_t *info)
27433 {
27434 struct task_struct *tsk = current;
27435@@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27436 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27437 printk_ratelimit()) {
27438 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27439- tsk->comm, tsk->pid, str,
27440+ tsk->comm, task_pid_nr(tsk), str,
27441 regs->ip, regs->sp, error_code);
27442 print_vma_addr(" in ", regs->ip);
27443 pr_cont("\n");
27444@@ -277,7 +289,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27445 conditional_sti(regs);
27446
27447 #ifdef CONFIG_X86_32
27448- if (regs->flags & X86_VM_MASK) {
27449+ if (v8086_mode(regs)) {
27450 local_irq_enable();
27451 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27452 goto exit;
27453@@ -285,18 +297,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27454 #endif
27455
27456 tsk = current;
27457- if (!user_mode(regs)) {
27458+ if (!user_mode_novm(regs)) {
27459 if (fixup_exception(regs))
27460 goto exit;
27461
27462 tsk->thread.error_code = error_code;
27463 tsk->thread.trap_nr = X86_TRAP_GP;
27464 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27465- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27466+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27467+
27468+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27469+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27470+ die("PAX: suspicious general protection fault", regs, error_code);
27471+ else
27472+#endif
27473+
27474 die("general protection fault", regs, error_code);
27475+ }
27476 goto exit;
27477 }
27478
27479+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27480+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27481+ struct mm_struct *mm = tsk->mm;
27482+ unsigned long limit;
27483+
27484+ down_write(&mm->mmap_sem);
27485+ limit = mm->context.user_cs_limit;
27486+ if (limit < TASK_SIZE) {
27487+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
27488+ up_write(&mm->mmap_sem);
27489+ return;
27490+ }
27491+ up_write(&mm->mmap_sem);
27492+ }
27493+#endif
27494+
27495 tsk->thread.error_code = error_code;
27496 tsk->thread.trap_nr = X86_TRAP_GP;
27497
27498@@ -457,7 +493,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27499 /* It's safe to allow irq's after DR6 has been saved */
27500 preempt_conditional_sti(regs);
27501
27502- if (regs->flags & X86_VM_MASK) {
27503+ if (v8086_mode(regs)) {
27504 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27505 X86_TRAP_DB);
27506 preempt_conditional_cli(regs);
27507@@ -472,7 +508,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27508 * We already checked v86 mode above, so we can check for kernel mode
27509 * by just checking the CPL of CS.
27510 */
27511- if ((dr6 & DR_STEP) && !user_mode(regs)) {
27512+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27513 tsk->thread.debugreg6 &= ~DR_STEP;
27514 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27515 regs->flags &= ~X86_EFLAGS_TF;
27516@@ -504,7 +540,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27517 return;
27518 conditional_sti(regs);
27519
27520- if (!user_mode_vm(regs))
27521+ if (!user_mode(regs))
27522 {
27523 if (!fixup_exception(regs)) {
27524 task->thread.error_code = error_code;
27525diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
27526index 2ed8459..7cf329f 100644
27527--- a/arch/x86/kernel/uprobes.c
27528+++ b/arch/x86/kernel/uprobes.c
27529@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
27530 int ret = NOTIFY_DONE;
27531
27532 /* We are only interested in userspace traps */
27533- if (regs && !user_mode_vm(regs))
27534+ if (regs && !user_mode(regs))
27535 return NOTIFY_DONE;
27536
27537 switch (val) {
27538@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27539
27540 if (ncopied != rasize) {
27541 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27542- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27543+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27544
27545 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27546 }
27547diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27548index b9242ba..50c5edd 100644
27549--- a/arch/x86/kernel/verify_cpu.S
27550+++ b/arch/x86/kernel/verify_cpu.S
27551@@ -20,6 +20,7 @@
27552 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27553 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27554 * arch/x86/kernel/head_32.S: processor startup
27555+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27556 *
27557 * verify_cpu, returns the status of longmode and SSE in register %eax.
27558 * 0: Success 1: Failure
27559diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27560index e8edcf5..27f9344 100644
27561--- a/arch/x86/kernel/vm86_32.c
27562+++ b/arch/x86/kernel/vm86_32.c
27563@@ -44,6 +44,7 @@
27564 #include <linux/ptrace.h>
27565 #include <linux/audit.h>
27566 #include <linux/stddef.h>
27567+#include <linux/grsecurity.h>
27568
27569 #include <asm/uaccess.h>
27570 #include <asm/io.h>
27571@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
27572 do_exit(SIGSEGV);
27573 }
27574
27575- tss = &per_cpu(init_tss, get_cpu());
27576+ tss = init_tss + get_cpu();
27577 current->thread.sp0 = current->thread.saved_sp0;
27578 current->thread.sysenter_cs = __KERNEL_CS;
27579 load_sp0(tss, &current->thread);
27580@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
27581
27582 if (tsk->thread.saved_sp0)
27583 return -EPERM;
27584+
27585+#ifdef CONFIG_GRKERNSEC_VM86
27586+ if (!capable(CAP_SYS_RAWIO)) {
27587+ gr_handle_vm86();
27588+ return -EPERM;
27589+ }
27590+#endif
27591+
27592 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
27593 offsetof(struct kernel_vm86_struct, vm86plus) -
27594 sizeof(info.regs));
27595@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
27596 int tmp;
27597 struct vm86plus_struct __user *v86;
27598
27599+#ifdef CONFIG_GRKERNSEC_VM86
27600+ if (!capable(CAP_SYS_RAWIO)) {
27601+ gr_handle_vm86();
27602+ return -EPERM;
27603+ }
27604+#endif
27605+
27606 tsk = current;
27607 switch (cmd) {
27608 case VM86_REQUEST_IRQ:
27609@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
27610 tsk->thread.saved_fs = info->regs32->fs;
27611 tsk->thread.saved_gs = get_user_gs(info->regs32);
27612
27613- tss = &per_cpu(init_tss, get_cpu());
27614+ tss = init_tss + get_cpu();
27615 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
27616 if (cpu_has_sep)
27617 tsk->thread.sysenter_cs = 0;
27618@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
27619 goto cannot_handle;
27620 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
27621 goto cannot_handle;
27622- intr_ptr = (unsigned long __user *) (i << 2);
27623+ intr_ptr = (__force unsigned long __user *) (i << 2);
27624 if (get_user(segoffs, intr_ptr))
27625 goto cannot_handle;
27626 if ((segoffs >> 16) == BIOSSEG)
27627diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
27628index da6b35a..977e9cf 100644
27629--- a/arch/x86/kernel/vmlinux.lds.S
27630+++ b/arch/x86/kernel/vmlinux.lds.S
27631@@ -26,6 +26,13 @@
27632 #include <asm/page_types.h>
27633 #include <asm/cache.h>
27634 #include <asm/boot.h>
27635+#include <asm/segment.h>
27636+
27637+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27638+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
27639+#else
27640+#define __KERNEL_TEXT_OFFSET 0
27641+#endif
27642
27643 #undef i386 /* in case the preprocessor is a 32bit one */
27644
27645@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
27646
27647 PHDRS {
27648 text PT_LOAD FLAGS(5); /* R_E */
27649+#ifdef CONFIG_X86_32
27650+ module PT_LOAD FLAGS(5); /* R_E */
27651+#endif
27652+#ifdef CONFIG_XEN
27653+ rodata PT_LOAD FLAGS(5); /* R_E */
27654+#else
27655+ rodata PT_LOAD FLAGS(4); /* R__ */
27656+#endif
27657 data PT_LOAD FLAGS(6); /* RW_ */
27658-#ifdef CONFIG_X86_64
27659+ init.begin PT_LOAD FLAGS(6); /* RW_ */
27660 #ifdef CONFIG_SMP
27661 percpu PT_LOAD FLAGS(6); /* RW_ */
27662 #endif
27663+ text.init PT_LOAD FLAGS(5); /* R_E */
27664+ text.exit PT_LOAD FLAGS(5); /* R_E */
27665 init PT_LOAD FLAGS(7); /* RWE */
27666-#endif
27667 note PT_NOTE FLAGS(0); /* ___ */
27668 }
27669
27670 SECTIONS
27671 {
27672 #ifdef CONFIG_X86_32
27673- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
27674- phys_startup_32 = startup_32 - LOAD_OFFSET;
27675+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
27676 #else
27677- . = __START_KERNEL;
27678- phys_startup_64 = startup_64 - LOAD_OFFSET;
27679+ . = __START_KERNEL;
27680 #endif
27681
27682 /* Text and read-only data */
27683- .text : AT(ADDR(.text) - LOAD_OFFSET) {
27684- _text = .;
27685+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27686 /* bootstrapping code */
27687+#ifdef CONFIG_X86_32
27688+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27689+#else
27690+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27691+#endif
27692+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27693+ _text = .;
27694 HEAD_TEXT
27695 . = ALIGN(8);
27696 _stext = .;
27697@@ -104,13 +124,47 @@ SECTIONS
27698 IRQENTRY_TEXT
27699 *(.fixup)
27700 *(.gnu.warning)
27701- /* End of text section */
27702- _etext = .;
27703 } :text = 0x9090
27704
27705- NOTES :text :note
27706+ . += __KERNEL_TEXT_OFFSET;
27707
27708- EXCEPTION_TABLE(16) :text = 0x9090
27709+#ifdef CONFIG_X86_32
27710+ . = ALIGN(PAGE_SIZE);
27711+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
27712+
27713+#ifdef CONFIG_PAX_KERNEXEC
27714+ MODULES_EXEC_VADDR = .;
27715+ BYTE(0)
27716+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27717+ . = ALIGN(HPAGE_SIZE) - 1;
27718+ MODULES_EXEC_END = .;
27719+#endif
27720+
27721+ } :module
27722+#endif
27723+
27724+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27725+ /* End of text section */
27726+ BYTE(0)
27727+ _etext = . - __KERNEL_TEXT_OFFSET;
27728+ }
27729+
27730+#ifdef CONFIG_X86_32
27731+ . = ALIGN(PAGE_SIZE);
27732+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27733+ . = ALIGN(PAGE_SIZE);
27734+ *(.empty_zero_page)
27735+ *(.initial_pg_fixmap)
27736+ *(.initial_pg_pmd)
27737+ *(.initial_page_table)
27738+ *(.swapper_pg_dir)
27739+ } :rodata
27740+#endif
27741+
27742+ . = ALIGN(PAGE_SIZE);
27743+ NOTES :rodata :note
27744+
27745+ EXCEPTION_TABLE(16) :rodata
27746
27747 #if defined(CONFIG_DEBUG_RODATA)
27748 /* .text should occupy whole number of pages */
27749@@ -122,16 +176,20 @@ SECTIONS
27750
27751 /* Data */
27752 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27753+
27754+#ifdef CONFIG_PAX_KERNEXEC
27755+ . = ALIGN(HPAGE_SIZE);
27756+#else
27757+ . = ALIGN(PAGE_SIZE);
27758+#endif
27759+
27760 /* Start of data section */
27761 _sdata = .;
27762
27763 /* init_task */
27764 INIT_TASK_DATA(THREAD_SIZE)
27765
27766-#ifdef CONFIG_X86_32
27767- /* 32 bit has nosave before _edata */
27768 NOSAVE_DATA
27769-#endif
27770
27771 PAGE_ALIGNED_DATA(PAGE_SIZE)
27772
27773@@ -172,12 +230,19 @@ SECTIONS
27774 #endif /* CONFIG_X86_64 */
27775
27776 /* Init code and data - will be freed after init */
27777- . = ALIGN(PAGE_SIZE);
27778 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
27779+ BYTE(0)
27780+
27781+#ifdef CONFIG_PAX_KERNEXEC
27782+ . = ALIGN(HPAGE_SIZE);
27783+#else
27784+ . = ALIGN(PAGE_SIZE);
27785+#endif
27786+
27787 __init_begin = .; /* paired with __init_end */
27788- }
27789+ } :init.begin
27790
27791-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
27792+#ifdef CONFIG_SMP
27793 /*
27794 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
27795 * output PHDR, so the next output section - .init.text - should
27796@@ -186,12 +251,27 @@ SECTIONS
27797 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
27798 #endif
27799
27800- INIT_TEXT_SECTION(PAGE_SIZE)
27801-#ifdef CONFIG_X86_64
27802- :init
27803-#endif
27804+ . = ALIGN(PAGE_SIZE);
27805+ init_begin = .;
27806+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
27807+ VMLINUX_SYMBOL(_sinittext) = .;
27808+ INIT_TEXT
27809+ VMLINUX_SYMBOL(_einittext) = .;
27810+ . = ALIGN(PAGE_SIZE);
27811+ } :text.init
27812
27813- INIT_DATA_SECTION(16)
27814+ /*
27815+ * .exit.text is discard at runtime, not link time, to deal with
27816+ * references from .altinstructions and .eh_frame
27817+ */
27818+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27819+ EXIT_TEXT
27820+ . = ALIGN(16);
27821+ } :text.exit
27822+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
27823+
27824+ . = ALIGN(PAGE_SIZE);
27825+ INIT_DATA_SECTION(16) :init
27826
27827 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
27828 __x86_cpu_dev_start = .;
27829@@ -262,19 +342,12 @@ SECTIONS
27830 }
27831
27832 . = ALIGN(8);
27833- /*
27834- * .exit.text is discard at runtime, not link time, to deal with
27835- * references from .altinstructions and .eh_frame
27836- */
27837- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
27838- EXIT_TEXT
27839- }
27840
27841 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
27842 EXIT_DATA
27843 }
27844
27845-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
27846+#ifndef CONFIG_SMP
27847 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
27848 #endif
27849
27850@@ -293,16 +366,10 @@ SECTIONS
27851 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
27852 __smp_locks = .;
27853 *(.smp_locks)
27854- . = ALIGN(PAGE_SIZE);
27855 __smp_locks_end = .;
27856+ . = ALIGN(PAGE_SIZE);
27857 }
27858
27859-#ifdef CONFIG_X86_64
27860- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
27861- NOSAVE_DATA
27862- }
27863-#endif
27864-
27865 /* BSS */
27866 . = ALIGN(PAGE_SIZE);
27867 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
27868@@ -318,6 +385,7 @@ SECTIONS
27869 __brk_base = .;
27870 . += 64 * 1024; /* 64k alignment slop space */
27871 *(.brk_reservation) /* areas brk users have reserved */
27872+ . = ALIGN(HPAGE_SIZE);
27873 __brk_limit = .;
27874 }
27875
27876@@ -344,13 +412,12 @@ SECTIONS
27877 * for the boot processor.
27878 */
27879 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
27880-INIT_PER_CPU(gdt_page);
27881 INIT_PER_CPU(irq_stack_union);
27882
27883 /*
27884 * Build-time check on the image size:
27885 */
27886-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
27887+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
27888 "kernel image bigger than KERNEL_IMAGE_SIZE");
27889
27890 #ifdef CONFIG_SMP
27891diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
27892index 1f96f93..d5c8f7a 100644
27893--- a/arch/x86/kernel/vsyscall_64.c
27894+++ b/arch/x86/kernel/vsyscall_64.c
27895@@ -56,15 +56,13 @@
27896 DEFINE_VVAR(int, vgetcpu_mode);
27897 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
27898
27899-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
27900+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
27901
27902 static int __init vsyscall_setup(char *str)
27903 {
27904 if (str) {
27905 if (!strcmp("emulate", str))
27906 vsyscall_mode = EMULATE;
27907- else if (!strcmp("native", str))
27908- vsyscall_mode = NATIVE;
27909 else if (!strcmp("none", str))
27910 vsyscall_mode = NONE;
27911 else
27912@@ -323,8 +321,7 @@ do_ret:
27913 return true;
27914
27915 sigsegv:
27916- force_sig(SIGSEGV, current);
27917- return true;
27918+ do_group_exit(SIGKILL);
27919 }
27920
27921 /*
27922@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
27923 extern char __vvar_page;
27924 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
27925
27926- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
27927- vsyscall_mode == NATIVE
27928- ? PAGE_KERNEL_VSYSCALL
27929- : PAGE_KERNEL_VVAR);
27930+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
27931 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
27932 (unsigned long)VSYSCALL_START);
27933
27934diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
27935index 04068192..4d75aa6 100644
27936--- a/arch/x86/kernel/x8664_ksyms_64.c
27937+++ b/arch/x86/kernel/x8664_ksyms_64.c
27938@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
27939 EXPORT_SYMBOL(copy_user_generic_unrolled);
27940 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
27941 EXPORT_SYMBOL(__copy_user_nocache);
27942-EXPORT_SYMBOL(_copy_from_user);
27943-EXPORT_SYMBOL(_copy_to_user);
27944
27945 EXPORT_SYMBOL(copy_page);
27946 EXPORT_SYMBOL(clear_page);
27947@@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
27948 EXPORT_SYMBOL(___preempt_schedule_context);
27949 #endif
27950 #endif
27951+
27952+#ifdef CONFIG_PAX_PER_CPU_PGD
27953+EXPORT_SYMBOL(cpu_pgd);
27954+#endif
27955diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
27956index 021783b..6511282 100644
27957--- a/arch/x86/kernel/x86_init.c
27958+++ b/arch/x86/kernel/x86_init.c
27959@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
27960 static void default_nmi_init(void) { };
27961 static int default_i8042_detect(void) { return 1; };
27962
27963-struct x86_platform_ops x86_platform = {
27964+struct x86_platform_ops x86_platform __read_only = {
27965 .calibrate_tsc = native_calibrate_tsc,
27966 .get_wallclock = mach_get_cmos_time,
27967 .set_wallclock = mach_set_rtc_mmss,
27968@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
27969 EXPORT_SYMBOL_GPL(x86_platform);
27970
27971 #if defined(CONFIG_PCI_MSI)
27972-struct x86_msi_ops x86_msi = {
27973+struct x86_msi_ops x86_msi __read_only = {
27974 .setup_msi_irqs = native_setup_msi_irqs,
27975 .compose_msi_msg = native_compose_msi_msg,
27976 .teardown_msi_irq = native_teardown_msi_irq,
27977@@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
27978 }
27979 #endif
27980
27981-struct x86_io_apic_ops x86_io_apic_ops = {
27982+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
27983 .init = native_io_apic_init_mappings,
27984 .read = native_io_apic_read,
27985 .write = native_io_apic_write,
27986diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
27987index 422fd82..b2d262e 100644
27988--- a/arch/x86/kernel/xsave.c
27989+++ b/arch/x86/kernel/xsave.c
27990@@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
27991
27992 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
27993 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
27994- err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27995+ err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27996
27997 if (!use_xsave())
27998 return err;
27999
28000- err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28001+ err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28002
28003 /*
28004 * Read the xstate_bv which we copied (directly from the cpu or
28005 * from the state in task struct) to the user buffers.
28006 */
28007- err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28008+ err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28009
28010 /*
28011 * For legacy compatible, we always set FP/SSE bits in the bit
28012@@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28013 */
28014 xstate_bv |= XSTATE_FPSSE;
28015
28016- err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28017+ err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28018
28019 return err;
28020 }
28021@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28022 {
28023 int err;
28024
28025+ buf = (struct xsave_struct __user *)____m(buf);
28026 if (use_xsave())
28027 err = xsave_user(buf);
28028 else if (use_fxsr())
28029@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28030 */
28031 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28032 {
28033+ buf = (void __user *)____m(buf);
28034 if (use_xsave()) {
28035 if ((unsigned long)buf % 64 || fx_only) {
28036 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28037diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28038index c697625..a032162 100644
28039--- a/arch/x86/kvm/cpuid.c
28040+++ b/arch/x86/kvm/cpuid.c
28041@@ -156,15 +156,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28042 struct kvm_cpuid2 *cpuid,
28043 struct kvm_cpuid_entry2 __user *entries)
28044 {
28045- int r;
28046+ int r, i;
28047
28048 r = -E2BIG;
28049 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28050 goto out;
28051 r = -EFAULT;
28052- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28053- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28054+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28055 goto out;
28056+ for (i = 0; i < cpuid->nent; ++i) {
28057+ struct kvm_cpuid_entry2 cpuid_entry;
28058+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28059+ goto out;
28060+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
28061+ }
28062 vcpu->arch.cpuid_nent = cpuid->nent;
28063 kvm_apic_set_version(vcpu);
28064 kvm_x86_ops->cpuid_update(vcpu);
28065@@ -179,15 +184,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28066 struct kvm_cpuid2 *cpuid,
28067 struct kvm_cpuid_entry2 __user *entries)
28068 {
28069- int r;
28070+ int r, i;
28071
28072 r = -E2BIG;
28073 if (cpuid->nent < vcpu->arch.cpuid_nent)
28074 goto out;
28075 r = -EFAULT;
28076- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28077- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28078+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28079 goto out;
28080+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28081+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28082+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28083+ goto out;
28084+ }
28085 return 0;
28086
28087 out:
28088diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28089index d86ff15..e77b023 100644
28090--- a/arch/x86/kvm/lapic.c
28091+++ b/arch/x86/kvm/lapic.c
28092@@ -55,7 +55,7 @@
28093 #define APIC_BUS_CYCLE_NS 1
28094
28095 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28096-#define apic_debug(fmt, arg...)
28097+#define apic_debug(fmt, arg...) do {} while (0)
28098
28099 #define APIC_LVT_NUM 6
28100 /* 14 is the version for Xeon and Pentium 8.4.8*/
28101diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28102index cba218a..1cc1bed 100644
28103--- a/arch/x86/kvm/paging_tmpl.h
28104+++ b/arch/x86/kvm/paging_tmpl.h
28105@@ -331,7 +331,7 @@ retry_walk:
28106 if (unlikely(kvm_is_error_hva(host_addr)))
28107 goto error;
28108
28109- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28110+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28111 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28112 goto error;
28113 walker->ptep_user[walker->level - 1] = ptep_user;
28114diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28115index 532add1..59eb241 100644
28116--- a/arch/x86/kvm/svm.c
28117+++ b/arch/x86/kvm/svm.c
28118@@ -3495,7 +3495,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28119 int cpu = raw_smp_processor_id();
28120
28121 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28122+
28123+ pax_open_kernel();
28124 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28125+ pax_close_kernel();
28126+
28127 load_TR_desc();
28128 }
28129
28130@@ -3898,6 +3902,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28131 #endif
28132 #endif
28133
28134+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28135+ __set_fs(current_thread_info()->addr_limit);
28136+#endif
28137+
28138 reload_tss(vcpu);
28139
28140 local_irq_disable();
28141diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28142index 31c3e8b..ca3acc6 100644
28143--- a/arch/x86/kvm/vmx.c
28144+++ b/arch/x86/kvm/vmx.c
28145@@ -1316,12 +1316,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28146 #endif
28147 }
28148
28149-static void vmcs_clear_bits(unsigned long field, u32 mask)
28150+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28151 {
28152 vmcs_writel(field, vmcs_readl(field) & ~mask);
28153 }
28154
28155-static void vmcs_set_bits(unsigned long field, u32 mask)
28156+static void vmcs_set_bits(unsigned long field, unsigned long mask)
28157 {
28158 vmcs_writel(field, vmcs_readl(field) | mask);
28159 }
28160@@ -1522,7 +1522,11 @@ static void reload_tss(void)
28161 struct desc_struct *descs;
28162
28163 descs = (void *)gdt->address;
28164+
28165+ pax_open_kernel();
28166 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28167+ pax_close_kernel();
28168+
28169 load_TR_desc();
28170 }
28171
28172@@ -1746,6 +1750,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28173 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28174 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28175
28176+#ifdef CONFIG_PAX_PER_CPU_PGD
28177+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28178+#endif
28179+
28180 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28181 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28182 vmx->loaded_vmcs->cpu = cpu;
28183@@ -2033,7 +2041,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28184 * reads and returns guest's timestamp counter "register"
28185 * guest_tsc = host_tsc + tsc_offset -- 21.3
28186 */
28187-static u64 guest_read_tsc(void)
28188+static u64 __intentional_overflow(-1) guest_read_tsc(void)
28189 {
28190 u64 host_tsc, tsc_offset;
28191
28192@@ -2987,8 +2995,11 @@ static __init int hardware_setup(void)
28193 if (!cpu_has_vmx_flexpriority())
28194 flexpriority_enabled = 0;
28195
28196- if (!cpu_has_vmx_tpr_shadow())
28197- kvm_x86_ops->update_cr8_intercept = NULL;
28198+ if (!cpu_has_vmx_tpr_shadow()) {
28199+ pax_open_kernel();
28200+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28201+ pax_close_kernel();
28202+ }
28203
28204 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28205 kvm_disable_largepages();
28206@@ -2999,13 +3010,15 @@ static __init int hardware_setup(void)
28207 if (!cpu_has_vmx_apicv())
28208 enable_apicv = 0;
28209
28210+ pax_open_kernel();
28211 if (enable_apicv)
28212- kvm_x86_ops->update_cr8_intercept = NULL;
28213+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28214 else {
28215- kvm_x86_ops->hwapic_irr_update = NULL;
28216- kvm_x86_ops->deliver_posted_interrupt = NULL;
28217- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28218+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28219+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28220+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28221 }
28222+ pax_close_kernel();
28223
28224 if (nested)
28225 nested_vmx_setup_ctls_msrs();
28226@@ -4134,7 +4147,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28227
28228 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28229 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28230+
28231+#ifndef CONFIG_PAX_PER_CPU_PGD
28232 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28233+#endif
28234
28235 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28236 #ifdef CONFIG_X86_64
28237@@ -4156,7 +4172,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28238 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28239 vmx->host_idt_base = dt.address;
28240
28241- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28242+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28243
28244 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28245 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28246@@ -7219,6 +7235,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28247 "jmp 2f \n\t"
28248 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28249 "2: "
28250+
28251+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28252+ "ljmp %[cs],$3f\n\t"
28253+ "3: "
28254+#endif
28255+
28256 /* Save guest registers, load host registers, keep flags */
28257 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28258 "pop %0 \n\t"
28259@@ -7271,6 +7293,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28260 #endif
28261 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28262 [wordsize]"i"(sizeof(ulong))
28263+
28264+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28265+ ,[cs]"i"(__KERNEL_CS)
28266+#endif
28267+
28268 : "cc", "memory"
28269 #ifdef CONFIG_X86_64
28270 , "rax", "rbx", "rdi", "rsi"
28271@@ -7284,7 +7311,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28272 if (debugctlmsr)
28273 update_debugctlmsr(debugctlmsr);
28274
28275-#ifndef CONFIG_X86_64
28276+#ifdef CONFIG_X86_32
28277 /*
28278 * The sysexit path does not restore ds/es, so we must set them to
28279 * a reasonable value ourselves.
28280@@ -7293,8 +7320,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28281 * may be executed in interrupt context, which saves and restore segments
28282 * around it, nullifying its effect.
28283 */
28284- loadsegment(ds, __USER_DS);
28285- loadsegment(es, __USER_DS);
28286+ loadsegment(ds, __KERNEL_DS);
28287+ loadsegment(es, __KERNEL_DS);
28288+ loadsegment(ss, __KERNEL_DS);
28289+
28290+#ifdef CONFIG_PAX_KERNEXEC
28291+ loadsegment(fs, __KERNEL_PERCPU);
28292+#endif
28293+
28294+#ifdef CONFIG_PAX_MEMORY_UDEREF
28295+ __set_fs(current_thread_info()->addr_limit);
28296+#endif
28297+
28298 #endif
28299
28300 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28301diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28302index 4e33b85..fa94855 100644
28303--- a/arch/x86/kvm/x86.c
28304+++ b/arch/x86/kvm/x86.c
28305@@ -1791,8 +1791,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28306 {
28307 struct kvm *kvm = vcpu->kvm;
28308 int lm = is_long_mode(vcpu);
28309- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28310- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28311+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28312+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28313 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28314 : kvm->arch.xen_hvm_config.blob_size_32;
28315 u32 page_num = data & ~PAGE_MASK;
28316@@ -2676,6 +2676,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28317 if (n < msr_list.nmsrs)
28318 goto out;
28319 r = -EFAULT;
28320+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28321+ goto out;
28322 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28323 num_msrs_to_save * sizeof(u32)))
28324 goto out;
28325@@ -5485,7 +5487,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28326 };
28327 #endif
28328
28329-int kvm_arch_init(void *opaque)
28330+int kvm_arch_init(const void *opaque)
28331 {
28332 int r;
28333 struct kvm_x86_ops *ops = opaque;
28334diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28335index bdf8532..f63c587 100644
28336--- a/arch/x86/lguest/boot.c
28337+++ b/arch/x86/lguest/boot.c
28338@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28339 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28340 * Launcher to reboot us.
28341 */
28342-static void lguest_restart(char *reason)
28343+static __noreturn void lguest_restart(char *reason)
28344 {
28345 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28346+ BUG();
28347 }
28348
28349 /*G:050
28350diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28351index 00933d5..3a64af9 100644
28352--- a/arch/x86/lib/atomic64_386_32.S
28353+++ b/arch/x86/lib/atomic64_386_32.S
28354@@ -48,6 +48,10 @@ BEGIN(read)
28355 movl (v), %eax
28356 movl 4(v), %edx
28357 RET_ENDP
28358+BEGIN(read_unchecked)
28359+ movl (v), %eax
28360+ movl 4(v), %edx
28361+RET_ENDP
28362 #undef v
28363
28364 #define v %esi
28365@@ -55,6 +59,10 @@ BEGIN(set)
28366 movl %ebx, (v)
28367 movl %ecx, 4(v)
28368 RET_ENDP
28369+BEGIN(set_unchecked)
28370+ movl %ebx, (v)
28371+ movl %ecx, 4(v)
28372+RET_ENDP
28373 #undef v
28374
28375 #define v %esi
28376@@ -70,6 +78,20 @@ RET_ENDP
28377 BEGIN(add)
28378 addl %eax, (v)
28379 adcl %edx, 4(v)
28380+
28381+#ifdef CONFIG_PAX_REFCOUNT
28382+ jno 0f
28383+ subl %eax, (v)
28384+ sbbl %edx, 4(v)
28385+ int $4
28386+0:
28387+ _ASM_EXTABLE(0b, 0b)
28388+#endif
28389+
28390+RET_ENDP
28391+BEGIN(add_unchecked)
28392+ addl %eax, (v)
28393+ adcl %edx, 4(v)
28394 RET_ENDP
28395 #undef v
28396
28397@@ -77,6 +99,24 @@ RET_ENDP
28398 BEGIN(add_return)
28399 addl (v), %eax
28400 adcl 4(v), %edx
28401+
28402+#ifdef CONFIG_PAX_REFCOUNT
28403+ into
28404+1234:
28405+ _ASM_EXTABLE(1234b, 2f)
28406+#endif
28407+
28408+ movl %eax, (v)
28409+ movl %edx, 4(v)
28410+
28411+#ifdef CONFIG_PAX_REFCOUNT
28412+2:
28413+#endif
28414+
28415+RET_ENDP
28416+BEGIN(add_return_unchecked)
28417+ addl (v), %eax
28418+ adcl 4(v), %edx
28419 movl %eax, (v)
28420 movl %edx, 4(v)
28421 RET_ENDP
28422@@ -86,6 +126,20 @@ RET_ENDP
28423 BEGIN(sub)
28424 subl %eax, (v)
28425 sbbl %edx, 4(v)
28426+
28427+#ifdef CONFIG_PAX_REFCOUNT
28428+ jno 0f
28429+ addl %eax, (v)
28430+ adcl %edx, 4(v)
28431+ int $4
28432+0:
28433+ _ASM_EXTABLE(0b, 0b)
28434+#endif
28435+
28436+RET_ENDP
28437+BEGIN(sub_unchecked)
28438+ subl %eax, (v)
28439+ sbbl %edx, 4(v)
28440 RET_ENDP
28441 #undef v
28442
28443@@ -96,6 +150,27 @@ BEGIN(sub_return)
28444 sbbl $0, %edx
28445 addl (v), %eax
28446 adcl 4(v), %edx
28447+
28448+#ifdef CONFIG_PAX_REFCOUNT
28449+ into
28450+1234:
28451+ _ASM_EXTABLE(1234b, 2f)
28452+#endif
28453+
28454+ movl %eax, (v)
28455+ movl %edx, 4(v)
28456+
28457+#ifdef CONFIG_PAX_REFCOUNT
28458+2:
28459+#endif
28460+
28461+RET_ENDP
28462+BEGIN(sub_return_unchecked)
28463+ negl %edx
28464+ negl %eax
28465+ sbbl $0, %edx
28466+ addl (v), %eax
28467+ adcl 4(v), %edx
28468 movl %eax, (v)
28469 movl %edx, 4(v)
28470 RET_ENDP
28471@@ -105,6 +180,20 @@ RET_ENDP
28472 BEGIN(inc)
28473 addl $1, (v)
28474 adcl $0, 4(v)
28475+
28476+#ifdef CONFIG_PAX_REFCOUNT
28477+ jno 0f
28478+ subl $1, (v)
28479+ sbbl $0, 4(v)
28480+ int $4
28481+0:
28482+ _ASM_EXTABLE(0b, 0b)
28483+#endif
28484+
28485+RET_ENDP
28486+BEGIN(inc_unchecked)
28487+ addl $1, (v)
28488+ adcl $0, 4(v)
28489 RET_ENDP
28490 #undef v
28491
28492@@ -114,6 +203,26 @@ BEGIN(inc_return)
28493 movl 4(v), %edx
28494 addl $1, %eax
28495 adcl $0, %edx
28496+
28497+#ifdef CONFIG_PAX_REFCOUNT
28498+ into
28499+1234:
28500+ _ASM_EXTABLE(1234b, 2f)
28501+#endif
28502+
28503+ movl %eax, (v)
28504+ movl %edx, 4(v)
28505+
28506+#ifdef CONFIG_PAX_REFCOUNT
28507+2:
28508+#endif
28509+
28510+RET_ENDP
28511+BEGIN(inc_return_unchecked)
28512+ movl (v), %eax
28513+ movl 4(v), %edx
28514+ addl $1, %eax
28515+ adcl $0, %edx
28516 movl %eax, (v)
28517 movl %edx, 4(v)
28518 RET_ENDP
28519@@ -123,6 +232,20 @@ RET_ENDP
28520 BEGIN(dec)
28521 subl $1, (v)
28522 sbbl $0, 4(v)
28523+
28524+#ifdef CONFIG_PAX_REFCOUNT
28525+ jno 0f
28526+ addl $1, (v)
28527+ adcl $0, 4(v)
28528+ int $4
28529+0:
28530+ _ASM_EXTABLE(0b, 0b)
28531+#endif
28532+
28533+RET_ENDP
28534+BEGIN(dec_unchecked)
28535+ subl $1, (v)
28536+ sbbl $0, 4(v)
28537 RET_ENDP
28538 #undef v
28539
28540@@ -132,6 +255,26 @@ BEGIN(dec_return)
28541 movl 4(v), %edx
28542 subl $1, %eax
28543 sbbl $0, %edx
28544+
28545+#ifdef CONFIG_PAX_REFCOUNT
28546+ into
28547+1234:
28548+ _ASM_EXTABLE(1234b, 2f)
28549+#endif
28550+
28551+ movl %eax, (v)
28552+ movl %edx, 4(v)
28553+
28554+#ifdef CONFIG_PAX_REFCOUNT
28555+2:
28556+#endif
28557+
28558+RET_ENDP
28559+BEGIN(dec_return_unchecked)
28560+ movl (v), %eax
28561+ movl 4(v), %edx
28562+ subl $1, %eax
28563+ sbbl $0, %edx
28564 movl %eax, (v)
28565 movl %edx, 4(v)
28566 RET_ENDP
28567@@ -143,6 +286,13 @@ BEGIN(add_unless)
28568 adcl %edx, %edi
28569 addl (v), %eax
28570 adcl 4(v), %edx
28571+
28572+#ifdef CONFIG_PAX_REFCOUNT
28573+ into
28574+1234:
28575+ _ASM_EXTABLE(1234b, 2f)
28576+#endif
28577+
28578 cmpl %eax, %ecx
28579 je 3f
28580 1:
28581@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
28582 1:
28583 addl $1, %eax
28584 adcl $0, %edx
28585+
28586+#ifdef CONFIG_PAX_REFCOUNT
28587+ into
28588+1234:
28589+ _ASM_EXTABLE(1234b, 2f)
28590+#endif
28591+
28592 movl %eax, (v)
28593 movl %edx, 4(v)
28594 movl $1, %eax
28595@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28596 movl 4(v), %edx
28597 subl $1, %eax
28598 sbbl $0, %edx
28599+
28600+#ifdef CONFIG_PAX_REFCOUNT
28601+ into
28602+1234:
28603+ _ASM_EXTABLE(1234b, 1f)
28604+#endif
28605+
28606 js 1f
28607 movl %eax, (v)
28608 movl %edx, 4(v)
28609diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28610index f5cc9eb..51fa319 100644
28611--- a/arch/x86/lib/atomic64_cx8_32.S
28612+++ b/arch/x86/lib/atomic64_cx8_32.S
28613@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28614 CFI_STARTPROC
28615
28616 read64 %ecx
28617+ pax_force_retaddr
28618 ret
28619 CFI_ENDPROC
28620 ENDPROC(atomic64_read_cx8)
28621
28622+ENTRY(atomic64_read_unchecked_cx8)
28623+ CFI_STARTPROC
28624+
28625+ read64 %ecx
28626+ pax_force_retaddr
28627+ ret
28628+ CFI_ENDPROC
28629+ENDPROC(atomic64_read_unchecked_cx8)
28630+
28631 ENTRY(atomic64_set_cx8)
28632 CFI_STARTPROC
28633
28634@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28635 cmpxchg8b (%esi)
28636 jne 1b
28637
28638+ pax_force_retaddr
28639 ret
28640 CFI_ENDPROC
28641 ENDPROC(atomic64_set_cx8)
28642
28643+ENTRY(atomic64_set_unchecked_cx8)
28644+ CFI_STARTPROC
28645+
28646+1:
28647+/* we don't need LOCK_PREFIX since aligned 64-bit writes
28648+ * are atomic on 586 and newer */
28649+ cmpxchg8b (%esi)
28650+ jne 1b
28651+
28652+ pax_force_retaddr
28653+ ret
28654+ CFI_ENDPROC
28655+ENDPROC(atomic64_set_unchecked_cx8)
28656+
28657 ENTRY(atomic64_xchg_cx8)
28658 CFI_STARTPROC
28659
28660@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28661 cmpxchg8b (%esi)
28662 jne 1b
28663
28664+ pax_force_retaddr
28665 ret
28666 CFI_ENDPROC
28667 ENDPROC(atomic64_xchg_cx8)
28668
28669-.macro addsub_return func ins insc
28670-ENTRY(atomic64_\func\()_return_cx8)
28671+.macro addsub_return func ins insc unchecked=""
28672+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28673 CFI_STARTPROC
28674 SAVE ebp
28675 SAVE ebx
28676@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28677 movl %edx, %ecx
28678 \ins\()l %esi, %ebx
28679 \insc\()l %edi, %ecx
28680+
28681+.ifb \unchecked
28682+#ifdef CONFIG_PAX_REFCOUNT
28683+ into
28684+2:
28685+ _ASM_EXTABLE(2b, 3f)
28686+#endif
28687+.endif
28688+
28689 LOCK_PREFIX
28690 cmpxchg8b (%ebp)
28691 jne 1b
28692-
28693-10:
28694 movl %ebx, %eax
28695 movl %ecx, %edx
28696+
28697+.ifb \unchecked
28698+#ifdef CONFIG_PAX_REFCOUNT
28699+3:
28700+#endif
28701+.endif
28702+
28703 RESTORE edi
28704 RESTORE esi
28705 RESTORE ebx
28706 RESTORE ebp
28707+ pax_force_retaddr
28708 ret
28709 CFI_ENDPROC
28710-ENDPROC(atomic64_\func\()_return_cx8)
28711+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28712 .endm
28713
28714 addsub_return add add adc
28715 addsub_return sub sub sbb
28716+addsub_return add add adc _unchecked
28717+addsub_return sub sub sbb _unchecked
28718
28719-.macro incdec_return func ins insc
28720-ENTRY(atomic64_\func\()_return_cx8)
28721+.macro incdec_return func ins insc unchecked=""
28722+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28723 CFI_STARTPROC
28724 SAVE ebx
28725
28726@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28727 movl %edx, %ecx
28728 \ins\()l $1, %ebx
28729 \insc\()l $0, %ecx
28730+
28731+.ifb \unchecked
28732+#ifdef CONFIG_PAX_REFCOUNT
28733+ into
28734+2:
28735+ _ASM_EXTABLE(2b, 3f)
28736+#endif
28737+.endif
28738+
28739 LOCK_PREFIX
28740 cmpxchg8b (%esi)
28741 jne 1b
28742
28743-10:
28744 movl %ebx, %eax
28745 movl %ecx, %edx
28746+
28747+.ifb \unchecked
28748+#ifdef CONFIG_PAX_REFCOUNT
28749+3:
28750+#endif
28751+.endif
28752+
28753 RESTORE ebx
28754+ pax_force_retaddr
28755 ret
28756 CFI_ENDPROC
28757-ENDPROC(atomic64_\func\()_return_cx8)
28758+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28759 .endm
28760
28761 incdec_return inc add adc
28762 incdec_return dec sub sbb
28763+incdec_return inc add adc _unchecked
28764+incdec_return dec sub sbb _unchecked
28765
28766 ENTRY(atomic64_dec_if_positive_cx8)
28767 CFI_STARTPROC
28768@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
28769 movl %edx, %ecx
28770 subl $1, %ebx
28771 sbb $0, %ecx
28772+
28773+#ifdef CONFIG_PAX_REFCOUNT
28774+ into
28775+1234:
28776+ _ASM_EXTABLE(1234b, 2f)
28777+#endif
28778+
28779 js 2f
28780 LOCK_PREFIX
28781 cmpxchg8b (%esi)
28782@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
28783 movl %ebx, %eax
28784 movl %ecx, %edx
28785 RESTORE ebx
28786+ pax_force_retaddr
28787 ret
28788 CFI_ENDPROC
28789 ENDPROC(atomic64_dec_if_positive_cx8)
28790@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
28791 movl %edx, %ecx
28792 addl %ebp, %ebx
28793 adcl %edi, %ecx
28794+
28795+#ifdef CONFIG_PAX_REFCOUNT
28796+ into
28797+1234:
28798+ _ASM_EXTABLE(1234b, 3f)
28799+#endif
28800+
28801 LOCK_PREFIX
28802 cmpxchg8b (%esi)
28803 jne 1b
28804@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
28805 CFI_ADJUST_CFA_OFFSET -8
28806 RESTORE ebx
28807 RESTORE ebp
28808+ pax_force_retaddr
28809 ret
28810 4:
28811 cmpl %edx, 4(%esp)
28812@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
28813 xorl %ecx, %ecx
28814 addl $1, %ebx
28815 adcl %edx, %ecx
28816+
28817+#ifdef CONFIG_PAX_REFCOUNT
28818+ into
28819+1234:
28820+ _ASM_EXTABLE(1234b, 3f)
28821+#endif
28822+
28823 LOCK_PREFIX
28824 cmpxchg8b (%esi)
28825 jne 1b
28826@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
28827 movl $1, %eax
28828 3:
28829 RESTORE ebx
28830+ pax_force_retaddr
28831 ret
28832 CFI_ENDPROC
28833 ENDPROC(atomic64_inc_not_zero_cx8)
28834diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
28835index e78b8ee..7e173a8 100644
28836--- a/arch/x86/lib/checksum_32.S
28837+++ b/arch/x86/lib/checksum_32.S
28838@@ -29,7 +29,8 @@
28839 #include <asm/dwarf2.h>
28840 #include <asm/errno.h>
28841 #include <asm/asm.h>
28842-
28843+#include <asm/segment.h>
28844+
28845 /*
28846 * computes a partial checksum, e.g. for TCP/UDP fragments
28847 */
28848@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
28849
28850 #define ARGBASE 16
28851 #define FP 12
28852-
28853-ENTRY(csum_partial_copy_generic)
28854+
28855+ENTRY(csum_partial_copy_generic_to_user)
28856 CFI_STARTPROC
28857+
28858+#ifdef CONFIG_PAX_MEMORY_UDEREF
28859+ pushl_cfi %gs
28860+ popl_cfi %es
28861+ jmp csum_partial_copy_generic
28862+#endif
28863+
28864+ENTRY(csum_partial_copy_generic_from_user)
28865+
28866+#ifdef CONFIG_PAX_MEMORY_UDEREF
28867+ pushl_cfi %gs
28868+ popl_cfi %ds
28869+#endif
28870+
28871+ENTRY(csum_partial_copy_generic)
28872 subl $4,%esp
28873 CFI_ADJUST_CFA_OFFSET 4
28874 pushl_cfi %edi
28875@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
28876 jmp 4f
28877 SRC(1: movw (%esi), %bx )
28878 addl $2, %esi
28879-DST( movw %bx, (%edi) )
28880+DST( movw %bx, %es:(%edi) )
28881 addl $2, %edi
28882 addw %bx, %ax
28883 adcl $0, %eax
28884@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
28885 SRC(1: movl (%esi), %ebx )
28886 SRC( movl 4(%esi), %edx )
28887 adcl %ebx, %eax
28888-DST( movl %ebx, (%edi) )
28889+DST( movl %ebx, %es:(%edi) )
28890 adcl %edx, %eax
28891-DST( movl %edx, 4(%edi) )
28892+DST( movl %edx, %es:4(%edi) )
28893
28894 SRC( movl 8(%esi), %ebx )
28895 SRC( movl 12(%esi), %edx )
28896 adcl %ebx, %eax
28897-DST( movl %ebx, 8(%edi) )
28898+DST( movl %ebx, %es:8(%edi) )
28899 adcl %edx, %eax
28900-DST( movl %edx, 12(%edi) )
28901+DST( movl %edx, %es:12(%edi) )
28902
28903 SRC( movl 16(%esi), %ebx )
28904 SRC( movl 20(%esi), %edx )
28905 adcl %ebx, %eax
28906-DST( movl %ebx, 16(%edi) )
28907+DST( movl %ebx, %es:16(%edi) )
28908 adcl %edx, %eax
28909-DST( movl %edx, 20(%edi) )
28910+DST( movl %edx, %es:20(%edi) )
28911
28912 SRC( movl 24(%esi), %ebx )
28913 SRC( movl 28(%esi), %edx )
28914 adcl %ebx, %eax
28915-DST( movl %ebx, 24(%edi) )
28916+DST( movl %ebx, %es:24(%edi) )
28917 adcl %edx, %eax
28918-DST( movl %edx, 28(%edi) )
28919+DST( movl %edx, %es:28(%edi) )
28920
28921 lea 32(%esi), %esi
28922 lea 32(%edi), %edi
28923@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
28924 shrl $2, %edx # This clears CF
28925 SRC(3: movl (%esi), %ebx )
28926 adcl %ebx, %eax
28927-DST( movl %ebx, (%edi) )
28928+DST( movl %ebx, %es:(%edi) )
28929 lea 4(%esi), %esi
28930 lea 4(%edi), %edi
28931 dec %edx
28932@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
28933 jb 5f
28934 SRC( movw (%esi), %cx )
28935 leal 2(%esi), %esi
28936-DST( movw %cx, (%edi) )
28937+DST( movw %cx, %es:(%edi) )
28938 leal 2(%edi), %edi
28939 je 6f
28940 shll $16,%ecx
28941 SRC(5: movb (%esi), %cl )
28942-DST( movb %cl, (%edi) )
28943+DST( movb %cl, %es:(%edi) )
28944 6: addl %ecx, %eax
28945 adcl $0, %eax
28946 7:
28947@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
28948
28949 6001:
28950 movl ARGBASE+20(%esp), %ebx # src_err_ptr
28951- movl $-EFAULT, (%ebx)
28952+ movl $-EFAULT, %ss:(%ebx)
28953
28954 # zero the complete destination - computing the rest
28955 # is too much work
28956@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
28957
28958 6002:
28959 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28960- movl $-EFAULT,(%ebx)
28961+ movl $-EFAULT,%ss:(%ebx)
28962 jmp 5000b
28963
28964 .previous
28965
28966+ pushl_cfi %ss
28967+ popl_cfi %ds
28968+ pushl_cfi %ss
28969+ popl_cfi %es
28970 popl_cfi %ebx
28971 CFI_RESTORE ebx
28972 popl_cfi %esi
28973@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
28974 popl_cfi %ecx # equivalent to addl $4,%esp
28975 ret
28976 CFI_ENDPROC
28977-ENDPROC(csum_partial_copy_generic)
28978+ENDPROC(csum_partial_copy_generic_to_user)
28979
28980 #else
28981
28982 /* Version for PentiumII/PPro */
28983
28984 #define ROUND1(x) \
28985+ nop; nop; nop; \
28986 SRC(movl x(%esi), %ebx ) ; \
28987 addl %ebx, %eax ; \
28988- DST(movl %ebx, x(%edi) ) ;
28989+ DST(movl %ebx, %es:x(%edi)) ;
28990
28991 #define ROUND(x) \
28992+ nop; nop; nop; \
28993 SRC(movl x(%esi), %ebx ) ; \
28994 adcl %ebx, %eax ; \
28995- DST(movl %ebx, x(%edi) ) ;
28996+ DST(movl %ebx, %es:x(%edi)) ;
28997
28998 #define ARGBASE 12
28999-
29000-ENTRY(csum_partial_copy_generic)
29001+
29002+ENTRY(csum_partial_copy_generic_to_user)
29003 CFI_STARTPROC
29004+
29005+#ifdef CONFIG_PAX_MEMORY_UDEREF
29006+ pushl_cfi %gs
29007+ popl_cfi %es
29008+ jmp csum_partial_copy_generic
29009+#endif
29010+
29011+ENTRY(csum_partial_copy_generic_from_user)
29012+
29013+#ifdef CONFIG_PAX_MEMORY_UDEREF
29014+ pushl_cfi %gs
29015+ popl_cfi %ds
29016+#endif
29017+
29018+ENTRY(csum_partial_copy_generic)
29019 pushl_cfi %ebx
29020 CFI_REL_OFFSET ebx, 0
29021 pushl_cfi %edi
29022@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29023 subl %ebx, %edi
29024 lea -1(%esi),%edx
29025 andl $-32,%edx
29026- lea 3f(%ebx,%ebx), %ebx
29027+ lea 3f(%ebx,%ebx,2), %ebx
29028 testl %esi, %esi
29029 jmp *%ebx
29030 1: addl $64,%esi
29031@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29032 jb 5f
29033 SRC( movw (%esi), %dx )
29034 leal 2(%esi), %esi
29035-DST( movw %dx, (%edi) )
29036+DST( movw %dx, %es:(%edi) )
29037 leal 2(%edi), %edi
29038 je 6f
29039 shll $16,%edx
29040 5:
29041 SRC( movb (%esi), %dl )
29042-DST( movb %dl, (%edi) )
29043+DST( movb %dl, %es:(%edi) )
29044 6: addl %edx, %eax
29045 adcl $0, %eax
29046 7:
29047 .section .fixup, "ax"
29048 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29049- movl $-EFAULT, (%ebx)
29050+ movl $-EFAULT, %ss:(%ebx)
29051 # zero the complete destination (computing the rest is too much work)
29052 movl ARGBASE+8(%esp),%edi # dst
29053 movl ARGBASE+12(%esp),%ecx # len
29054@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29055 rep; stosb
29056 jmp 7b
29057 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29058- movl $-EFAULT, (%ebx)
29059+ movl $-EFAULT, %ss:(%ebx)
29060 jmp 7b
29061 .previous
29062
29063+#ifdef CONFIG_PAX_MEMORY_UDEREF
29064+ pushl_cfi %ss
29065+ popl_cfi %ds
29066+ pushl_cfi %ss
29067+ popl_cfi %es
29068+#endif
29069+
29070 popl_cfi %esi
29071 CFI_RESTORE esi
29072 popl_cfi %edi
29073@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29074 CFI_RESTORE ebx
29075 ret
29076 CFI_ENDPROC
29077-ENDPROC(csum_partial_copy_generic)
29078+ENDPROC(csum_partial_copy_generic_to_user)
29079
29080 #undef ROUND
29081 #undef ROUND1
29082diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29083index f2145cf..cea889d 100644
29084--- a/arch/x86/lib/clear_page_64.S
29085+++ b/arch/x86/lib/clear_page_64.S
29086@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29087 movl $4096/8,%ecx
29088 xorl %eax,%eax
29089 rep stosq
29090+ pax_force_retaddr
29091 ret
29092 CFI_ENDPROC
29093 ENDPROC(clear_page_c)
29094@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29095 movl $4096,%ecx
29096 xorl %eax,%eax
29097 rep stosb
29098+ pax_force_retaddr
29099 ret
29100 CFI_ENDPROC
29101 ENDPROC(clear_page_c_e)
29102@@ -43,6 +45,7 @@ ENTRY(clear_page)
29103 leaq 64(%rdi),%rdi
29104 jnz .Lloop
29105 nop
29106+ pax_force_retaddr
29107 ret
29108 CFI_ENDPROC
29109 .Lclear_page_end:
29110@@ -58,7 +61,7 @@ ENDPROC(clear_page)
29111
29112 #include <asm/cpufeature.h>
29113
29114- .section .altinstr_replacement,"ax"
29115+ .section .altinstr_replacement,"a"
29116 1: .byte 0xeb /* jmp <disp8> */
29117 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29118 2: .byte 0xeb /* jmp <disp8> */
29119diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29120index 1e572c5..2a162cd 100644
29121--- a/arch/x86/lib/cmpxchg16b_emu.S
29122+++ b/arch/x86/lib/cmpxchg16b_emu.S
29123@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29124
29125 popf
29126 mov $1, %al
29127+ pax_force_retaddr
29128 ret
29129
29130 not_same:
29131 popf
29132 xor %al,%al
29133+ pax_force_retaddr
29134 ret
29135
29136 CFI_ENDPROC
29137diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29138index 176cca6..e0d658e 100644
29139--- a/arch/x86/lib/copy_page_64.S
29140+++ b/arch/x86/lib/copy_page_64.S
29141@@ -9,6 +9,7 @@ copy_page_rep:
29142 CFI_STARTPROC
29143 movl $4096/8, %ecx
29144 rep movsq
29145+ pax_force_retaddr
29146 ret
29147 CFI_ENDPROC
29148 ENDPROC(copy_page_rep)
29149@@ -24,8 +25,8 @@ ENTRY(copy_page)
29150 CFI_ADJUST_CFA_OFFSET 2*8
29151 movq %rbx, (%rsp)
29152 CFI_REL_OFFSET rbx, 0
29153- movq %r12, 1*8(%rsp)
29154- CFI_REL_OFFSET r12, 1*8
29155+ movq %r13, 1*8(%rsp)
29156+ CFI_REL_OFFSET r13, 1*8
29157
29158 movl $(4096/64)-5, %ecx
29159 .p2align 4
29160@@ -38,7 +39,7 @@ ENTRY(copy_page)
29161 movq 0x8*4(%rsi), %r9
29162 movq 0x8*5(%rsi), %r10
29163 movq 0x8*6(%rsi), %r11
29164- movq 0x8*7(%rsi), %r12
29165+ movq 0x8*7(%rsi), %r13
29166
29167 prefetcht0 5*64(%rsi)
29168
29169@@ -49,7 +50,7 @@ ENTRY(copy_page)
29170 movq %r9, 0x8*4(%rdi)
29171 movq %r10, 0x8*5(%rdi)
29172 movq %r11, 0x8*6(%rdi)
29173- movq %r12, 0x8*7(%rdi)
29174+ movq %r13, 0x8*7(%rdi)
29175
29176 leaq 64 (%rsi), %rsi
29177 leaq 64 (%rdi), %rdi
29178@@ -68,7 +69,7 @@ ENTRY(copy_page)
29179 movq 0x8*4(%rsi), %r9
29180 movq 0x8*5(%rsi), %r10
29181 movq 0x8*6(%rsi), %r11
29182- movq 0x8*7(%rsi), %r12
29183+ movq 0x8*7(%rsi), %r13
29184
29185 movq %rax, 0x8*0(%rdi)
29186 movq %rbx, 0x8*1(%rdi)
29187@@ -77,7 +78,7 @@ ENTRY(copy_page)
29188 movq %r9, 0x8*4(%rdi)
29189 movq %r10, 0x8*5(%rdi)
29190 movq %r11, 0x8*6(%rdi)
29191- movq %r12, 0x8*7(%rdi)
29192+ movq %r13, 0x8*7(%rdi)
29193
29194 leaq 64(%rdi), %rdi
29195 leaq 64(%rsi), %rsi
29196@@ -85,10 +86,11 @@ ENTRY(copy_page)
29197
29198 movq (%rsp), %rbx
29199 CFI_RESTORE rbx
29200- movq 1*8(%rsp), %r12
29201- CFI_RESTORE r12
29202+ movq 1*8(%rsp), %r13
29203+ CFI_RESTORE r13
29204 addq $2*8, %rsp
29205 CFI_ADJUST_CFA_OFFSET -2*8
29206+ pax_force_retaddr
29207 ret
29208 .Lcopy_page_end:
29209 CFI_ENDPROC
29210@@ -99,7 +101,7 @@ ENDPROC(copy_page)
29211
29212 #include <asm/cpufeature.h>
29213
29214- .section .altinstr_replacement,"ax"
29215+ .section .altinstr_replacement,"a"
29216 1: .byte 0xeb /* jmp <disp8> */
29217 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29218 2:
29219diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29220index a30ca15..407412b 100644
29221--- a/arch/x86/lib/copy_user_64.S
29222+++ b/arch/x86/lib/copy_user_64.S
29223@@ -18,31 +18,7 @@
29224 #include <asm/alternative-asm.h>
29225 #include <asm/asm.h>
29226 #include <asm/smap.h>
29227-
29228-/*
29229- * By placing feature2 after feature1 in altinstructions section, we logically
29230- * implement:
29231- * If CPU has feature2, jmp to alt2 is used
29232- * else if CPU has feature1, jmp to alt1 is used
29233- * else jmp to orig is used.
29234- */
29235- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29236-0:
29237- .byte 0xe9 /* 32bit jump */
29238- .long \orig-1f /* by default jump to orig */
29239-1:
29240- .section .altinstr_replacement,"ax"
29241-2: .byte 0xe9 /* near jump with 32bit immediate */
29242- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29243-3: .byte 0xe9 /* near jump with 32bit immediate */
29244- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29245- .previous
29246-
29247- .section .altinstructions,"a"
29248- altinstruction_entry 0b,2b,\feature1,5,5
29249- altinstruction_entry 0b,3b,\feature2,5,5
29250- .previous
29251- .endm
29252+#include <asm/pgtable.h>
29253
29254 .macro ALIGN_DESTINATION
29255 #ifdef FIX_ALIGNMENT
29256@@ -70,52 +46,6 @@
29257 #endif
29258 .endm
29259
29260-/* Standard copy_to_user with segment limit checking */
29261-ENTRY(_copy_to_user)
29262- CFI_STARTPROC
29263- GET_THREAD_INFO(%rax)
29264- movq %rdi,%rcx
29265- addq %rdx,%rcx
29266- jc bad_to_user
29267- cmpq TI_addr_limit(%rax),%rcx
29268- ja bad_to_user
29269- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29270- copy_user_generic_unrolled,copy_user_generic_string, \
29271- copy_user_enhanced_fast_string
29272- CFI_ENDPROC
29273-ENDPROC(_copy_to_user)
29274-
29275-/* Standard copy_from_user with segment limit checking */
29276-ENTRY(_copy_from_user)
29277- CFI_STARTPROC
29278- GET_THREAD_INFO(%rax)
29279- movq %rsi,%rcx
29280- addq %rdx,%rcx
29281- jc bad_from_user
29282- cmpq TI_addr_limit(%rax),%rcx
29283- ja bad_from_user
29284- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29285- copy_user_generic_unrolled,copy_user_generic_string, \
29286- copy_user_enhanced_fast_string
29287- CFI_ENDPROC
29288-ENDPROC(_copy_from_user)
29289-
29290- .section .fixup,"ax"
29291- /* must zero dest */
29292-ENTRY(bad_from_user)
29293-bad_from_user:
29294- CFI_STARTPROC
29295- movl %edx,%ecx
29296- xorl %eax,%eax
29297- rep
29298- stosb
29299-bad_to_user:
29300- movl %edx,%eax
29301- ret
29302- CFI_ENDPROC
29303-ENDPROC(bad_from_user)
29304- .previous
29305-
29306 /*
29307 * copy_user_generic_unrolled - memory copy with exception handling.
29308 * This version is for CPUs like P4 that don't have efficient micro
29309@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29310 */
29311 ENTRY(copy_user_generic_unrolled)
29312 CFI_STARTPROC
29313+ ASM_PAX_OPEN_USERLAND
29314 ASM_STAC
29315 cmpl $8,%edx
29316 jb 20f /* less then 8 bytes, go to byte copy loop */
29317@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29318 jnz 21b
29319 23: xor %eax,%eax
29320 ASM_CLAC
29321+ ASM_PAX_CLOSE_USERLAND
29322+ pax_force_retaddr
29323 ret
29324
29325 .section .fixup,"ax"
29326@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29327 */
29328 ENTRY(copy_user_generic_string)
29329 CFI_STARTPROC
29330+ ASM_PAX_OPEN_USERLAND
29331 ASM_STAC
29332 andl %edx,%edx
29333 jz 4f
29334@@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
29335 movsb
29336 4: xorl %eax,%eax
29337 ASM_CLAC
29338+ ASM_PAX_CLOSE_USERLAND
29339+ pax_force_retaddr
29340 ret
29341
29342 .section .fixup,"ax"
29343@@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
29344 */
29345 ENTRY(copy_user_enhanced_fast_string)
29346 CFI_STARTPROC
29347+ ASM_PAX_OPEN_USERLAND
29348 ASM_STAC
29349 andl %edx,%edx
29350 jz 2f
29351@@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
29352 movsb
29353 2: xorl %eax,%eax
29354 ASM_CLAC
29355+ ASM_PAX_CLOSE_USERLAND
29356+ pax_force_retaddr
29357 ret
29358
29359 .section .fixup,"ax"
29360diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29361index 6a4f43c..c70fb52 100644
29362--- a/arch/x86/lib/copy_user_nocache_64.S
29363+++ b/arch/x86/lib/copy_user_nocache_64.S
29364@@ -8,6 +8,7 @@
29365
29366 #include <linux/linkage.h>
29367 #include <asm/dwarf2.h>
29368+#include <asm/alternative-asm.h>
29369
29370 #define FIX_ALIGNMENT 1
29371
29372@@ -16,6 +17,7 @@
29373 #include <asm/thread_info.h>
29374 #include <asm/asm.h>
29375 #include <asm/smap.h>
29376+#include <asm/pgtable.h>
29377
29378 .macro ALIGN_DESTINATION
29379 #ifdef FIX_ALIGNMENT
29380@@ -49,6 +51,16 @@
29381 */
29382 ENTRY(__copy_user_nocache)
29383 CFI_STARTPROC
29384+
29385+#ifdef CONFIG_PAX_MEMORY_UDEREF
29386+ mov pax_user_shadow_base,%rcx
29387+ cmp %rcx,%rsi
29388+ jae 1f
29389+ add %rcx,%rsi
29390+1:
29391+#endif
29392+
29393+ ASM_PAX_OPEN_USERLAND
29394 ASM_STAC
29395 cmpl $8,%edx
29396 jb 20f /* less then 8 bytes, go to byte copy loop */
29397@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29398 jnz 21b
29399 23: xorl %eax,%eax
29400 ASM_CLAC
29401+ ASM_PAX_CLOSE_USERLAND
29402 sfence
29403+ pax_force_retaddr
29404 ret
29405
29406 .section .fixup,"ax"
29407diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29408index 2419d5f..fe52d0e 100644
29409--- a/arch/x86/lib/csum-copy_64.S
29410+++ b/arch/x86/lib/csum-copy_64.S
29411@@ -9,6 +9,7 @@
29412 #include <asm/dwarf2.h>
29413 #include <asm/errno.h>
29414 #include <asm/asm.h>
29415+#include <asm/alternative-asm.h>
29416
29417 /*
29418 * Checksum copy with exception handling.
29419@@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
29420 CFI_ADJUST_CFA_OFFSET 7*8
29421 movq %rbx, 2*8(%rsp)
29422 CFI_REL_OFFSET rbx, 2*8
29423- movq %r12, 3*8(%rsp)
29424- CFI_REL_OFFSET r12, 3*8
29425+ movq %r15, 3*8(%rsp)
29426+ CFI_REL_OFFSET r15, 3*8
29427 movq %r14, 4*8(%rsp)
29428 CFI_REL_OFFSET r14, 4*8
29429 movq %r13, 5*8(%rsp)
29430@@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
29431 movl %edx, %ecx
29432
29433 xorl %r9d, %r9d
29434- movq %rcx, %r12
29435+ movq %rcx, %r15
29436
29437- shrq $6, %r12
29438+ shrq $6, %r15
29439 jz .Lhandle_tail /* < 64 */
29440
29441 clc
29442
29443 /* main loop. clear in 64 byte blocks */
29444 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
29445- /* r11: temp3, rdx: temp4, r12 loopcnt */
29446+ /* r11: temp3, rdx: temp4, r15 loopcnt */
29447 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
29448 .p2align 4
29449 .Lloop:
29450@@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
29451 adcq %r14, %rax
29452 adcq %r13, %rax
29453
29454- decl %r12d
29455+ decl %r15d
29456
29457 dest
29458 movq %rbx, (%rsi)
29459@@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
29460 .Lende:
29461 movq 2*8(%rsp), %rbx
29462 CFI_RESTORE rbx
29463- movq 3*8(%rsp), %r12
29464- CFI_RESTORE r12
29465+ movq 3*8(%rsp), %r15
29466+ CFI_RESTORE r15
29467 movq 4*8(%rsp), %r14
29468 CFI_RESTORE r14
29469 movq 5*8(%rsp), %r13
29470@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
29471 CFI_RESTORE rbp
29472 addq $7*8, %rsp
29473 CFI_ADJUST_CFA_OFFSET -7*8
29474+ pax_force_retaddr
29475 ret
29476 CFI_RESTORE_STATE
29477
29478diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
29479index 7609e0e..b449b98 100644
29480--- a/arch/x86/lib/csum-wrappers_64.c
29481+++ b/arch/x86/lib/csum-wrappers_64.c
29482@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
29483 len -= 2;
29484 }
29485 }
29486+ pax_open_userland();
29487 stac();
29488- isum = csum_partial_copy_generic((__force const void *)src,
29489+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
29490 dst, len, isum, errp, NULL);
29491 clac();
29492+ pax_close_userland();
29493 if (unlikely(*errp))
29494 goto out_err;
29495
29496@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
29497 }
29498
29499 *errp = 0;
29500+ pax_open_userland();
29501 stac();
29502- ret = csum_partial_copy_generic(src, (void __force *)dst,
29503+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
29504 len, isum, NULL, errp);
29505 clac();
29506+ pax_close_userland();
29507 return ret;
29508 }
29509 EXPORT_SYMBOL(csum_partial_copy_to_user);
29510diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
29511index a451235..1daa956 100644
29512--- a/arch/x86/lib/getuser.S
29513+++ b/arch/x86/lib/getuser.S
29514@@ -33,17 +33,40 @@
29515 #include <asm/thread_info.h>
29516 #include <asm/asm.h>
29517 #include <asm/smap.h>
29518+#include <asm/segment.h>
29519+#include <asm/pgtable.h>
29520+#include <asm/alternative-asm.h>
29521+
29522+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29523+#define __copyuser_seg gs;
29524+#else
29525+#define __copyuser_seg
29526+#endif
29527
29528 .text
29529 ENTRY(__get_user_1)
29530 CFI_STARTPROC
29531+
29532+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29533 GET_THREAD_INFO(%_ASM_DX)
29534 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29535 jae bad_get_user
29536 ASM_STAC
29537-1: movzbl (%_ASM_AX),%edx
29538+
29539+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29540+ mov pax_user_shadow_base,%_ASM_DX
29541+ cmp %_ASM_DX,%_ASM_AX
29542+ jae 1234f
29543+ add %_ASM_DX,%_ASM_AX
29544+1234:
29545+#endif
29546+
29547+#endif
29548+
29549+1: __copyuser_seg movzbl (%_ASM_AX),%edx
29550 xor %eax,%eax
29551 ASM_CLAC
29552+ pax_force_retaddr
29553 ret
29554 CFI_ENDPROC
29555 ENDPROC(__get_user_1)
29556@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
29557 ENTRY(__get_user_2)
29558 CFI_STARTPROC
29559 add $1,%_ASM_AX
29560+
29561+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29562 jc bad_get_user
29563 GET_THREAD_INFO(%_ASM_DX)
29564 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29565 jae bad_get_user
29566 ASM_STAC
29567-2: movzwl -1(%_ASM_AX),%edx
29568+
29569+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29570+ mov pax_user_shadow_base,%_ASM_DX
29571+ cmp %_ASM_DX,%_ASM_AX
29572+ jae 1234f
29573+ add %_ASM_DX,%_ASM_AX
29574+1234:
29575+#endif
29576+
29577+#endif
29578+
29579+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
29580 xor %eax,%eax
29581 ASM_CLAC
29582+ pax_force_retaddr
29583 ret
29584 CFI_ENDPROC
29585 ENDPROC(__get_user_2)
29586@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29587 ENTRY(__get_user_4)
29588 CFI_STARTPROC
29589 add $3,%_ASM_AX
29590+
29591+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29592 jc bad_get_user
29593 GET_THREAD_INFO(%_ASM_DX)
29594 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29595 jae bad_get_user
29596 ASM_STAC
29597-3: movl -3(%_ASM_AX),%edx
29598+
29599+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29600+ mov pax_user_shadow_base,%_ASM_DX
29601+ cmp %_ASM_DX,%_ASM_AX
29602+ jae 1234f
29603+ add %_ASM_DX,%_ASM_AX
29604+1234:
29605+#endif
29606+
29607+#endif
29608+
29609+3: __copyuser_seg movl -3(%_ASM_AX),%edx
29610 xor %eax,%eax
29611 ASM_CLAC
29612+ pax_force_retaddr
29613 ret
29614 CFI_ENDPROC
29615 ENDPROC(__get_user_4)
29616@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29617 GET_THREAD_INFO(%_ASM_DX)
29618 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29619 jae bad_get_user
29620+
29621+#ifdef CONFIG_PAX_MEMORY_UDEREF
29622+ mov pax_user_shadow_base,%_ASM_DX
29623+ cmp %_ASM_DX,%_ASM_AX
29624+ jae 1234f
29625+ add %_ASM_DX,%_ASM_AX
29626+1234:
29627+#endif
29628+
29629 ASM_STAC
29630 4: movq -7(%_ASM_AX),%rdx
29631 xor %eax,%eax
29632 ASM_CLAC
29633+ pax_force_retaddr
29634 ret
29635 #else
29636 add $7,%_ASM_AX
29637@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29638 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29639 jae bad_get_user_8
29640 ASM_STAC
29641-4: movl -7(%_ASM_AX),%edx
29642-5: movl -3(%_ASM_AX),%ecx
29643+4: __copyuser_seg movl -7(%_ASM_AX),%edx
29644+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29645 xor %eax,%eax
29646 ASM_CLAC
29647+ pax_force_retaddr
29648 ret
29649 #endif
29650 CFI_ENDPROC
29651@@ -113,6 +175,7 @@ bad_get_user:
29652 xor %edx,%edx
29653 mov $(-EFAULT),%_ASM_AX
29654 ASM_CLAC
29655+ pax_force_retaddr
29656 ret
29657 CFI_ENDPROC
29658 END(bad_get_user)
29659@@ -124,6 +187,7 @@ bad_get_user_8:
29660 xor %ecx,%ecx
29661 mov $(-EFAULT),%_ASM_AX
29662 ASM_CLAC
29663+ pax_force_retaddr
29664 ret
29665 CFI_ENDPROC
29666 END(bad_get_user_8)
29667diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29668index 54fcffe..7be149e 100644
29669--- a/arch/x86/lib/insn.c
29670+++ b/arch/x86/lib/insn.c
29671@@ -20,8 +20,10 @@
29672
29673 #ifdef __KERNEL__
29674 #include <linux/string.h>
29675+#include <asm/pgtable_types.h>
29676 #else
29677 #include <string.h>
29678+#define ktla_ktva(addr) addr
29679 #endif
29680 #include <asm/inat.h>
29681 #include <asm/insn.h>
29682@@ -53,8 +55,8 @@
29683 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29684 {
29685 memset(insn, 0, sizeof(*insn));
29686- insn->kaddr = kaddr;
29687- insn->next_byte = kaddr;
29688+ insn->kaddr = ktla_ktva(kaddr);
29689+ insn->next_byte = ktla_ktva(kaddr);
29690 insn->x86_64 = x86_64 ? 1 : 0;
29691 insn->opnd_bytes = 4;
29692 if (x86_64)
29693diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29694index 05a95e7..326f2fa 100644
29695--- a/arch/x86/lib/iomap_copy_64.S
29696+++ b/arch/x86/lib/iomap_copy_64.S
29697@@ -17,6 +17,7 @@
29698
29699 #include <linux/linkage.h>
29700 #include <asm/dwarf2.h>
29701+#include <asm/alternative-asm.h>
29702
29703 /*
29704 * override generic version in lib/iomap_copy.c
29705@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29706 CFI_STARTPROC
29707 movl %edx,%ecx
29708 rep movsd
29709+ pax_force_retaddr
29710 ret
29711 CFI_ENDPROC
29712 ENDPROC(__iowrite32_copy)
29713diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29714index 56313a3..0db417e 100644
29715--- a/arch/x86/lib/memcpy_64.S
29716+++ b/arch/x86/lib/memcpy_64.S
29717@@ -24,7 +24,7 @@
29718 * This gets patched over the unrolled variant (below) via the
29719 * alternative instructions framework:
29720 */
29721- .section .altinstr_replacement, "ax", @progbits
29722+ .section .altinstr_replacement, "a", @progbits
29723 .Lmemcpy_c:
29724 movq %rdi, %rax
29725 movq %rdx, %rcx
29726@@ -33,6 +33,7 @@
29727 rep movsq
29728 movl %edx, %ecx
29729 rep movsb
29730+ pax_force_retaddr
29731 ret
29732 .Lmemcpy_e:
29733 .previous
29734@@ -44,11 +45,12 @@
29735 * This gets patched over the unrolled variant (below) via the
29736 * alternative instructions framework:
29737 */
29738- .section .altinstr_replacement, "ax", @progbits
29739+ .section .altinstr_replacement, "a", @progbits
29740 .Lmemcpy_c_e:
29741 movq %rdi, %rax
29742 movq %rdx, %rcx
29743 rep movsb
29744+ pax_force_retaddr
29745 ret
29746 .Lmemcpy_e_e:
29747 .previous
29748@@ -136,6 +138,7 @@ ENTRY(memcpy)
29749 movq %r9, 1*8(%rdi)
29750 movq %r10, -2*8(%rdi, %rdx)
29751 movq %r11, -1*8(%rdi, %rdx)
29752+ pax_force_retaddr
29753 retq
29754 .p2align 4
29755 .Lless_16bytes:
29756@@ -148,6 +151,7 @@ ENTRY(memcpy)
29757 movq -1*8(%rsi, %rdx), %r9
29758 movq %r8, 0*8(%rdi)
29759 movq %r9, -1*8(%rdi, %rdx)
29760+ pax_force_retaddr
29761 retq
29762 .p2align 4
29763 .Lless_8bytes:
29764@@ -161,6 +165,7 @@ ENTRY(memcpy)
29765 movl -4(%rsi, %rdx), %r8d
29766 movl %ecx, (%rdi)
29767 movl %r8d, -4(%rdi, %rdx)
29768+ pax_force_retaddr
29769 retq
29770 .p2align 4
29771 .Lless_3bytes:
29772@@ -179,6 +184,7 @@ ENTRY(memcpy)
29773 movb %cl, (%rdi)
29774
29775 .Lend:
29776+ pax_force_retaddr
29777 retq
29778 CFI_ENDPROC
29779 ENDPROC(memcpy)
29780diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
29781index 65268a6..dd1de11 100644
29782--- a/arch/x86/lib/memmove_64.S
29783+++ b/arch/x86/lib/memmove_64.S
29784@@ -202,14 +202,16 @@ ENTRY(memmove)
29785 movb (%rsi), %r11b
29786 movb %r11b, (%rdi)
29787 13:
29788+ pax_force_retaddr
29789 retq
29790 CFI_ENDPROC
29791
29792- .section .altinstr_replacement,"ax"
29793+ .section .altinstr_replacement,"a"
29794 .Lmemmove_begin_forward_efs:
29795 /* Forward moving data. */
29796 movq %rdx, %rcx
29797 rep movsb
29798+ pax_force_retaddr
29799 retq
29800 .Lmemmove_end_forward_efs:
29801 .previous
29802diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
29803index 2dcb380..2eb79fe 100644
29804--- a/arch/x86/lib/memset_64.S
29805+++ b/arch/x86/lib/memset_64.S
29806@@ -16,7 +16,7 @@
29807 *
29808 * rax original destination
29809 */
29810- .section .altinstr_replacement, "ax", @progbits
29811+ .section .altinstr_replacement, "a", @progbits
29812 .Lmemset_c:
29813 movq %rdi,%r9
29814 movq %rdx,%rcx
29815@@ -30,6 +30,7 @@
29816 movl %edx,%ecx
29817 rep stosb
29818 movq %r9,%rax
29819+ pax_force_retaddr
29820 ret
29821 .Lmemset_e:
29822 .previous
29823@@ -45,13 +46,14 @@
29824 *
29825 * rax original destination
29826 */
29827- .section .altinstr_replacement, "ax", @progbits
29828+ .section .altinstr_replacement, "a", @progbits
29829 .Lmemset_c_e:
29830 movq %rdi,%r9
29831 movb %sil,%al
29832 movq %rdx,%rcx
29833 rep stosb
29834 movq %r9,%rax
29835+ pax_force_retaddr
29836 ret
29837 .Lmemset_e_e:
29838 .previous
29839@@ -118,6 +120,7 @@ ENTRY(__memset)
29840
29841 .Lende:
29842 movq %r10,%rax
29843+ pax_force_retaddr
29844 ret
29845
29846 CFI_RESTORE_STATE
29847diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
29848index c9f2d9b..e7fd2c0 100644
29849--- a/arch/x86/lib/mmx_32.c
29850+++ b/arch/x86/lib/mmx_32.c
29851@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29852 {
29853 void *p;
29854 int i;
29855+ unsigned long cr0;
29856
29857 if (unlikely(in_interrupt()))
29858 return __memcpy(to, from, len);
29859@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29860 kernel_fpu_begin();
29861
29862 __asm__ __volatile__ (
29863- "1: prefetch (%0)\n" /* This set is 28 bytes */
29864- " prefetch 64(%0)\n"
29865- " prefetch 128(%0)\n"
29866- " prefetch 192(%0)\n"
29867- " prefetch 256(%0)\n"
29868+ "1: prefetch (%1)\n" /* This set is 28 bytes */
29869+ " prefetch 64(%1)\n"
29870+ " prefetch 128(%1)\n"
29871+ " prefetch 192(%1)\n"
29872+ " prefetch 256(%1)\n"
29873 "2: \n"
29874 ".section .fixup, \"ax\"\n"
29875- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29876+ "3: \n"
29877+
29878+#ifdef CONFIG_PAX_KERNEXEC
29879+ " movl %%cr0, %0\n"
29880+ " movl %0, %%eax\n"
29881+ " andl $0xFFFEFFFF, %%eax\n"
29882+ " movl %%eax, %%cr0\n"
29883+#endif
29884+
29885+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29886+
29887+#ifdef CONFIG_PAX_KERNEXEC
29888+ " movl %0, %%cr0\n"
29889+#endif
29890+
29891 " jmp 2b\n"
29892 ".previous\n"
29893 _ASM_EXTABLE(1b, 3b)
29894- : : "r" (from));
29895+ : "=&r" (cr0) : "r" (from) : "ax");
29896
29897 for ( ; i > 5; i--) {
29898 __asm__ __volatile__ (
29899- "1: prefetch 320(%0)\n"
29900- "2: movq (%0), %%mm0\n"
29901- " movq 8(%0), %%mm1\n"
29902- " movq 16(%0), %%mm2\n"
29903- " movq 24(%0), %%mm3\n"
29904- " movq %%mm0, (%1)\n"
29905- " movq %%mm1, 8(%1)\n"
29906- " movq %%mm2, 16(%1)\n"
29907- " movq %%mm3, 24(%1)\n"
29908- " movq 32(%0), %%mm0\n"
29909- " movq 40(%0), %%mm1\n"
29910- " movq 48(%0), %%mm2\n"
29911- " movq 56(%0), %%mm3\n"
29912- " movq %%mm0, 32(%1)\n"
29913- " movq %%mm1, 40(%1)\n"
29914- " movq %%mm2, 48(%1)\n"
29915- " movq %%mm3, 56(%1)\n"
29916+ "1: prefetch 320(%1)\n"
29917+ "2: movq (%1), %%mm0\n"
29918+ " movq 8(%1), %%mm1\n"
29919+ " movq 16(%1), %%mm2\n"
29920+ " movq 24(%1), %%mm3\n"
29921+ " movq %%mm0, (%2)\n"
29922+ " movq %%mm1, 8(%2)\n"
29923+ " movq %%mm2, 16(%2)\n"
29924+ " movq %%mm3, 24(%2)\n"
29925+ " movq 32(%1), %%mm0\n"
29926+ " movq 40(%1), %%mm1\n"
29927+ " movq 48(%1), %%mm2\n"
29928+ " movq 56(%1), %%mm3\n"
29929+ " movq %%mm0, 32(%2)\n"
29930+ " movq %%mm1, 40(%2)\n"
29931+ " movq %%mm2, 48(%2)\n"
29932+ " movq %%mm3, 56(%2)\n"
29933 ".section .fixup, \"ax\"\n"
29934- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29935+ "3:\n"
29936+
29937+#ifdef CONFIG_PAX_KERNEXEC
29938+ " movl %%cr0, %0\n"
29939+ " movl %0, %%eax\n"
29940+ " andl $0xFFFEFFFF, %%eax\n"
29941+ " movl %%eax, %%cr0\n"
29942+#endif
29943+
29944+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29945+
29946+#ifdef CONFIG_PAX_KERNEXEC
29947+ " movl %0, %%cr0\n"
29948+#endif
29949+
29950 " jmp 2b\n"
29951 ".previous\n"
29952 _ASM_EXTABLE(1b, 3b)
29953- : : "r" (from), "r" (to) : "memory");
29954+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29955
29956 from += 64;
29957 to += 64;
29958@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
29959 static void fast_copy_page(void *to, void *from)
29960 {
29961 int i;
29962+ unsigned long cr0;
29963
29964 kernel_fpu_begin();
29965
29966@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
29967 * but that is for later. -AV
29968 */
29969 __asm__ __volatile__(
29970- "1: prefetch (%0)\n"
29971- " prefetch 64(%0)\n"
29972- " prefetch 128(%0)\n"
29973- " prefetch 192(%0)\n"
29974- " prefetch 256(%0)\n"
29975+ "1: prefetch (%1)\n"
29976+ " prefetch 64(%1)\n"
29977+ " prefetch 128(%1)\n"
29978+ " prefetch 192(%1)\n"
29979+ " prefetch 256(%1)\n"
29980 "2: \n"
29981 ".section .fixup, \"ax\"\n"
29982- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29983+ "3: \n"
29984+
29985+#ifdef CONFIG_PAX_KERNEXEC
29986+ " movl %%cr0, %0\n"
29987+ " movl %0, %%eax\n"
29988+ " andl $0xFFFEFFFF, %%eax\n"
29989+ " movl %%eax, %%cr0\n"
29990+#endif
29991+
29992+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29993+
29994+#ifdef CONFIG_PAX_KERNEXEC
29995+ " movl %0, %%cr0\n"
29996+#endif
29997+
29998 " jmp 2b\n"
29999 ".previous\n"
30000- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30001+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30002
30003 for (i = 0; i < (4096-320)/64; i++) {
30004 __asm__ __volatile__ (
30005- "1: prefetch 320(%0)\n"
30006- "2: movq (%0), %%mm0\n"
30007- " movntq %%mm0, (%1)\n"
30008- " movq 8(%0), %%mm1\n"
30009- " movntq %%mm1, 8(%1)\n"
30010- " movq 16(%0), %%mm2\n"
30011- " movntq %%mm2, 16(%1)\n"
30012- " movq 24(%0), %%mm3\n"
30013- " movntq %%mm3, 24(%1)\n"
30014- " movq 32(%0), %%mm4\n"
30015- " movntq %%mm4, 32(%1)\n"
30016- " movq 40(%0), %%mm5\n"
30017- " movntq %%mm5, 40(%1)\n"
30018- " movq 48(%0), %%mm6\n"
30019- " movntq %%mm6, 48(%1)\n"
30020- " movq 56(%0), %%mm7\n"
30021- " movntq %%mm7, 56(%1)\n"
30022+ "1: prefetch 320(%1)\n"
30023+ "2: movq (%1), %%mm0\n"
30024+ " movntq %%mm0, (%2)\n"
30025+ " movq 8(%1), %%mm1\n"
30026+ " movntq %%mm1, 8(%2)\n"
30027+ " movq 16(%1), %%mm2\n"
30028+ " movntq %%mm2, 16(%2)\n"
30029+ " movq 24(%1), %%mm3\n"
30030+ " movntq %%mm3, 24(%2)\n"
30031+ " movq 32(%1), %%mm4\n"
30032+ " movntq %%mm4, 32(%2)\n"
30033+ " movq 40(%1), %%mm5\n"
30034+ " movntq %%mm5, 40(%2)\n"
30035+ " movq 48(%1), %%mm6\n"
30036+ " movntq %%mm6, 48(%2)\n"
30037+ " movq 56(%1), %%mm7\n"
30038+ " movntq %%mm7, 56(%2)\n"
30039 ".section .fixup, \"ax\"\n"
30040- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30041+ "3:\n"
30042+
30043+#ifdef CONFIG_PAX_KERNEXEC
30044+ " movl %%cr0, %0\n"
30045+ " movl %0, %%eax\n"
30046+ " andl $0xFFFEFFFF, %%eax\n"
30047+ " movl %%eax, %%cr0\n"
30048+#endif
30049+
30050+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30051+
30052+#ifdef CONFIG_PAX_KERNEXEC
30053+ " movl %0, %%cr0\n"
30054+#endif
30055+
30056 " jmp 2b\n"
30057 ".previous\n"
30058- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30059+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30060
30061 from += 64;
30062 to += 64;
30063@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30064 static void fast_copy_page(void *to, void *from)
30065 {
30066 int i;
30067+ unsigned long cr0;
30068
30069 kernel_fpu_begin();
30070
30071 __asm__ __volatile__ (
30072- "1: prefetch (%0)\n"
30073- " prefetch 64(%0)\n"
30074- " prefetch 128(%0)\n"
30075- " prefetch 192(%0)\n"
30076- " prefetch 256(%0)\n"
30077+ "1: prefetch (%1)\n"
30078+ " prefetch 64(%1)\n"
30079+ " prefetch 128(%1)\n"
30080+ " prefetch 192(%1)\n"
30081+ " prefetch 256(%1)\n"
30082 "2: \n"
30083 ".section .fixup, \"ax\"\n"
30084- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30085+ "3: \n"
30086+
30087+#ifdef CONFIG_PAX_KERNEXEC
30088+ " movl %%cr0, %0\n"
30089+ " movl %0, %%eax\n"
30090+ " andl $0xFFFEFFFF, %%eax\n"
30091+ " movl %%eax, %%cr0\n"
30092+#endif
30093+
30094+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30095+
30096+#ifdef CONFIG_PAX_KERNEXEC
30097+ " movl %0, %%cr0\n"
30098+#endif
30099+
30100 " jmp 2b\n"
30101 ".previous\n"
30102- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30103+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30104
30105 for (i = 0; i < 4096/64; i++) {
30106 __asm__ __volatile__ (
30107- "1: prefetch 320(%0)\n"
30108- "2: movq (%0), %%mm0\n"
30109- " movq 8(%0), %%mm1\n"
30110- " movq 16(%0), %%mm2\n"
30111- " movq 24(%0), %%mm3\n"
30112- " movq %%mm0, (%1)\n"
30113- " movq %%mm1, 8(%1)\n"
30114- " movq %%mm2, 16(%1)\n"
30115- " movq %%mm3, 24(%1)\n"
30116- " movq 32(%0), %%mm0\n"
30117- " movq 40(%0), %%mm1\n"
30118- " movq 48(%0), %%mm2\n"
30119- " movq 56(%0), %%mm3\n"
30120- " movq %%mm0, 32(%1)\n"
30121- " movq %%mm1, 40(%1)\n"
30122- " movq %%mm2, 48(%1)\n"
30123- " movq %%mm3, 56(%1)\n"
30124+ "1: prefetch 320(%1)\n"
30125+ "2: movq (%1), %%mm0\n"
30126+ " movq 8(%1), %%mm1\n"
30127+ " movq 16(%1), %%mm2\n"
30128+ " movq 24(%1), %%mm3\n"
30129+ " movq %%mm0, (%2)\n"
30130+ " movq %%mm1, 8(%2)\n"
30131+ " movq %%mm2, 16(%2)\n"
30132+ " movq %%mm3, 24(%2)\n"
30133+ " movq 32(%1), %%mm0\n"
30134+ " movq 40(%1), %%mm1\n"
30135+ " movq 48(%1), %%mm2\n"
30136+ " movq 56(%1), %%mm3\n"
30137+ " movq %%mm0, 32(%2)\n"
30138+ " movq %%mm1, 40(%2)\n"
30139+ " movq %%mm2, 48(%2)\n"
30140+ " movq %%mm3, 56(%2)\n"
30141 ".section .fixup, \"ax\"\n"
30142- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30143+ "3:\n"
30144+
30145+#ifdef CONFIG_PAX_KERNEXEC
30146+ " movl %%cr0, %0\n"
30147+ " movl %0, %%eax\n"
30148+ " andl $0xFFFEFFFF, %%eax\n"
30149+ " movl %%eax, %%cr0\n"
30150+#endif
30151+
30152+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30153+
30154+#ifdef CONFIG_PAX_KERNEXEC
30155+ " movl %0, %%cr0\n"
30156+#endif
30157+
30158 " jmp 2b\n"
30159 ".previous\n"
30160 _ASM_EXTABLE(1b, 3b)
30161- : : "r" (from), "r" (to) : "memory");
30162+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30163
30164 from += 64;
30165 to += 64;
30166diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30167index f6d13ee..d789440 100644
30168--- a/arch/x86/lib/msr-reg.S
30169+++ b/arch/x86/lib/msr-reg.S
30170@@ -3,6 +3,7 @@
30171 #include <asm/dwarf2.h>
30172 #include <asm/asm.h>
30173 #include <asm/msr.h>
30174+#include <asm/alternative-asm.h>
30175
30176 #ifdef CONFIG_X86_64
30177 /*
30178@@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30179 movl %edi, 28(%r10)
30180 popq_cfi %rbp
30181 popq_cfi %rbx
30182+ pax_force_retaddr
30183 ret
30184 3:
30185 CFI_RESTORE_STATE
30186diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30187index fc6ba17..d4d989d 100644
30188--- a/arch/x86/lib/putuser.S
30189+++ b/arch/x86/lib/putuser.S
30190@@ -16,7 +16,9 @@
30191 #include <asm/errno.h>
30192 #include <asm/asm.h>
30193 #include <asm/smap.h>
30194-
30195+#include <asm/segment.h>
30196+#include <asm/pgtable.h>
30197+#include <asm/alternative-asm.h>
30198
30199 /*
30200 * __put_user_X
30201@@ -30,57 +32,125 @@
30202 * as they get called from within inline assembly.
30203 */
30204
30205-#define ENTER CFI_STARTPROC ; \
30206- GET_THREAD_INFO(%_ASM_BX)
30207-#define EXIT ASM_CLAC ; \
30208- ret ; \
30209+#define ENTER CFI_STARTPROC
30210+#define EXIT ASM_CLAC ; \
30211+ pax_force_retaddr ; \
30212+ ret ; \
30213 CFI_ENDPROC
30214
30215+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30216+#define _DEST %_ASM_CX,%_ASM_BX
30217+#else
30218+#define _DEST %_ASM_CX
30219+#endif
30220+
30221+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30222+#define __copyuser_seg gs;
30223+#else
30224+#define __copyuser_seg
30225+#endif
30226+
30227 .text
30228 ENTRY(__put_user_1)
30229 ENTER
30230+
30231+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30232+ GET_THREAD_INFO(%_ASM_BX)
30233 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30234 jae bad_put_user
30235 ASM_STAC
30236-1: movb %al,(%_ASM_CX)
30237+
30238+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30239+ mov pax_user_shadow_base,%_ASM_BX
30240+ cmp %_ASM_BX,%_ASM_CX
30241+ jb 1234f
30242+ xor %ebx,%ebx
30243+1234:
30244+#endif
30245+
30246+#endif
30247+
30248+1: __copyuser_seg movb %al,(_DEST)
30249 xor %eax,%eax
30250 EXIT
30251 ENDPROC(__put_user_1)
30252
30253 ENTRY(__put_user_2)
30254 ENTER
30255+
30256+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30257+ GET_THREAD_INFO(%_ASM_BX)
30258 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30259 sub $1,%_ASM_BX
30260 cmp %_ASM_BX,%_ASM_CX
30261 jae bad_put_user
30262 ASM_STAC
30263-2: movw %ax,(%_ASM_CX)
30264+
30265+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30266+ mov pax_user_shadow_base,%_ASM_BX
30267+ cmp %_ASM_BX,%_ASM_CX
30268+ jb 1234f
30269+ xor %ebx,%ebx
30270+1234:
30271+#endif
30272+
30273+#endif
30274+
30275+2: __copyuser_seg movw %ax,(_DEST)
30276 xor %eax,%eax
30277 EXIT
30278 ENDPROC(__put_user_2)
30279
30280 ENTRY(__put_user_4)
30281 ENTER
30282+
30283+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30284+ GET_THREAD_INFO(%_ASM_BX)
30285 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30286 sub $3,%_ASM_BX
30287 cmp %_ASM_BX,%_ASM_CX
30288 jae bad_put_user
30289 ASM_STAC
30290-3: movl %eax,(%_ASM_CX)
30291+
30292+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30293+ mov pax_user_shadow_base,%_ASM_BX
30294+ cmp %_ASM_BX,%_ASM_CX
30295+ jb 1234f
30296+ xor %ebx,%ebx
30297+1234:
30298+#endif
30299+
30300+#endif
30301+
30302+3: __copyuser_seg movl %eax,(_DEST)
30303 xor %eax,%eax
30304 EXIT
30305 ENDPROC(__put_user_4)
30306
30307 ENTRY(__put_user_8)
30308 ENTER
30309+
30310+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30311+ GET_THREAD_INFO(%_ASM_BX)
30312 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30313 sub $7,%_ASM_BX
30314 cmp %_ASM_BX,%_ASM_CX
30315 jae bad_put_user
30316 ASM_STAC
30317-4: mov %_ASM_AX,(%_ASM_CX)
30318+
30319+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30320+ mov pax_user_shadow_base,%_ASM_BX
30321+ cmp %_ASM_BX,%_ASM_CX
30322+ jb 1234f
30323+ xor %ebx,%ebx
30324+1234:
30325+#endif
30326+
30327+#endif
30328+
30329+4: __copyuser_seg mov %_ASM_AX,(_DEST)
30330 #ifdef CONFIG_X86_32
30331-5: movl %edx,4(%_ASM_CX)
30332+5: __copyuser_seg movl %edx,4(_DEST)
30333 #endif
30334 xor %eax,%eax
30335 EXIT
30336diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
30337index 1cad221..de671ee 100644
30338--- a/arch/x86/lib/rwlock.S
30339+++ b/arch/x86/lib/rwlock.S
30340@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
30341 FRAME
30342 0: LOCK_PREFIX
30343 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30344+
30345+#ifdef CONFIG_PAX_REFCOUNT
30346+ jno 1234f
30347+ LOCK_PREFIX
30348+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30349+ int $4
30350+1234:
30351+ _ASM_EXTABLE(1234b, 1234b)
30352+#endif
30353+
30354 1: rep; nop
30355 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
30356 jne 1b
30357 LOCK_PREFIX
30358 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30359+
30360+#ifdef CONFIG_PAX_REFCOUNT
30361+ jno 1234f
30362+ LOCK_PREFIX
30363+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30364+ int $4
30365+1234:
30366+ _ASM_EXTABLE(1234b, 1234b)
30367+#endif
30368+
30369 jnz 0b
30370 ENDFRAME
30371+ pax_force_retaddr
30372 ret
30373 CFI_ENDPROC
30374 END(__write_lock_failed)
30375@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
30376 FRAME
30377 0: LOCK_PREFIX
30378 READ_LOCK_SIZE(inc) (%__lock_ptr)
30379+
30380+#ifdef CONFIG_PAX_REFCOUNT
30381+ jno 1234f
30382+ LOCK_PREFIX
30383+ READ_LOCK_SIZE(dec) (%__lock_ptr)
30384+ int $4
30385+1234:
30386+ _ASM_EXTABLE(1234b, 1234b)
30387+#endif
30388+
30389 1: rep; nop
30390 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
30391 js 1b
30392 LOCK_PREFIX
30393 READ_LOCK_SIZE(dec) (%__lock_ptr)
30394+
30395+#ifdef CONFIG_PAX_REFCOUNT
30396+ jno 1234f
30397+ LOCK_PREFIX
30398+ READ_LOCK_SIZE(inc) (%__lock_ptr)
30399+ int $4
30400+1234:
30401+ _ASM_EXTABLE(1234b, 1234b)
30402+#endif
30403+
30404 js 0b
30405 ENDFRAME
30406+ pax_force_retaddr
30407 ret
30408 CFI_ENDPROC
30409 END(__read_lock_failed)
30410diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30411index 5dff5f0..cadebf4 100644
30412--- a/arch/x86/lib/rwsem.S
30413+++ b/arch/x86/lib/rwsem.S
30414@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30415 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30416 CFI_RESTORE __ASM_REG(dx)
30417 restore_common_regs
30418+ pax_force_retaddr
30419 ret
30420 CFI_ENDPROC
30421 ENDPROC(call_rwsem_down_read_failed)
30422@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30423 movq %rax,%rdi
30424 call rwsem_down_write_failed
30425 restore_common_regs
30426+ pax_force_retaddr
30427 ret
30428 CFI_ENDPROC
30429 ENDPROC(call_rwsem_down_write_failed)
30430@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30431 movq %rax,%rdi
30432 call rwsem_wake
30433 restore_common_regs
30434-1: ret
30435+1: pax_force_retaddr
30436+ ret
30437 CFI_ENDPROC
30438 ENDPROC(call_rwsem_wake)
30439
30440@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30441 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30442 CFI_RESTORE __ASM_REG(dx)
30443 restore_common_regs
30444+ pax_force_retaddr
30445 ret
30446 CFI_ENDPROC
30447 ENDPROC(call_rwsem_downgrade_wake)
30448diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30449index a63efd6..8149fbe 100644
30450--- a/arch/x86/lib/thunk_64.S
30451+++ b/arch/x86/lib/thunk_64.S
30452@@ -8,6 +8,7 @@
30453 #include <linux/linkage.h>
30454 #include <asm/dwarf2.h>
30455 #include <asm/calling.h>
30456+#include <asm/alternative-asm.h>
30457
30458 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30459 .macro THUNK name, func, put_ret_addr_in_rdi=0
30460@@ -15,11 +16,11 @@
30461 \name:
30462 CFI_STARTPROC
30463
30464- /* this one pushes 9 elems, the next one would be %rIP */
30465- SAVE_ARGS
30466+ /* this one pushes 15+1 elems, the next one would be %rIP */
30467+ SAVE_ARGS 8
30468
30469 .if \put_ret_addr_in_rdi
30470- movq_cfi_restore 9*8, rdi
30471+ movq_cfi_restore RIP, rdi
30472 .endif
30473
30474 call \func
30475@@ -38,8 +39,9 @@
30476
30477 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30478 CFI_STARTPROC
30479- SAVE_ARGS
30480+ SAVE_ARGS 8
30481 restore:
30482- RESTORE_ARGS
30483+ RESTORE_ARGS 1,8
30484+ pax_force_retaddr
30485 ret
30486 CFI_ENDPROC
30487diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
30488index e2f5e21..4b22130 100644
30489--- a/arch/x86/lib/usercopy_32.c
30490+++ b/arch/x86/lib/usercopy_32.c
30491@@ -42,11 +42,13 @@ do { \
30492 int __d0; \
30493 might_fault(); \
30494 __asm__ __volatile__( \
30495+ __COPYUSER_SET_ES \
30496 ASM_STAC "\n" \
30497 "0: rep; stosl\n" \
30498 " movl %2,%0\n" \
30499 "1: rep; stosb\n" \
30500 "2: " ASM_CLAC "\n" \
30501+ __COPYUSER_RESTORE_ES \
30502 ".section .fixup,\"ax\"\n" \
30503 "3: lea 0(%2,%0,4),%0\n" \
30504 " jmp 2b\n" \
30505@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
30506
30507 #ifdef CONFIG_X86_INTEL_USERCOPY
30508 static unsigned long
30509-__copy_user_intel(void __user *to, const void *from, unsigned long size)
30510+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
30511 {
30512 int d0, d1;
30513 __asm__ __volatile__(
30514@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30515 " .align 2,0x90\n"
30516 "3: movl 0(%4), %%eax\n"
30517 "4: movl 4(%4), %%edx\n"
30518- "5: movl %%eax, 0(%3)\n"
30519- "6: movl %%edx, 4(%3)\n"
30520+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
30521+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
30522 "7: movl 8(%4), %%eax\n"
30523 "8: movl 12(%4),%%edx\n"
30524- "9: movl %%eax, 8(%3)\n"
30525- "10: movl %%edx, 12(%3)\n"
30526+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
30527+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
30528 "11: movl 16(%4), %%eax\n"
30529 "12: movl 20(%4), %%edx\n"
30530- "13: movl %%eax, 16(%3)\n"
30531- "14: movl %%edx, 20(%3)\n"
30532+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
30533+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30534 "15: movl 24(%4), %%eax\n"
30535 "16: movl 28(%4), %%edx\n"
30536- "17: movl %%eax, 24(%3)\n"
30537- "18: movl %%edx, 28(%3)\n"
30538+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30539+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30540 "19: movl 32(%4), %%eax\n"
30541 "20: movl 36(%4), %%edx\n"
30542- "21: movl %%eax, 32(%3)\n"
30543- "22: movl %%edx, 36(%3)\n"
30544+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30545+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30546 "23: movl 40(%4), %%eax\n"
30547 "24: movl 44(%4), %%edx\n"
30548- "25: movl %%eax, 40(%3)\n"
30549- "26: movl %%edx, 44(%3)\n"
30550+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30551+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30552 "27: movl 48(%4), %%eax\n"
30553 "28: movl 52(%4), %%edx\n"
30554- "29: movl %%eax, 48(%3)\n"
30555- "30: movl %%edx, 52(%3)\n"
30556+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
30557+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
30558 "31: movl 56(%4), %%eax\n"
30559 "32: movl 60(%4), %%edx\n"
30560- "33: movl %%eax, 56(%3)\n"
30561- "34: movl %%edx, 60(%3)\n"
30562+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
30563+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
30564 " addl $-64, %0\n"
30565 " addl $64, %4\n"
30566 " addl $64, %3\n"
30567@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30568 " shrl $2, %0\n"
30569 " andl $3, %%eax\n"
30570 " cld\n"
30571+ __COPYUSER_SET_ES
30572 "99: rep; movsl\n"
30573 "36: movl %%eax, %0\n"
30574 "37: rep; movsb\n"
30575 "100:\n"
30576+ __COPYUSER_RESTORE_ES
30577+ ".section .fixup,\"ax\"\n"
30578+ "101: lea 0(%%eax,%0,4),%0\n"
30579+ " jmp 100b\n"
30580+ ".previous\n"
30581+ _ASM_EXTABLE(1b,100b)
30582+ _ASM_EXTABLE(2b,100b)
30583+ _ASM_EXTABLE(3b,100b)
30584+ _ASM_EXTABLE(4b,100b)
30585+ _ASM_EXTABLE(5b,100b)
30586+ _ASM_EXTABLE(6b,100b)
30587+ _ASM_EXTABLE(7b,100b)
30588+ _ASM_EXTABLE(8b,100b)
30589+ _ASM_EXTABLE(9b,100b)
30590+ _ASM_EXTABLE(10b,100b)
30591+ _ASM_EXTABLE(11b,100b)
30592+ _ASM_EXTABLE(12b,100b)
30593+ _ASM_EXTABLE(13b,100b)
30594+ _ASM_EXTABLE(14b,100b)
30595+ _ASM_EXTABLE(15b,100b)
30596+ _ASM_EXTABLE(16b,100b)
30597+ _ASM_EXTABLE(17b,100b)
30598+ _ASM_EXTABLE(18b,100b)
30599+ _ASM_EXTABLE(19b,100b)
30600+ _ASM_EXTABLE(20b,100b)
30601+ _ASM_EXTABLE(21b,100b)
30602+ _ASM_EXTABLE(22b,100b)
30603+ _ASM_EXTABLE(23b,100b)
30604+ _ASM_EXTABLE(24b,100b)
30605+ _ASM_EXTABLE(25b,100b)
30606+ _ASM_EXTABLE(26b,100b)
30607+ _ASM_EXTABLE(27b,100b)
30608+ _ASM_EXTABLE(28b,100b)
30609+ _ASM_EXTABLE(29b,100b)
30610+ _ASM_EXTABLE(30b,100b)
30611+ _ASM_EXTABLE(31b,100b)
30612+ _ASM_EXTABLE(32b,100b)
30613+ _ASM_EXTABLE(33b,100b)
30614+ _ASM_EXTABLE(34b,100b)
30615+ _ASM_EXTABLE(35b,100b)
30616+ _ASM_EXTABLE(36b,100b)
30617+ _ASM_EXTABLE(37b,100b)
30618+ _ASM_EXTABLE(99b,101b)
30619+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
30620+ : "1"(to), "2"(from), "0"(size)
30621+ : "eax", "edx", "memory");
30622+ return size;
30623+}
30624+
30625+static unsigned long
30626+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30627+{
30628+ int d0, d1;
30629+ __asm__ __volatile__(
30630+ " .align 2,0x90\n"
30631+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30632+ " cmpl $67, %0\n"
30633+ " jbe 3f\n"
30634+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30635+ " .align 2,0x90\n"
30636+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30637+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30638+ "5: movl %%eax, 0(%3)\n"
30639+ "6: movl %%edx, 4(%3)\n"
30640+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30641+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30642+ "9: movl %%eax, 8(%3)\n"
30643+ "10: movl %%edx, 12(%3)\n"
30644+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30645+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30646+ "13: movl %%eax, 16(%3)\n"
30647+ "14: movl %%edx, 20(%3)\n"
30648+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30649+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30650+ "17: movl %%eax, 24(%3)\n"
30651+ "18: movl %%edx, 28(%3)\n"
30652+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30653+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30654+ "21: movl %%eax, 32(%3)\n"
30655+ "22: movl %%edx, 36(%3)\n"
30656+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30657+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30658+ "25: movl %%eax, 40(%3)\n"
30659+ "26: movl %%edx, 44(%3)\n"
30660+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30661+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30662+ "29: movl %%eax, 48(%3)\n"
30663+ "30: movl %%edx, 52(%3)\n"
30664+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30665+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30666+ "33: movl %%eax, 56(%3)\n"
30667+ "34: movl %%edx, 60(%3)\n"
30668+ " addl $-64, %0\n"
30669+ " addl $64, %4\n"
30670+ " addl $64, %3\n"
30671+ " cmpl $63, %0\n"
30672+ " ja 1b\n"
30673+ "35: movl %0, %%eax\n"
30674+ " shrl $2, %0\n"
30675+ " andl $3, %%eax\n"
30676+ " cld\n"
30677+ "99: rep; "__copyuser_seg" movsl\n"
30678+ "36: movl %%eax, %0\n"
30679+ "37: rep; "__copyuser_seg" movsb\n"
30680+ "100:\n"
30681 ".section .fixup,\"ax\"\n"
30682 "101: lea 0(%%eax,%0,4),%0\n"
30683 " jmp 100b\n"
30684@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30685 int d0, d1;
30686 __asm__ __volatile__(
30687 " .align 2,0x90\n"
30688- "0: movl 32(%4), %%eax\n"
30689+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30690 " cmpl $67, %0\n"
30691 " jbe 2f\n"
30692- "1: movl 64(%4), %%eax\n"
30693+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30694 " .align 2,0x90\n"
30695- "2: movl 0(%4), %%eax\n"
30696- "21: movl 4(%4), %%edx\n"
30697+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30698+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30699 " movl %%eax, 0(%3)\n"
30700 " movl %%edx, 4(%3)\n"
30701- "3: movl 8(%4), %%eax\n"
30702- "31: movl 12(%4),%%edx\n"
30703+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30704+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30705 " movl %%eax, 8(%3)\n"
30706 " movl %%edx, 12(%3)\n"
30707- "4: movl 16(%4), %%eax\n"
30708- "41: movl 20(%4), %%edx\n"
30709+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30710+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30711 " movl %%eax, 16(%3)\n"
30712 " movl %%edx, 20(%3)\n"
30713- "10: movl 24(%4), %%eax\n"
30714- "51: movl 28(%4), %%edx\n"
30715+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30716+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30717 " movl %%eax, 24(%3)\n"
30718 " movl %%edx, 28(%3)\n"
30719- "11: movl 32(%4), %%eax\n"
30720- "61: movl 36(%4), %%edx\n"
30721+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30722+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30723 " movl %%eax, 32(%3)\n"
30724 " movl %%edx, 36(%3)\n"
30725- "12: movl 40(%4), %%eax\n"
30726- "71: movl 44(%4), %%edx\n"
30727+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30728+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30729 " movl %%eax, 40(%3)\n"
30730 " movl %%edx, 44(%3)\n"
30731- "13: movl 48(%4), %%eax\n"
30732- "81: movl 52(%4), %%edx\n"
30733+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30734+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30735 " movl %%eax, 48(%3)\n"
30736 " movl %%edx, 52(%3)\n"
30737- "14: movl 56(%4), %%eax\n"
30738- "91: movl 60(%4), %%edx\n"
30739+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30740+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30741 " movl %%eax, 56(%3)\n"
30742 " movl %%edx, 60(%3)\n"
30743 " addl $-64, %0\n"
30744@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30745 " shrl $2, %0\n"
30746 " andl $3, %%eax\n"
30747 " cld\n"
30748- "6: rep; movsl\n"
30749+ "6: rep; "__copyuser_seg" movsl\n"
30750 " movl %%eax,%0\n"
30751- "7: rep; movsb\n"
30752+ "7: rep; "__copyuser_seg" movsb\n"
30753 "8:\n"
30754 ".section .fixup,\"ax\"\n"
30755 "9: lea 0(%%eax,%0,4),%0\n"
30756@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30757
30758 __asm__ __volatile__(
30759 " .align 2,0x90\n"
30760- "0: movl 32(%4), %%eax\n"
30761+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30762 " cmpl $67, %0\n"
30763 " jbe 2f\n"
30764- "1: movl 64(%4), %%eax\n"
30765+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30766 " .align 2,0x90\n"
30767- "2: movl 0(%4), %%eax\n"
30768- "21: movl 4(%4), %%edx\n"
30769+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30770+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30771 " movnti %%eax, 0(%3)\n"
30772 " movnti %%edx, 4(%3)\n"
30773- "3: movl 8(%4), %%eax\n"
30774- "31: movl 12(%4),%%edx\n"
30775+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30776+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30777 " movnti %%eax, 8(%3)\n"
30778 " movnti %%edx, 12(%3)\n"
30779- "4: movl 16(%4), %%eax\n"
30780- "41: movl 20(%4), %%edx\n"
30781+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30782+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30783 " movnti %%eax, 16(%3)\n"
30784 " movnti %%edx, 20(%3)\n"
30785- "10: movl 24(%4), %%eax\n"
30786- "51: movl 28(%4), %%edx\n"
30787+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30788+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30789 " movnti %%eax, 24(%3)\n"
30790 " movnti %%edx, 28(%3)\n"
30791- "11: movl 32(%4), %%eax\n"
30792- "61: movl 36(%4), %%edx\n"
30793+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30794+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30795 " movnti %%eax, 32(%3)\n"
30796 " movnti %%edx, 36(%3)\n"
30797- "12: movl 40(%4), %%eax\n"
30798- "71: movl 44(%4), %%edx\n"
30799+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30800+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30801 " movnti %%eax, 40(%3)\n"
30802 " movnti %%edx, 44(%3)\n"
30803- "13: movl 48(%4), %%eax\n"
30804- "81: movl 52(%4), %%edx\n"
30805+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30806+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30807 " movnti %%eax, 48(%3)\n"
30808 " movnti %%edx, 52(%3)\n"
30809- "14: movl 56(%4), %%eax\n"
30810- "91: movl 60(%4), %%edx\n"
30811+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30812+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30813 " movnti %%eax, 56(%3)\n"
30814 " movnti %%edx, 60(%3)\n"
30815 " addl $-64, %0\n"
30816@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30817 " shrl $2, %0\n"
30818 " andl $3, %%eax\n"
30819 " cld\n"
30820- "6: rep; movsl\n"
30821+ "6: rep; "__copyuser_seg" movsl\n"
30822 " movl %%eax,%0\n"
30823- "7: rep; movsb\n"
30824+ "7: rep; "__copyuser_seg" movsb\n"
30825 "8:\n"
30826 ".section .fixup,\"ax\"\n"
30827 "9: lea 0(%%eax,%0,4),%0\n"
30828@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
30829
30830 __asm__ __volatile__(
30831 " .align 2,0x90\n"
30832- "0: movl 32(%4), %%eax\n"
30833+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30834 " cmpl $67, %0\n"
30835 " jbe 2f\n"
30836- "1: movl 64(%4), %%eax\n"
30837+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30838 " .align 2,0x90\n"
30839- "2: movl 0(%4), %%eax\n"
30840- "21: movl 4(%4), %%edx\n"
30841+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30842+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30843 " movnti %%eax, 0(%3)\n"
30844 " movnti %%edx, 4(%3)\n"
30845- "3: movl 8(%4), %%eax\n"
30846- "31: movl 12(%4),%%edx\n"
30847+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30848+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30849 " movnti %%eax, 8(%3)\n"
30850 " movnti %%edx, 12(%3)\n"
30851- "4: movl 16(%4), %%eax\n"
30852- "41: movl 20(%4), %%edx\n"
30853+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30854+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30855 " movnti %%eax, 16(%3)\n"
30856 " movnti %%edx, 20(%3)\n"
30857- "10: movl 24(%4), %%eax\n"
30858- "51: movl 28(%4), %%edx\n"
30859+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30860+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30861 " movnti %%eax, 24(%3)\n"
30862 " movnti %%edx, 28(%3)\n"
30863- "11: movl 32(%4), %%eax\n"
30864- "61: movl 36(%4), %%edx\n"
30865+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30866+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30867 " movnti %%eax, 32(%3)\n"
30868 " movnti %%edx, 36(%3)\n"
30869- "12: movl 40(%4), %%eax\n"
30870- "71: movl 44(%4), %%edx\n"
30871+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30872+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30873 " movnti %%eax, 40(%3)\n"
30874 " movnti %%edx, 44(%3)\n"
30875- "13: movl 48(%4), %%eax\n"
30876- "81: movl 52(%4), %%edx\n"
30877+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30878+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30879 " movnti %%eax, 48(%3)\n"
30880 " movnti %%edx, 52(%3)\n"
30881- "14: movl 56(%4), %%eax\n"
30882- "91: movl 60(%4), %%edx\n"
30883+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30884+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30885 " movnti %%eax, 56(%3)\n"
30886 " movnti %%edx, 60(%3)\n"
30887 " addl $-64, %0\n"
30888@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
30889 " shrl $2, %0\n"
30890 " andl $3, %%eax\n"
30891 " cld\n"
30892- "6: rep; movsl\n"
30893+ "6: rep; "__copyuser_seg" movsl\n"
30894 " movl %%eax,%0\n"
30895- "7: rep; movsb\n"
30896+ "7: rep; "__copyuser_seg" movsb\n"
30897 "8:\n"
30898 ".section .fixup,\"ax\"\n"
30899 "9: lea 0(%%eax,%0,4),%0\n"
30900@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
30901 */
30902 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
30903 unsigned long size);
30904-unsigned long __copy_user_intel(void __user *to, const void *from,
30905+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
30906+ unsigned long size);
30907+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
30908 unsigned long size);
30909 unsigned long __copy_user_zeroing_intel_nocache(void *to,
30910 const void __user *from, unsigned long size);
30911 #endif /* CONFIG_X86_INTEL_USERCOPY */
30912
30913 /* Generic arbitrary sized copy. */
30914-#define __copy_user(to, from, size) \
30915+#define __copy_user(to, from, size, prefix, set, restore) \
30916 do { \
30917 int __d0, __d1, __d2; \
30918 __asm__ __volatile__( \
30919+ set \
30920 " cmp $7,%0\n" \
30921 " jbe 1f\n" \
30922 " movl %1,%0\n" \
30923 " negl %0\n" \
30924 " andl $7,%0\n" \
30925 " subl %0,%3\n" \
30926- "4: rep; movsb\n" \
30927+ "4: rep; "prefix"movsb\n" \
30928 " movl %3,%0\n" \
30929 " shrl $2,%0\n" \
30930 " andl $3,%3\n" \
30931 " .align 2,0x90\n" \
30932- "0: rep; movsl\n" \
30933+ "0: rep; "prefix"movsl\n" \
30934 " movl %3,%0\n" \
30935- "1: rep; movsb\n" \
30936+ "1: rep; "prefix"movsb\n" \
30937 "2:\n" \
30938+ restore \
30939 ".section .fixup,\"ax\"\n" \
30940 "5: addl %3,%0\n" \
30941 " jmp 2b\n" \
30942@@ -538,14 +650,14 @@ do { \
30943 " negl %0\n" \
30944 " andl $7,%0\n" \
30945 " subl %0,%3\n" \
30946- "4: rep; movsb\n" \
30947+ "4: rep; "__copyuser_seg"movsb\n" \
30948 " movl %3,%0\n" \
30949 " shrl $2,%0\n" \
30950 " andl $3,%3\n" \
30951 " .align 2,0x90\n" \
30952- "0: rep; movsl\n" \
30953+ "0: rep; "__copyuser_seg"movsl\n" \
30954 " movl %3,%0\n" \
30955- "1: rep; movsb\n" \
30956+ "1: rep; "__copyuser_seg"movsb\n" \
30957 "2:\n" \
30958 ".section .fixup,\"ax\"\n" \
30959 "5: addl %3,%0\n" \
30960@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
30961 {
30962 stac();
30963 if (movsl_is_ok(to, from, n))
30964- __copy_user(to, from, n);
30965+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
30966 else
30967- n = __copy_user_intel(to, from, n);
30968+ n = __generic_copy_to_user_intel(to, from, n);
30969 clac();
30970 return n;
30971 }
30972@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
30973 {
30974 stac();
30975 if (movsl_is_ok(to, from, n))
30976- __copy_user(to, from, n);
30977+ __copy_user(to, from, n, __copyuser_seg, "", "");
30978 else
30979- n = __copy_user_intel((void __user *)to,
30980- (const void *)from, n);
30981+ n = __generic_copy_from_user_intel(to, from, n);
30982 clac();
30983 return n;
30984 }
30985@@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
30986 if (n > 64 && cpu_has_xmm2)
30987 n = __copy_user_intel_nocache(to, from, n);
30988 else
30989- __copy_user(to, from, n);
30990+ __copy_user(to, from, n, __copyuser_seg, "", "");
30991 #else
30992- __copy_user(to, from, n);
30993+ __copy_user(to, from, n, __copyuser_seg, "", "");
30994 #endif
30995 clac();
30996 return n;
30997 }
30998 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
30999
31000-/**
31001- * copy_to_user: - Copy a block of data into user space.
31002- * @to: Destination address, in user space.
31003- * @from: Source address, in kernel space.
31004- * @n: Number of bytes to copy.
31005- *
31006- * Context: User context only. This function may sleep.
31007- *
31008- * Copy data from kernel space to user space.
31009- *
31010- * Returns number of bytes that could not be copied.
31011- * On success, this will be zero.
31012- */
31013-unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31014+#ifdef CONFIG_PAX_MEMORY_UDEREF
31015+void __set_fs(mm_segment_t x)
31016 {
31017- if (access_ok(VERIFY_WRITE, to, n))
31018- n = __copy_to_user(to, from, n);
31019- return n;
31020+ switch (x.seg) {
31021+ case 0:
31022+ loadsegment(gs, 0);
31023+ break;
31024+ case TASK_SIZE_MAX:
31025+ loadsegment(gs, __USER_DS);
31026+ break;
31027+ case -1UL:
31028+ loadsegment(gs, __KERNEL_DS);
31029+ break;
31030+ default:
31031+ BUG();
31032+ }
31033 }
31034-EXPORT_SYMBOL(_copy_to_user);
31035+EXPORT_SYMBOL(__set_fs);
31036
31037-/**
31038- * copy_from_user: - Copy a block of data from user space.
31039- * @to: Destination address, in kernel space.
31040- * @from: Source address, in user space.
31041- * @n: Number of bytes to copy.
31042- *
31043- * Context: User context only. This function may sleep.
31044- *
31045- * Copy data from user space to kernel space.
31046- *
31047- * Returns number of bytes that could not be copied.
31048- * On success, this will be zero.
31049- *
31050- * If some data could not be copied, this function will pad the copied
31051- * data to the requested size using zero bytes.
31052- */
31053-unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31054+void set_fs(mm_segment_t x)
31055 {
31056- if (access_ok(VERIFY_READ, from, n))
31057- n = __copy_from_user(to, from, n);
31058- else
31059- memset(to, 0, n);
31060- return n;
31061+ current_thread_info()->addr_limit = x;
31062+ __set_fs(x);
31063 }
31064-EXPORT_SYMBOL(_copy_from_user);
31065+EXPORT_SYMBOL(set_fs);
31066+#endif
31067diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31068index c905e89..01ab928 100644
31069--- a/arch/x86/lib/usercopy_64.c
31070+++ b/arch/x86/lib/usercopy_64.c
31071@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31072 might_fault();
31073 /* no memory constraint because it doesn't change any memory gcc knows
31074 about */
31075+ pax_open_userland();
31076 stac();
31077 asm volatile(
31078 " testq %[size8],%[size8]\n"
31079@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31080 _ASM_EXTABLE(0b,3b)
31081 _ASM_EXTABLE(1b,2b)
31082 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31083- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31084+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31085 [zero] "r" (0UL), [eight] "r" (8UL));
31086 clac();
31087+ pax_close_userland();
31088 return size;
31089 }
31090 EXPORT_SYMBOL(__clear_user);
31091@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31092 }
31093 EXPORT_SYMBOL(clear_user);
31094
31095-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31096+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31097 {
31098- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31099- return copy_user_generic((__force void *)to, (__force void *)from, len);
31100- }
31101- return len;
31102+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31103+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31104+ return len;
31105 }
31106 EXPORT_SYMBOL(copy_in_user);
31107
31108@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31109 * it is not necessary to optimize tail handling.
31110 */
31111 __visible unsigned long
31112-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31113+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31114 {
31115 char c;
31116 unsigned zero_len;
31117
31118+ clac();
31119+ pax_close_userland();
31120 for (; len; --len, to++) {
31121 if (__get_user_nocheck(c, from++, sizeof(char)))
31122 break;
31123@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31124 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31125 if (__put_user_nocheck(c, to++, sizeof(char)))
31126 break;
31127- clac();
31128 return len;
31129 }
31130diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31131index 6a19ad9..1c48f9a 100644
31132--- a/arch/x86/mm/Makefile
31133+++ b/arch/x86/mm/Makefile
31134@@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31135 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31136
31137 obj-$(CONFIG_MEMTEST) += memtest.o
31138+
31139+quote:="
31140+obj-$(CONFIG_X86_64) += uderef_64.o
31141+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31142diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31143index 903ec1e..c4166b2 100644
31144--- a/arch/x86/mm/extable.c
31145+++ b/arch/x86/mm/extable.c
31146@@ -6,12 +6,24 @@
31147 static inline unsigned long
31148 ex_insn_addr(const struct exception_table_entry *x)
31149 {
31150- return (unsigned long)&x->insn + x->insn;
31151+ unsigned long reloc = 0;
31152+
31153+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31154+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31155+#endif
31156+
31157+ return (unsigned long)&x->insn + x->insn + reloc;
31158 }
31159 static inline unsigned long
31160 ex_fixup_addr(const struct exception_table_entry *x)
31161 {
31162- return (unsigned long)&x->fixup + x->fixup;
31163+ unsigned long reloc = 0;
31164+
31165+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31166+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31167+#endif
31168+
31169+ return (unsigned long)&x->fixup + x->fixup + reloc;
31170 }
31171
31172 int fixup_exception(struct pt_regs *regs)
31173@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31174 unsigned long new_ip;
31175
31176 #ifdef CONFIG_PNPBIOS
31177- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31178+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31179 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31180 extern u32 pnp_bios_is_utter_crap;
31181 pnp_bios_is_utter_crap = 1;
31182@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31183 i += 4;
31184 p->fixup -= i;
31185 i += 4;
31186+
31187+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31188+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31189+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31190+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31191+#endif
31192+
31193 }
31194 }
31195
31196diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31197index 6dea040..31e52ff 100644
31198--- a/arch/x86/mm/fault.c
31199+++ b/arch/x86/mm/fault.c
31200@@ -14,11 +14,18 @@
31201 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31202 #include <linux/prefetch.h> /* prefetchw */
31203 #include <linux/context_tracking.h> /* exception_enter(), ... */
31204+#include <linux/unistd.h>
31205+#include <linux/compiler.h>
31206
31207 #include <asm/traps.h> /* dotraplinkage, ... */
31208 #include <asm/pgalloc.h> /* pgd_*(), ... */
31209 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31210 #include <asm/fixmap.h> /* VSYSCALL_START */
31211+#include <asm/tlbflush.h>
31212+
31213+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31214+#include <asm/stacktrace.h>
31215+#endif
31216
31217 #define CREATE_TRACE_POINTS
31218 #include <asm/trace/exceptions.h>
31219@@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
31220 int ret = 0;
31221
31222 /* kprobe_running() needs smp_processor_id() */
31223- if (kprobes_built_in() && !user_mode_vm(regs)) {
31224+ if (kprobes_built_in() && !user_mode(regs)) {
31225 preempt_disable();
31226 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31227 ret = 1;
31228@@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31229 return !instr_lo || (instr_lo>>1) == 1;
31230 case 0x00:
31231 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31232- if (probe_kernel_address(instr, opcode))
31233+ if (user_mode(regs)) {
31234+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31235+ return 0;
31236+ } else if (probe_kernel_address(instr, opcode))
31237 return 0;
31238
31239 *prefetch = (instr_lo == 0xF) &&
31240@@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31241 while (instr < max_instr) {
31242 unsigned char opcode;
31243
31244- if (probe_kernel_address(instr, opcode))
31245+ if (user_mode(regs)) {
31246+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31247+ break;
31248+ } else if (probe_kernel_address(instr, opcode))
31249 break;
31250
31251 instr++;
31252@@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31253 force_sig_info(si_signo, &info, tsk);
31254 }
31255
31256+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31257+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31258+#endif
31259+
31260+#ifdef CONFIG_PAX_EMUTRAMP
31261+static int pax_handle_fetch_fault(struct pt_regs *regs);
31262+#endif
31263+
31264+#ifdef CONFIG_PAX_PAGEEXEC
31265+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31266+{
31267+ pgd_t *pgd;
31268+ pud_t *pud;
31269+ pmd_t *pmd;
31270+
31271+ pgd = pgd_offset(mm, address);
31272+ if (!pgd_present(*pgd))
31273+ return NULL;
31274+ pud = pud_offset(pgd, address);
31275+ if (!pud_present(*pud))
31276+ return NULL;
31277+ pmd = pmd_offset(pud, address);
31278+ if (!pmd_present(*pmd))
31279+ return NULL;
31280+ return pmd;
31281+}
31282+#endif
31283+
31284 DEFINE_SPINLOCK(pgd_lock);
31285 LIST_HEAD(pgd_list);
31286
31287@@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31288 for (address = VMALLOC_START & PMD_MASK;
31289 address >= TASK_SIZE && address < FIXADDR_TOP;
31290 address += PMD_SIZE) {
31291+
31292+#ifdef CONFIG_PAX_PER_CPU_PGD
31293+ unsigned long cpu;
31294+#else
31295 struct page *page;
31296+#endif
31297
31298 spin_lock(&pgd_lock);
31299+
31300+#ifdef CONFIG_PAX_PER_CPU_PGD
31301+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31302+ pgd_t *pgd = get_cpu_pgd(cpu, user);
31303+ pmd_t *ret;
31304+
31305+ ret = vmalloc_sync_one(pgd, address);
31306+ if (!ret)
31307+ break;
31308+ pgd = get_cpu_pgd(cpu, kernel);
31309+#else
31310 list_for_each_entry(page, &pgd_list, lru) {
31311+ pgd_t *pgd;
31312 spinlock_t *pgt_lock;
31313 pmd_t *ret;
31314
31315@@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31316 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31317
31318 spin_lock(pgt_lock);
31319- ret = vmalloc_sync_one(page_address(page), address);
31320+ pgd = page_address(page);
31321+#endif
31322+
31323+ ret = vmalloc_sync_one(pgd, address);
31324+
31325+#ifndef CONFIG_PAX_PER_CPU_PGD
31326 spin_unlock(pgt_lock);
31327+#endif
31328
31329 if (!ret)
31330 break;
31331@@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31332 * an interrupt in the middle of a task switch..
31333 */
31334 pgd_paddr = read_cr3();
31335+
31336+#ifdef CONFIG_PAX_PER_CPU_PGD
31337+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31338+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31339+#endif
31340+
31341 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31342 if (!pmd_k)
31343 return -1;
31344@@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31345 * happen within a race in page table update. In the later
31346 * case just flush:
31347 */
31348- pgd = pgd_offset(current->active_mm, address);
31349+
31350 pgd_ref = pgd_offset_k(address);
31351 if (pgd_none(*pgd_ref))
31352 return -1;
31353
31354+#ifdef CONFIG_PAX_PER_CPU_PGD
31355+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31356+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31357+ if (pgd_none(*pgd)) {
31358+ set_pgd(pgd, *pgd_ref);
31359+ arch_flush_lazy_mmu_mode();
31360+ } else {
31361+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31362+ }
31363+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31364+#else
31365+ pgd = pgd_offset(current->active_mm, address);
31366+#endif
31367+
31368 if (pgd_none(*pgd)) {
31369 set_pgd(pgd, *pgd_ref);
31370 arch_flush_lazy_mmu_mode();
31371@@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31372 static int is_errata100(struct pt_regs *regs, unsigned long address)
31373 {
31374 #ifdef CONFIG_X86_64
31375- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31376+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31377 return 1;
31378 #endif
31379 return 0;
31380@@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31381 }
31382
31383 static const char nx_warning[] = KERN_CRIT
31384-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31385+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31386
31387 static void
31388 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31389@@ -582,15 +666,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31390 if (!oops_may_print())
31391 return;
31392
31393- if (error_code & PF_INSTR) {
31394+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31395 unsigned int level;
31396
31397 pte_t *pte = lookup_address(address, &level);
31398
31399 if (pte && pte_present(*pte) && !pte_exec(*pte))
31400- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31401+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31402 }
31403
31404+#ifdef CONFIG_PAX_KERNEXEC
31405+ if (init_mm.start_code <= address && address < init_mm.end_code) {
31406+ if (current->signal->curr_ip)
31407+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31408+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
31409+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31410+ else
31411+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31412+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31413+ }
31414+#endif
31415+
31416 printk(KERN_ALERT "BUG: unable to handle kernel ");
31417 if (address < PAGE_SIZE)
31418 printk(KERN_CONT "NULL pointer dereference");
31419@@ -771,6 +867,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31420 return;
31421 }
31422 #endif
31423+
31424+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31425+ if (pax_is_fetch_fault(regs, error_code, address)) {
31426+
31427+#ifdef CONFIG_PAX_EMUTRAMP
31428+ switch (pax_handle_fetch_fault(regs)) {
31429+ case 2:
31430+ return;
31431+ }
31432+#endif
31433+
31434+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31435+ do_group_exit(SIGKILL);
31436+ }
31437+#endif
31438+
31439 /* Kernel addresses are always protection faults: */
31440 if (address >= TASK_SIZE)
31441 error_code |= PF_PROT;
31442@@ -856,7 +968,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31443 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31444 printk(KERN_ERR
31445 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31446- tsk->comm, tsk->pid, address);
31447+ tsk->comm, task_pid_nr(tsk), address);
31448 code = BUS_MCEERR_AR;
31449 }
31450 #endif
31451@@ -910,6 +1022,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31452 return 1;
31453 }
31454
31455+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31456+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31457+{
31458+ pte_t *pte;
31459+ pmd_t *pmd;
31460+ spinlock_t *ptl;
31461+ unsigned char pte_mask;
31462+
31463+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31464+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
31465+ return 0;
31466+
31467+ /* PaX: it's our fault, let's handle it if we can */
31468+
31469+ /* PaX: take a look at read faults before acquiring any locks */
31470+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
31471+ /* instruction fetch attempt from a protected page in user mode */
31472+ up_read(&mm->mmap_sem);
31473+
31474+#ifdef CONFIG_PAX_EMUTRAMP
31475+ switch (pax_handle_fetch_fault(regs)) {
31476+ case 2:
31477+ return 1;
31478+ }
31479+#endif
31480+
31481+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31482+ do_group_exit(SIGKILL);
31483+ }
31484+
31485+ pmd = pax_get_pmd(mm, address);
31486+ if (unlikely(!pmd))
31487+ return 0;
31488+
31489+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
31490+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
31491+ pte_unmap_unlock(pte, ptl);
31492+ return 0;
31493+ }
31494+
31495+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
31496+ /* write attempt to a protected page in user mode */
31497+ pte_unmap_unlock(pte, ptl);
31498+ return 0;
31499+ }
31500+
31501+#ifdef CONFIG_SMP
31502+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
31503+#else
31504+ if (likely(address > get_limit(regs->cs)))
31505+#endif
31506+ {
31507+ set_pte(pte, pte_mkread(*pte));
31508+ __flush_tlb_one(address);
31509+ pte_unmap_unlock(pte, ptl);
31510+ up_read(&mm->mmap_sem);
31511+ return 1;
31512+ }
31513+
31514+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
31515+
31516+ /*
31517+ * PaX: fill DTLB with user rights and retry
31518+ */
31519+ __asm__ __volatile__ (
31520+ "orb %2,(%1)\n"
31521+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
31522+/*
31523+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
31524+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
31525+ * page fault when examined during a TLB load attempt. this is true not only
31526+ * for PTEs holding a non-present entry but also present entries that will
31527+ * raise a page fault (such as those set up by PaX, or the copy-on-write
31528+ * mechanism). in effect it means that we do *not* need to flush the TLBs
31529+ * for our target pages since their PTEs are simply not in the TLBs at all.
31530+
31531+ * the best thing in omitting it is that we gain around 15-20% speed in the
31532+ * fast path of the page fault handler and can get rid of tracing since we
31533+ * can no longer flush unintended entries.
31534+ */
31535+ "invlpg (%0)\n"
31536+#endif
31537+ __copyuser_seg"testb $0,(%0)\n"
31538+ "xorb %3,(%1)\n"
31539+ :
31540+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31541+ : "memory", "cc");
31542+ pte_unmap_unlock(pte, ptl);
31543+ up_read(&mm->mmap_sem);
31544+ return 1;
31545+}
31546+#endif
31547+
31548 /*
31549 * Handle a spurious fault caused by a stale TLB entry.
31550 *
31551@@ -976,6 +1181,9 @@ int show_unhandled_signals = 1;
31552 static inline int
31553 access_error(unsigned long error_code, struct vm_area_struct *vma)
31554 {
31555+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
31556+ return 1;
31557+
31558 if (error_code & PF_WRITE) {
31559 /* write, present and write, not present: */
31560 if (unlikely(!(vma->vm_flags & VM_WRITE)))
31561@@ -1010,7 +1218,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
31562 if (error_code & PF_USER)
31563 return false;
31564
31565- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
31566+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
31567 return false;
31568
31569 return true;
31570@@ -1037,6 +1245,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
31571 /* Get the faulting address: */
31572 address = read_cr2();
31573
31574+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31575+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
31576+ if (!search_exception_tables(regs->ip)) {
31577+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31578+ bad_area_nosemaphore(regs, error_code, address);
31579+ return;
31580+ }
31581+ if (address < pax_user_shadow_base) {
31582+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31583+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31584+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31585+ } else
31586+ address -= pax_user_shadow_base;
31587+ }
31588+#endif
31589+
31590 /*
31591 * Detect and handle instructions that would cause a page fault for
31592 * both a tracked kernel page and a userspace page.
31593@@ -1114,7 +1338,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
31594 * User-mode registers count as a user access even for any
31595 * potential system fault or CPU buglet:
31596 */
31597- if (user_mode_vm(regs)) {
31598+ if (user_mode(regs)) {
31599 local_irq_enable();
31600 error_code |= PF_USER;
31601 flags |= FAULT_FLAG_USER;
31602@@ -1161,6 +1385,11 @@ retry:
31603 might_sleep();
31604 }
31605
31606+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31607+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31608+ return;
31609+#endif
31610+
31611 vma = find_vma(mm, address);
31612 if (unlikely(!vma)) {
31613 bad_area(regs, error_code, address);
31614@@ -1172,18 +1401,24 @@ retry:
31615 bad_area(regs, error_code, address);
31616 return;
31617 }
31618- if (error_code & PF_USER) {
31619- /*
31620- * Accessing the stack below %sp is always a bug.
31621- * The large cushion allows instructions like enter
31622- * and pusha to work. ("enter $65535, $31" pushes
31623- * 32 pointers and then decrements %sp by 65535.)
31624- */
31625- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31626- bad_area(regs, error_code, address);
31627- return;
31628- }
31629+ /*
31630+ * Accessing the stack below %sp is always a bug.
31631+ * The large cushion allows instructions like enter
31632+ * and pusha to work. ("enter $65535, $31" pushes
31633+ * 32 pointers and then decrements %sp by 65535.)
31634+ */
31635+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31636+ bad_area(regs, error_code, address);
31637+ return;
31638 }
31639+
31640+#ifdef CONFIG_PAX_SEGMEXEC
31641+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31642+ bad_area(regs, error_code, address);
31643+ return;
31644+ }
31645+#endif
31646+
31647 if (unlikely(expand_stack(vma, address))) {
31648 bad_area(regs, error_code, address);
31649 return;
31650@@ -1277,3 +1512,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
31651 __do_page_fault(regs, error_code);
31652 exception_exit(prev_state);
31653 }
31654+
31655+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31656+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31657+{
31658+ struct mm_struct *mm = current->mm;
31659+ unsigned long ip = regs->ip;
31660+
31661+ if (v8086_mode(regs))
31662+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31663+
31664+#ifdef CONFIG_PAX_PAGEEXEC
31665+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31666+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31667+ return true;
31668+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31669+ return true;
31670+ return false;
31671+ }
31672+#endif
31673+
31674+#ifdef CONFIG_PAX_SEGMEXEC
31675+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31676+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31677+ return true;
31678+ return false;
31679+ }
31680+#endif
31681+
31682+ return false;
31683+}
31684+#endif
31685+
31686+#ifdef CONFIG_PAX_EMUTRAMP
31687+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31688+{
31689+ int err;
31690+
31691+ do { /* PaX: libffi trampoline emulation */
31692+ unsigned char mov, jmp;
31693+ unsigned int addr1, addr2;
31694+
31695+#ifdef CONFIG_X86_64
31696+ if ((regs->ip + 9) >> 32)
31697+ break;
31698+#endif
31699+
31700+ err = get_user(mov, (unsigned char __user *)regs->ip);
31701+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31702+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31703+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31704+
31705+ if (err)
31706+ break;
31707+
31708+ if (mov == 0xB8 && jmp == 0xE9) {
31709+ regs->ax = addr1;
31710+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31711+ return 2;
31712+ }
31713+ } while (0);
31714+
31715+ do { /* PaX: gcc trampoline emulation #1 */
31716+ unsigned char mov1, mov2;
31717+ unsigned short jmp;
31718+ unsigned int addr1, addr2;
31719+
31720+#ifdef CONFIG_X86_64
31721+ if ((regs->ip + 11) >> 32)
31722+ break;
31723+#endif
31724+
31725+ err = get_user(mov1, (unsigned char __user *)regs->ip);
31726+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31727+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31728+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31729+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31730+
31731+ if (err)
31732+ break;
31733+
31734+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31735+ regs->cx = addr1;
31736+ regs->ax = addr2;
31737+ regs->ip = addr2;
31738+ return 2;
31739+ }
31740+ } while (0);
31741+
31742+ do { /* PaX: gcc trampoline emulation #2 */
31743+ unsigned char mov, jmp;
31744+ unsigned int addr1, addr2;
31745+
31746+#ifdef CONFIG_X86_64
31747+ if ((regs->ip + 9) >> 32)
31748+ break;
31749+#endif
31750+
31751+ err = get_user(mov, (unsigned char __user *)regs->ip);
31752+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31753+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31754+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31755+
31756+ if (err)
31757+ break;
31758+
31759+ if (mov == 0xB9 && jmp == 0xE9) {
31760+ regs->cx = addr1;
31761+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31762+ return 2;
31763+ }
31764+ } while (0);
31765+
31766+ return 1; /* PaX in action */
31767+}
31768+
31769+#ifdef CONFIG_X86_64
31770+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
31771+{
31772+ int err;
31773+
31774+ do { /* PaX: libffi trampoline emulation */
31775+ unsigned short mov1, mov2, jmp1;
31776+ unsigned char stcclc, jmp2;
31777+ unsigned long addr1, addr2;
31778+
31779+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31780+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31781+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31782+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31783+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
31784+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
31785+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
31786+
31787+ if (err)
31788+ break;
31789+
31790+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31791+ regs->r11 = addr1;
31792+ regs->r10 = addr2;
31793+ if (stcclc == 0xF8)
31794+ regs->flags &= ~X86_EFLAGS_CF;
31795+ else
31796+ regs->flags |= X86_EFLAGS_CF;
31797+ regs->ip = addr1;
31798+ return 2;
31799+ }
31800+ } while (0);
31801+
31802+ do { /* PaX: gcc trampoline emulation #1 */
31803+ unsigned short mov1, mov2, jmp1;
31804+ unsigned char jmp2;
31805+ unsigned int addr1;
31806+ unsigned long addr2;
31807+
31808+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31809+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
31810+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
31811+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
31812+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
31813+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
31814+
31815+ if (err)
31816+ break;
31817+
31818+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31819+ regs->r11 = addr1;
31820+ regs->r10 = addr2;
31821+ regs->ip = addr1;
31822+ return 2;
31823+ }
31824+ } while (0);
31825+
31826+ do { /* PaX: gcc trampoline emulation #2 */
31827+ unsigned short mov1, mov2, jmp1;
31828+ unsigned char jmp2;
31829+ unsigned long addr1, addr2;
31830+
31831+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31832+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31833+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31834+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31835+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
31836+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
31837+
31838+ if (err)
31839+ break;
31840+
31841+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31842+ regs->r11 = addr1;
31843+ regs->r10 = addr2;
31844+ regs->ip = addr1;
31845+ return 2;
31846+ }
31847+ } while (0);
31848+
31849+ return 1; /* PaX in action */
31850+}
31851+#endif
31852+
31853+/*
31854+ * PaX: decide what to do with offenders (regs->ip = fault address)
31855+ *
31856+ * returns 1 when task should be killed
31857+ * 2 when gcc trampoline was detected
31858+ */
31859+static int pax_handle_fetch_fault(struct pt_regs *regs)
31860+{
31861+ if (v8086_mode(regs))
31862+ return 1;
31863+
31864+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
31865+ return 1;
31866+
31867+#ifdef CONFIG_X86_32
31868+ return pax_handle_fetch_fault_32(regs);
31869+#else
31870+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
31871+ return pax_handle_fetch_fault_32(regs);
31872+ else
31873+ return pax_handle_fetch_fault_64(regs);
31874+#endif
31875+}
31876+#endif
31877+
31878+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31879+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
31880+{
31881+ long i;
31882+
31883+ printk(KERN_ERR "PAX: bytes at PC: ");
31884+ for (i = 0; i < 20; i++) {
31885+ unsigned char c;
31886+ if (get_user(c, (unsigned char __force_user *)pc+i))
31887+ printk(KERN_CONT "?? ");
31888+ else
31889+ printk(KERN_CONT "%02x ", c);
31890+ }
31891+ printk("\n");
31892+
31893+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
31894+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
31895+ unsigned long c;
31896+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
31897+#ifdef CONFIG_X86_32
31898+ printk(KERN_CONT "???????? ");
31899+#else
31900+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
31901+ printk(KERN_CONT "???????? ???????? ");
31902+ else
31903+ printk(KERN_CONT "???????????????? ");
31904+#endif
31905+ } else {
31906+#ifdef CONFIG_X86_64
31907+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
31908+ printk(KERN_CONT "%08x ", (unsigned int)c);
31909+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
31910+ } else
31911+#endif
31912+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
31913+ }
31914+ }
31915+ printk("\n");
31916+}
31917+#endif
31918+
31919+/**
31920+ * probe_kernel_write(): safely attempt to write to a location
31921+ * @dst: address to write to
31922+ * @src: pointer to the data that shall be written
31923+ * @size: size of the data chunk
31924+ *
31925+ * Safely write to address @dst from the buffer at @src. If a kernel fault
31926+ * happens, handle that and return -EFAULT.
31927+ */
31928+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
31929+{
31930+ long ret;
31931+ mm_segment_t old_fs = get_fs();
31932+
31933+ set_fs(KERNEL_DS);
31934+ pagefault_disable();
31935+ pax_open_kernel();
31936+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
31937+ pax_close_kernel();
31938+ pagefault_enable();
31939+ set_fs(old_fs);
31940+
31941+ return ret ? -EFAULT : 0;
31942+}
31943diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
31944index 0596e8e..5626789 100644
31945--- a/arch/x86/mm/gup.c
31946+++ b/arch/x86/mm/gup.c
31947@@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
31948 addr = start;
31949 len = (unsigned long) nr_pages << PAGE_SHIFT;
31950 end = start + len;
31951- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31952+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
31953 (void __user *)start, len)))
31954 return 0;
31955
31956@@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
31957 goto slow_irqon;
31958 #endif
31959
31960+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
31961+ (void __user *)start, len)))
31962+ return 0;
31963+
31964 /*
31965 * XXX: batch / limit 'nr', to avoid large irq off latency
31966 * needs some instrumenting to determine the common sizes used by
31967diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
31968index 4500142..53a363c 100644
31969--- a/arch/x86/mm/highmem_32.c
31970+++ b/arch/x86/mm/highmem_32.c
31971@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
31972 idx = type + KM_TYPE_NR*smp_processor_id();
31973 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31974 BUG_ON(!pte_none(*(kmap_pte-idx)));
31975+
31976+ pax_open_kernel();
31977 set_pte(kmap_pte-idx, mk_pte(page, prot));
31978+ pax_close_kernel();
31979+
31980 arch_flush_lazy_mmu_mode();
31981
31982 return (void *)vaddr;
31983diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
31984index 9d980d8..6bbfacb 100644
31985--- a/arch/x86/mm/hugetlbpage.c
31986+++ b/arch/x86/mm/hugetlbpage.c
31987@@ -92,23 +92,30 @@ int pmd_huge_support(void)
31988 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
31989 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
31990 unsigned long addr, unsigned long len,
31991- unsigned long pgoff, unsigned long flags)
31992+ unsigned long pgoff, unsigned long flags, unsigned long offset)
31993 {
31994 struct hstate *h = hstate_file(file);
31995 struct vm_unmapped_area_info info;
31996-
31997+
31998 info.flags = 0;
31999 info.length = len;
32000 info.low_limit = TASK_UNMAPPED_BASE;
32001+
32002+#ifdef CONFIG_PAX_RANDMMAP
32003+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32004+ info.low_limit += current->mm->delta_mmap;
32005+#endif
32006+
32007 info.high_limit = TASK_SIZE;
32008 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32009 info.align_offset = 0;
32010+ info.threadstack_offset = offset;
32011 return vm_unmapped_area(&info);
32012 }
32013
32014 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32015 unsigned long addr0, unsigned long len,
32016- unsigned long pgoff, unsigned long flags)
32017+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32018 {
32019 struct hstate *h = hstate_file(file);
32020 struct vm_unmapped_area_info info;
32021@@ -120,6 +127,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32022 info.high_limit = current->mm->mmap_base;
32023 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32024 info.align_offset = 0;
32025+ info.threadstack_offset = offset;
32026 addr = vm_unmapped_area(&info);
32027
32028 /*
32029@@ -132,6 +140,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32030 VM_BUG_ON(addr != -ENOMEM);
32031 info.flags = 0;
32032 info.low_limit = TASK_UNMAPPED_BASE;
32033+
32034+#ifdef CONFIG_PAX_RANDMMAP
32035+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32036+ info.low_limit += current->mm->delta_mmap;
32037+#endif
32038+
32039 info.high_limit = TASK_SIZE;
32040 addr = vm_unmapped_area(&info);
32041 }
32042@@ -146,10 +160,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32043 struct hstate *h = hstate_file(file);
32044 struct mm_struct *mm = current->mm;
32045 struct vm_area_struct *vma;
32046+ unsigned long pax_task_size = TASK_SIZE;
32047+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32048
32049 if (len & ~huge_page_mask(h))
32050 return -EINVAL;
32051- if (len > TASK_SIZE)
32052+
32053+#ifdef CONFIG_PAX_SEGMEXEC
32054+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32055+ pax_task_size = SEGMEXEC_TASK_SIZE;
32056+#endif
32057+
32058+ pax_task_size -= PAGE_SIZE;
32059+
32060+ if (len > pax_task_size)
32061 return -ENOMEM;
32062
32063 if (flags & MAP_FIXED) {
32064@@ -158,19 +182,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32065 return addr;
32066 }
32067
32068+#ifdef CONFIG_PAX_RANDMMAP
32069+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32070+#endif
32071+
32072 if (addr) {
32073 addr = ALIGN(addr, huge_page_size(h));
32074 vma = find_vma(mm, addr);
32075- if (TASK_SIZE - len >= addr &&
32076- (!vma || addr + len <= vma->vm_start))
32077+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32078 return addr;
32079 }
32080 if (mm->get_unmapped_area == arch_get_unmapped_area)
32081 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32082- pgoff, flags);
32083+ pgoff, flags, offset);
32084 else
32085 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32086- pgoff, flags);
32087+ pgoff, flags, offset);
32088 }
32089
32090 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
32091diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32092index f971306..e83e0f6 100644
32093--- a/arch/x86/mm/init.c
32094+++ b/arch/x86/mm/init.c
32095@@ -4,6 +4,7 @@
32096 #include <linux/swap.h>
32097 #include <linux/memblock.h>
32098 #include <linux/bootmem.h> /* for max_low_pfn */
32099+#include <linux/tboot.h>
32100
32101 #include <asm/cacheflush.h>
32102 #include <asm/e820.h>
32103@@ -17,6 +18,8 @@
32104 #include <asm/proto.h>
32105 #include <asm/dma.h> /* for MAX_DMA_PFN */
32106 #include <asm/microcode.h>
32107+#include <asm/desc.h>
32108+#include <asm/bios_ebda.h>
32109
32110 #include "mm_internal.h"
32111
32112@@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32113 early_ioremap_page_table_range_init();
32114 #endif
32115
32116+#ifdef CONFIG_PAX_PER_CPU_PGD
32117+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32118+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32119+ KERNEL_PGD_PTRS);
32120+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32121+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32122+ KERNEL_PGD_PTRS);
32123+ load_cr3(get_cpu_pgd(0, kernel));
32124+#else
32125 load_cr3(swapper_pg_dir);
32126+#endif
32127+
32128 __flush_tlb_all();
32129
32130 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32131@@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32132 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32133 * mmio resources as well as potential bios/acpi data regions.
32134 */
32135+
32136+#ifdef CONFIG_GRKERNSEC_KMEM
32137+static unsigned int ebda_start __read_only;
32138+static unsigned int ebda_end __read_only;
32139+#endif
32140+
32141 int devmem_is_allowed(unsigned long pagenr)
32142 {
32143- if (pagenr < 256)
32144+#ifdef CONFIG_GRKERNSEC_KMEM
32145+ /* allow BDA */
32146+ if (!pagenr)
32147 return 1;
32148+ /* allow EBDA */
32149+ if (pagenr >= ebda_start && pagenr < ebda_end)
32150+ return 1;
32151+ /* if tboot is in use, allow access to its hardcoded serial log range */
32152+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32153+ return 1;
32154+#else
32155+ if (!pagenr)
32156+ return 1;
32157+#ifdef CONFIG_VM86
32158+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32159+ return 1;
32160+#endif
32161+#endif
32162+
32163+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32164+ return 1;
32165+#ifdef CONFIG_GRKERNSEC_KMEM
32166+ /* throw out everything else below 1MB */
32167+ if (pagenr <= 256)
32168+ return 0;
32169+#endif
32170 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32171 return 0;
32172 if (!page_is_ram(pagenr))
32173@@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32174 #endif
32175 }
32176
32177+#ifdef CONFIG_GRKERNSEC_KMEM
32178+static inline void gr_init_ebda(void)
32179+{
32180+ unsigned int ebda_addr;
32181+ unsigned int ebda_size = 0;
32182+
32183+ ebda_addr = get_bios_ebda();
32184+ if (ebda_addr) {
32185+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32186+ ebda_size <<= 10;
32187+ }
32188+ if (ebda_addr && ebda_size) {
32189+ ebda_start = ebda_addr >> PAGE_SHIFT;
32190+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32191+ } else {
32192+ ebda_start = 0x9f000 >> PAGE_SHIFT;
32193+ ebda_end = 0xa0000 >> PAGE_SHIFT;
32194+ }
32195+}
32196+#else
32197+static inline void gr_init_ebda(void) { }
32198+#endif
32199+
32200 void free_initmem(void)
32201 {
32202+#ifdef CONFIG_PAX_KERNEXEC
32203+#ifdef CONFIG_X86_32
32204+ /* PaX: limit KERNEL_CS to actual size */
32205+ unsigned long addr, limit;
32206+ struct desc_struct d;
32207+ int cpu;
32208+#else
32209+ pgd_t *pgd;
32210+ pud_t *pud;
32211+ pmd_t *pmd;
32212+ unsigned long addr, end;
32213+#endif
32214+#endif
32215+
32216+ gr_init_ebda();
32217+
32218+#ifdef CONFIG_PAX_KERNEXEC
32219+#ifdef CONFIG_X86_32
32220+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32221+ limit = (limit - 1UL) >> PAGE_SHIFT;
32222+
32223+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32224+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32225+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32226+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32227+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32228+ }
32229+
32230+ /* PaX: make KERNEL_CS read-only */
32231+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32232+ if (!paravirt_enabled())
32233+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32234+/*
32235+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32236+ pgd = pgd_offset_k(addr);
32237+ pud = pud_offset(pgd, addr);
32238+ pmd = pmd_offset(pud, addr);
32239+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32240+ }
32241+*/
32242+#ifdef CONFIG_X86_PAE
32243+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32244+/*
32245+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32246+ pgd = pgd_offset_k(addr);
32247+ pud = pud_offset(pgd, addr);
32248+ pmd = pmd_offset(pud, addr);
32249+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32250+ }
32251+*/
32252+#endif
32253+
32254+#ifdef CONFIG_MODULES
32255+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32256+#endif
32257+
32258+#else
32259+ /* PaX: make kernel code/rodata read-only, rest non-executable */
32260+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32261+ pgd = pgd_offset_k(addr);
32262+ pud = pud_offset(pgd, addr);
32263+ pmd = pmd_offset(pud, addr);
32264+ if (!pmd_present(*pmd))
32265+ continue;
32266+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32267+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32268+ else
32269+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32270+ }
32271+
32272+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32273+ end = addr + KERNEL_IMAGE_SIZE;
32274+ for (; addr < end; addr += PMD_SIZE) {
32275+ pgd = pgd_offset_k(addr);
32276+ pud = pud_offset(pgd, addr);
32277+ pmd = pmd_offset(pud, addr);
32278+ if (!pmd_present(*pmd))
32279+ continue;
32280+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32281+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32282+ }
32283+#endif
32284+
32285+ flush_tlb_all();
32286+#endif
32287+
32288 free_init_pages("unused kernel",
32289 (unsigned long)(&__init_begin),
32290 (unsigned long)(&__init_end));
32291diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32292index 4287f1f..3b99c71 100644
32293--- a/arch/x86/mm/init_32.c
32294+++ b/arch/x86/mm/init_32.c
32295@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32296 bool __read_mostly __vmalloc_start_set = false;
32297
32298 /*
32299- * Creates a middle page table and puts a pointer to it in the
32300- * given global directory entry. This only returns the gd entry
32301- * in non-PAE compilation mode, since the middle layer is folded.
32302- */
32303-static pmd_t * __init one_md_table_init(pgd_t *pgd)
32304-{
32305- pud_t *pud;
32306- pmd_t *pmd_table;
32307-
32308-#ifdef CONFIG_X86_PAE
32309- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32310- pmd_table = (pmd_t *)alloc_low_page();
32311- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32312- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32313- pud = pud_offset(pgd, 0);
32314- BUG_ON(pmd_table != pmd_offset(pud, 0));
32315-
32316- return pmd_table;
32317- }
32318-#endif
32319- pud = pud_offset(pgd, 0);
32320- pmd_table = pmd_offset(pud, 0);
32321-
32322- return pmd_table;
32323-}
32324-
32325-/*
32326 * Create a page table and place a pointer to it in a middle page
32327 * directory entry:
32328 */
32329@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32330 pte_t *page_table = (pte_t *)alloc_low_page();
32331
32332 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32333+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32334+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32335+#else
32336 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32337+#endif
32338 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32339 }
32340
32341 return pte_offset_kernel(pmd, 0);
32342 }
32343
32344+static pmd_t * __init one_md_table_init(pgd_t *pgd)
32345+{
32346+ pud_t *pud;
32347+ pmd_t *pmd_table;
32348+
32349+ pud = pud_offset(pgd, 0);
32350+ pmd_table = pmd_offset(pud, 0);
32351+
32352+ return pmd_table;
32353+}
32354+
32355 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32356 {
32357 int pgd_idx = pgd_index(vaddr);
32358@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32359 int pgd_idx, pmd_idx;
32360 unsigned long vaddr;
32361 pgd_t *pgd;
32362+ pud_t *pud;
32363 pmd_t *pmd;
32364 pte_t *pte = NULL;
32365 unsigned long count = page_table_range_init_count(start, end);
32366@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32367 pgd = pgd_base + pgd_idx;
32368
32369 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32370- pmd = one_md_table_init(pgd);
32371- pmd = pmd + pmd_index(vaddr);
32372+ pud = pud_offset(pgd, vaddr);
32373+ pmd = pmd_offset(pud, vaddr);
32374+
32375+#ifdef CONFIG_X86_PAE
32376+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32377+#endif
32378+
32379 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32380 pmd++, pmd_idx++) {
32381 pte = page_table_kmap_check(one_page_table_init(pmd),
32382@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32383 }
32384 }
32385
32386-static inline int is_kernel_text(unsigned long addr)
32387+static inline int is_kernel_text(unsigned long start, unsigned long end)
32388 {
32389- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32390- return 1;
32391- return 0;
32392+ if ((start > ktla_ktva((unsigned long)_etext) ||
32393+ end <= ktla_ktva((unsigned long)_stext)) &&
32394+ (start > ktla_ktva((unsigned long)_einittext) ||
32395+ end <= ktla_ktva((unsigned long)_sinittext)) &&
32396+
32397+#ifdef CONFIG_ACPI_SLEEP
32398+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32399+#endif
32400+
32401+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32402+ return 0;
32403+ return 1;
32404 }
32405
32406 /*
32407@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32408 unsigned long last_map_addr = end;
32409 unsigned long start_pfn, end_pfn;
32410 pgd_t *pgd_base = swapper_pg_dir;
32411- int pgd_idx, pmd_idx, pte_ofs;
32412+ unsigned int pgd_idx, pmd_idx, pte_ofs;
32413 unsigned long pfn;
32414 pgd_t *pgd;
32415+ pud_t *pud;
32416 pmd_t *pmd;
32417 pte_t *pte;
32418 unsigned pages_2m, pages_4k;
32419@@ -291,8 +295,13 @@ repeat:
32420 pfn = start_pfn;
32421 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32422 pgd = pgd_base + pgd_idx;
32423- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32424- pmd = one_md_table_init(pgd);
32425+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32426+ pud = pud_offset(pgd, 0);
32427+ pmd = pmd_offset(pud, 0);
32428+
32429+#ifdef CONFIG_X86_PAE
32430+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32431+#endif
32432
32433 if (pfn >= end_pfn)
32434 continue;
32435@@ -304,14 +313,13 @@ repeat:
32436 #endif
32437 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32438 pmd++, pmd_idx++) {
32439- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32440+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32441
32442 /*
32443 * Map with big pages if possible, otherwise
32444 * create normal page tables:
32445 */
32446 if (use_pse) {
32447- unsigned int addr2;
32448 pgprot_t prot = PAGE_KERNEL_LARGE;
32449 /*
32450 * first pass will use the same initial
32451@@ -322,11 +330,7 @@ repeat:
32452 _PAGE_PSE);
32453
32454 pfn &= PMD_MASK >> PAGE_SHIFT;
32455- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32456- PAGE_OFFSET + PAGE_SIZE-1;
32457-
32458- if (is_kernel_text(addr) ||
32459- is_kernel_text(addr2))
32460+ if (is_kernel_text(address, address + PMD_SIZE))
32461 prot = PAGE_KERNEL_LARGE_EXEC;
32462
32463 pages_2m++;
32464@@ -343,7 +347,7 @@ repeat:
32465 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32466 pte += pte_ofs;
32467 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32468- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32469+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32470 pgprot_t prot = PAGE_KERNEL;
32471 /*
32472 * first pass will use the same initial
32473@@ -351,7 +355,7 @@ repeat:
32474 */
32475 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32476
32477- if (is_kernel_text(addr))
32478+ if (is_kernel_text(address, address + PAGE_SIZE))
32479 prot = PAGE_KERNEL_EXEC;
32480
32481 pages_4k++;
32482@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
32483
32484 pud = pud_offset(pgd, va);
32485 pmd = pmd_offset(pud, va);
32486- if (!pmd_present(*pmd))
32487+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
32488 break;
32489
32490 /* should not be large page here */
32491@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
32492
32493 static void __init pagetable_init(void)
32494 {
32495- pgd_t *pgd_base = swapper_pg_dir;
32496-
32497- permanent_kmaps_init(pgd_base);
32498+ permanent_kmaps_init(swapper_pg_dir);
32499 }
32500
32501-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32502+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32503 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32504
32505 /* user-defined highmem size */
32506@@ -787,10 +789,10 @@ void __init mem_init(void)
32507 ((unsigned long)&__init_end -
32508 (unsigned long)&__init_begin) >> 10,
32509
32510- (unsigned long)&_etext, (unsigned long)&_edata,
32511- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
32512+ (unsigned long)&_sdata, (unsigned long)&_edata,
32513+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
32514
32515- (unsigned long)&_text, (unsigned long)&_etext,
32516+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
32517 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
32518
32519 /*
32520@@ -880,6 +882,7 @@ void set_kernel_text_rw(void)
32521 if (!kernel_set_to_readonly)
32522 return;
32523
32524+ start = ktla_ktva(start);
32525 pr_debug("Set kernel text: %lx - %lx for read write\n",
32526 start, start+size);
32527
32528@@ -894,6 +897,7 @@ void set_kernel_text_ro(void)
32529 if (!kernel_set_to_readonly)
32530 return;
32531
32532+ start = ktla_ktva(start);
32533 pr_debug("Set kernel text: %lx - %lx for read only\n",
32534 start, start+size);
32535
32536@@ -922,6 +926,7 @@ void mark_rodata_ro(void)
32537 unsigned long start = PFN_ALIGN(_text);
32538 unsigned long size = PFN_ALIGN(_etext) - start;
32539
32540+ start = ktla_ktva(start);
32541 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32542 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32543 size >> 10);
32544diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32545index 104d56a..62ba13f1 100644
32546--- a/arch/x86/mm/init_64.c
32547+++ b/arch/x86/mm/init_64.c
32548@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32549 * around without checking the pgd every time.
32550 */
32551
32552-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32553+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32554 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32555
32556 int force_personality32;
32557@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32558
32559 for (address = start; address <= end; address += PGDIR_SIZE) {
32560 const pgd_t *pgd_ref = pgd_offset_k(address);
32561+
32562+#ifdef CONFIG_PAX_PER_CPU_PGD
32563+ unsigned long cpu;
32564+#else
32565 struct page *page;
32566+#endif
32567
32568 if (pgd_none(*pgd_ref))
32569 continue;
32570
32571 spin_lock(&pgd_lock);
32572+
32573+#ifdef CONFIG_PAX_PER_CPU_PGD
32574+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32575+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
32576+
32577+ if (pgd_none(*pgd))
32578+ set_pgd(pgd, *pgd_ref);
32579+ else
32580+ BUG_ON(pgd_page_vaddr(*pgd)
32581+ != pgd_page_vaddr(*pgd_ref));
32582+ pgd = pgd_offset_cpu(cpu, kernel, address);
32583+#else
32584 list_for_each_entry(page, &pgd_list, lru) {
32585 pgd_t *pgd;
32586 spinlock_t *pgt_lock;
32587@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32588 /* the pgt_lock only for Xen */
32589 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32590 spin_lock(pgt_lock);
32591+#endif
32592
32593 if (pgd_none(*pgd))
32594 set_pgd(pgd, *pgd_ref);
32595@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32596 BUG_ON(pgd_page_vaddr(*pgd)
32597 != pgd_page_vaddr(*pgd_ref));
32598
32599+#ifndef CONFIG_PAX_PER_CPU_PGD
32600 spin_unlock(pgt_lock);
32601+#endif
32602+
32603 }
32604 spin_unlock(&pgd_lock);
32605 }
32606@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32607 {
32608 if (pgd_none(*pgd)) {
32609 pud_t *pud = (pud_t *)spp_getpage();
32610- pgd_populate(&init_mm, pgd, pud);
32611+ pgd_populate_kernel(&init_mm, pgd, pud);
32612 if (pud != pud_offset(pgd, 0))
32613 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32614 pud, pud_offset(pgd, 0));
32615@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32616 {
32617 if (pud_none(*pud)) {
32618 pmd_t *pmd = (pmd_t *) spp_getpage();
32619- pud_populate(&init_mm, pud, pmd);
32620+ pud_populate_kernel(&init_mm, pud, pmd);
32621 if (pmd != pmd_offset(pud, 0))
32622 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32623 pmd, pmd_offset(pud, 0));
32624@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32625 pmd = fill_pmd(pud, vaddr);
32626 pte = fill_pte(pmd, vaddr);
32627
32628+ pax_open_kernel();
32629 set_pte(pte, new_pte);
32630+ pax_close_kernel();
32631
32632 /*
32633 * It's enough to flush this one mapping.
32634@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32635 pgd = pgd_offset_k((unsigned long)__va(phys));
32636 if (pgd_none(*pgd)) {
32637 pud = (pud_t *) spp_getpage();
32638- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32639- _PAGE_USER));
32640+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32641 }
32642 pud = pud_offset(pgd, (unsigned long)__va(phys));
32643 if (pud_none(*pud)) {
32644 pmd = (pmd_t *) spp_getpage();
32645- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32646- _PAGE_USER));
32647+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32648 }
32649 pmd = pmd_offset(pud, phys);
32650 BUG_ON(!pmd_none(*pmd));
32651@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32652 prot);
32653
32654 spin_lock(&init_mm.page_table_lock);
32655- pud_populate(&init_mm, pud, pmd);
32656+ pud_populate_kernel(&init_mm, pud, pmd);
32657 spin_unlock(&init_mm.page_table_lock);
32658 }
32659 __flush_tlb_all();
32660@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32661 page_size_mask);
32662
32663 spin_lock(&init_mm.page_table_lock);
32664- pgd_populate(&init_mm, pgd, pud);
32665+ pgd_populate_kernel(&init_mm, pgd, pud);
32666 spin_unlock(&init_mm.page_table_lock);
32667 pgd_changed = true;
32668 }
32669@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32670 static struct vm_area_struct gate_vma = {
32671 .vm_start = VSYSCALL_START,
32672 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32673- .vm_page_prot = PAGE_READONLY_EXEC,
32674- .vm_flags = VM_READ | VM_EXEC
32675+ .vm_page_prot = PAGE_READONLY,
32676+ .vm_flags = VM_READ
32677 };
32678
32679 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32680@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32681
32682 const char *arch_vma_name(struct vm_area_struct *vma)
32683 {
32684- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32685+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32686 return "[vdso]";
32687 if (vma == &gate_vma)
32688 return "[vsyscall]";
32689diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32690index 7b179b4..6bd17777 100644
32691--- a/arch/x86/mm/iomap_32.c
32692+++ b/arch/x86/mm/iomap_32.c
32693@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32694 type = kmap_atomic_idx_push();
32695 idx = type + KM_TYPE_NR * smp_processor_id();
32696 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32697+
32698+ pax_open_kernel();
32699 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32700+ pax_close_kernel();
32701+
32702 arch_flush_lazy_mmu_mode();
32703
32704 return (void *)vaddr;
32705diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32706index 799580c..72f9fe0 100644
32707--- a/arch/x86/mm/ioremap.c
32708+++ b/arch/x86/mm/ioremap.c
32709@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
32710 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
32711 int is_ram = page_is_ram(pfn);
32712
32713- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
32714+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
32715 return NULL;
32716 WARN_ON_ONCE(is_ram);
32717 }
32718@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
32719 *
32720 * Caller must ensure there is only one unmapping for the same pointer.
32721 */
32722-void iounmap(volatile void __iomem *addr)
32723+void iounmap(const volatile void __iomem *addr)
32724 {
32725 struct vm_struct *p, *o;
32726
32727@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32728
32729 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32730 if (page_is_ram(start >> PAGE_SHIFT))
32731+#ifdef CONFIG_HIGHMEM
32732+ if ((start >> PAGE_SHIFT) < max_low_pfn)
32733+#endif
32734 return __va(phys);
32735
32736 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32737@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32738 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32739 {
32740 if (page_is_ram(phys >> PAGE_SHIFT))
32741+#ifdef CONFIG_HIGHMEM
32742+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
32743+#endif
32744 return;
32745
32746 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32747@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
32748 early_param("early_ioremap_debug", early_ioremap_debug_setup);
32749
32750 static __initdata int after_paging_init;
32751-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32752+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32753
32754 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32755 {
32756@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
32757 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
32758
32759 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32760- memset(bm_pte, 0, sizeof(bm_pte));
32761- pmd_populate_kernel(&init_mm, pmd, bm_pte);
32762+ pmd_populate_user(&init_mm, pmd, bm_pte);
32763
32764 /*
32765 * The boot-ioremap range spans multiple pmds, for which
32766diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
32767index d87dd6d..bf3fa66 100644
32768--- a/arch/x86/mm/kmemcheck/kmemcheck.c
32769+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
32770@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
32771 * memory (e.g. tracked pages)? For now, we need this to avoid
32772 * invoking kmemcheck for PnP BIOS calls.
32773 */
32774- if (regs->flags & X86_VM_MASK)
32775+ if (v8086_mode(regs))
32776 return false;
32777- if (regs->cs != __KERNEL_CS)
32778+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
32779 return false;
32780
32781 pte = kmemcheck_pte_lookup(address);
32782diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
32783index 25e7e13..1964579 100644
32784--- a/arch/x86/mm/mmap.c
32785+++ b/arch/x86/mm/mmap.c
32786@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
32787 * Leave an at least ~128 MB hole with possible stack randomization.
32788 */
32789 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
32790-#define MAX_GAP (TASK_SIZE/6*5)
32791+#define MAX_GAP (pax_task_size/6*5)
32792
32793 static int mmap_is_legacy(void)
32794 {
32795@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
32796 return rnd << PAGE_SHIFT;
32797 }
32798
32799-static unsigned long mmap_base(void)
32800+static unsigned long mmap_base(struct mm_struct *mm)
32801 {
32802 unsigned long gap = rlimit(RLIMIT_STACK);
32803+ unsigned long pax_task_size = TASK_SIZE;
32804+
32805+#ifdef CONFIG_PAX_SEGMEXEC
32806+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32807+ pax_task_size = SEGMEXEC_TASK_SIZE;
32808+#endif
32809
32810 if (gap < MIN_GAP)
32811 gap = MIN_GAP;
32812 else if (gap > MAX_GAP)
32813 gap = MAX_GAP;
32814
32815- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
32816+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
32817 }
32818
32819 /*
32820 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
32821 * does, but not when emulating X86_32
32822 */
32823-static unsigned long mmap_legacy_base(void)
32824+static unsigned long mmap_legacy_base(struct mm_struct *mm)
32825 {
32826- if (mmap_is_ia32())
32827+ if (mmap_is_ia32()) {
32828+
32829+#ifdef CONFIG_PAX_SEGMEXEC
32830+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32831+ return SEGMEXEC_TASK_UNMAPPED_BASE;
32832+ else
32833+#endif
32834+
32835 return TASK_UNMAPPED_BASE;
32836- else
32837+ } else
32838 return TASK_UNMAPPED_BASE + mmap_rnd();
32839 }
32840
32841@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
32842 */
32843 void arch_pick_mmap_layout(struct mm_struct *mm)
32844 {
32845- mm->mmap_legacy_base = mmap_legacy_base();
32846- mm->mmap_base = mmap_base();
32847+ mm->mmap_legacy_base = mmap_legacy_base(mm);
32848+ mm->mmap_base = mmap_base(mm);
32849+
32850+#ifdef CONFIG_PAX_RANDMMAP
32851+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
32852+ mm->mmap_legacy_base += mm->delta_mmap;
32853+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
32854+ }
32855+#endif
32856
32857 if (mmap_is_legacy()) {
32858 mm->mmap_base = mm->mmap_legacy_base;
32859diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
32860index 0057a7a..95c7edd 100644
32861--- a/arch/x86/mm/mmio-mod.c
32862+++ b/arch/x86/mm/mmio-mod.c
32863@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
32864 break;
32865 default:
32866 {
32867- unsigned char *ip = (unsigned char *)instptr;
32868+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
32869 my_trace->opcode = MMIO_UNKNOWN_OP;
32870 my_trace->width = 0;
32871 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
32872@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
32873 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32874 void __iomem *addr)
32875 {
32876- static atomic_t next_id;
32877+ static atomic_unchecked_t next_id;
32878 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
32879 /* These are page-unaligned. */
32880 struct mmiotrace_map map = {
32881@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32882 .private = trace
32883 },
32884 .phys = offset,
32885- .id = atomic_inc_return(&next_id)
32886+ .id = atomic_inc_return_unchecked(&next_id)
32887 };
32888 map.map_id = trace->id;
32889
32890@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
32891 ioremap_trace_core(offset, size, addr);
32892 }
32893
32894-static void iounmap_trace_core(volatile void __iomem *addr)
32895+static void iounmap_trace_core(const volatile void __iomem *addr)
32896 {
32897 struct mmiotrace_map map = {
32898 .phys = 0,
32899@@ -328,7 +328,7 @@ not_enabled:
32900 }
32901 }
32902
32903-void mmiotrace_iounmap(volatile void __iomem *addr)
32904+void mmiotrace_iounmap(const volatile void __iomem *addr)
32905 {
32906 might_sleep();
32907 if (is_enabled()) /* recheck and proper locking in *_core() */
32908diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
32909index 24aec58..c39fe8b 100644
32910--- a/arch/x86/mm/numa.c
32911+++ b/arch/x86/mm/numa.c
32912@@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
32913 return true;
32914 }
32915
32916-static int __init numa_register_memblks(struct numa_meminfo *mi)
32917+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
32918 {
32919 unsigned long uninitialized_var(pfn_align);
32920 int i, nid;
32921diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
32922index d0b1773..4c3327c 100644
32923--- a/arch/x86/mm/pageattr-test.c
32924+++ b/arch/x86/mm/pageattr-test.c
32925@@ -36,7 +36,7 @@ enum {
32926
32927 static int pte_testbit(pte_t pte)
32928 {
32929- return pte_flags(pte) & _PAGE_UNUSED1;
32930+ return pte_flags(pte) & _PAGE_CPA_TEST;
32931 }
32932
32933 struct split_state {
32934diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
32935index bb32480..75f2f5e 100644
32936--- a/arch/x86/mm/pageattr.c
32937+++ b/arch/x86/mm/pageattr.c
32938@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32939 */
32940 #ifdef CONFIG_PCI_BIOS
32941 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
32942- pgprot_val(forbidden) |= _PAGE_NX;
32943+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32944 #endif
32945
32946 /*
32947@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32948 * Does not cover __inittext since that is gone later on. On
32949 * 64bit we do not enforce !NX on the low mapping
32950 */
32951- if (within(address, (unsigned long)_text, (unsigned long)_etext))
32952- pgprot_val(forbidden) |= _PAGE_NX;
32953+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
32954+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32955
32956+#ifdef CONFIG_DEBUG_RODATA
32957 /*
32958 * The .rodata section needs to be read-only. Using the pfn
32959 * catches all aliases.
32960@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32961 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
32962 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
32963 pgprot_val(forbidden) |= _PAGE_RW;
32964+#endif
32965
32966 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
32967 /*
32968@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32969 }
32970 #endif
32971
32972+#ifdef CONFIG_PAX_KERNEXEC
32973+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
32974+ pgprot_val(forbidden) |= _PAGE_RW;
32975+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32976+ }
32977+#endif
32978+
32979 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
32980
32981 return prot;
32982@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
32983 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
32984 {
32985 /* change init_mm */
32986+ pax_open_kernel();
32987 set_pte_atomic(kpte, pte);
32988+
32989 #ifdef CONFIG_X86_32
32990 if (!SHARED_KERNEL_PMD) {
32991+
32992+#ifdef CONFIG_PAX_PER_CPU_PGD
32993+ unsigned long cpu;
32994+#else
32995 struct page *page;
32996+#endif
32997
32998+#ifdef CONFIG_PAX_PER_CPU_PGD
32999+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33000+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33001+#else
33002 list_for_each_entry(page, &pgd_list, lru) {
33003- pgd_t *pgd;
33004+ pgd_t *pgd = (pgd_t *)page_address(page);
33005+#endif
33006+
33007 pud_t *pud;
33008 pmd_t *pmd;
33009
33010- pgd = (pgd_t *)page_address(page) + pgd_index(address);
33011+ pgd += pgd_index(address);
33012 pud = pud_offset(pgd, address);
33013 pmd = pmd_offset(pud, address);
33014 set_pte_atomic((pte_t *)pmd, pte);
33015 }
33016 }
33017 #endif
33018+ pax_close_kernel();
33019 }
33020
33021 static int
33022diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33023index 6574388..87e9bef 100644
33024--- a/arch/x86/mm/pat.c
33025+++ b/arch/x86/mm/pat.c
33026@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33027
33028 if (!entry) {
33029 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33030- current->comm, current->pid, start, end - 1);
33031+ current->comm, task_pid_nr(current), start, end - 1);
33032 return -EINVAL;
33033 }
33034
33035@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33036
33037 while (cursor < to) {
33038 if (!devmem_is_allowed(pfn)) {
33039- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33040- current->comm, from, to - 1);
33041+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33042+ current->comm, from, to - 1, cursor);
33043 return 0;
33044 }
33045 cursor += PAGE_SIZE;
33046@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33047 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33048 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33049 "for [mem %#010Lx-%#010Lx]\n",
33050- current->comm, current->pid,
33051+ current->comm, task_pid_nr(current),
33052 cattr_name(flags),
33053 base, (unsigned long long)(base + size-1));
33054 return -EINVAL;
33055@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33056 flags = lookup_memtype(paddr);
33057 if (want_flags != flags) {
33058 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33059- current->comm, current->pid,
33060+ current->comm, task_pid_nr(current),
33061 cattr_name(want_flags),
33062 (unsigned long long)paddr,
33063 (unsigned long long)(paddr + size - 1),
33064@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33065 free_memtype(paddr, paddr + size);
33066 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33067 " for [mem %#010Lx-%#010Lx], got %s\n",
33068- current->comm, current->pid,
33069+ current->comm, task_pid_nr(current),
33070 cattr_name(want_flags),
33071 (unsigned long long)paddr,
33072 (unsigned long long)(paddr + size - 1),
33073diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33074index 415f6c4..d319983 100644
33075--- a/arch/x86/mm/pat_rbtree.c
33076+++ b/arch/x86/mm/pat_rbtree.c
33077@@ -160,7 +160,7 @@ success:
33078
33079 failure:
33080 printk(KERN_INFO "%s:%d conflicting memory types "
33081- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33082+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33083 end, cattr_name(found_type), cattr_name(match->type));
33084 return -EBUSY;
33085 }
33086diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33087index 9f0614d..92ae64a 100644
33088--- a/arch/x86/mm/pf_in.c
33089+++ b/arch/x86/mm/pf_in.c
33090@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33091 int i;
33092 enum reason_type rv = OTHERS;
33093
33094- p = (unsigned char *)ins_addr;
33095+ p = (unsigned char *)ktla_ktva(ins_addr);
33096 p += skip_prefix(p, &prf);
33097 p += get_opcode(p, &opcode);
33098
33099@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33100 struct prefix_bits prf;
33101 int i;
33102
33103- p = (unsigned char *)ins_addr;
33104+ p = (unsigned char *)ktla_ktva(ins_addr);
33105 p += skip_prefix(p, &prf);
33106 p += get_opcode(p, &opcode);
33107
33108@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33109 struct prefix_bits prf;
33110 int i;
33111
33112- p = (unsigned char *)ins_addr;
33113+ p = (unsigned char *)ktla_ktva(ins_addr);
33114 p += skip_prefix(p, &prf);
33115 p += get_opcode(p, &opcode);
33116
33117@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33118 struct prefix_bits prf;
33119 int i;
33120
33121- p = (unsigned char *)ins_addr;
33122+ p = (unsigned char *)ktla_ktva(ins_addr);
33123 p += skip_prefix(p, &prf);
33124 p += get_opcode(p, &opcode);
33125 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33126@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33127 struct prefix_bits prf;
33128 int i;
33129
33130- p = (unsigned char *)ins_addr;
33131+ p = (unsigned char *)ktla_ktva(ins_addr);
33132 p += skip_prefix(p, &prf);
33133 p += get_opcode(p, &opcode);
33134 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33135diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33136index c96314a..433b127 100644
33137--- a/arch/x86/mm/pgtable.c
33138+++ b/arch/x86/mm/pgtable.c
33139@@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33140 list_del(&page->lru);
33141 }
33142
33143-#define UNSHARED_PTRS_PER_PGD \
33144- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33145+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33146+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33147
33148+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33149+{
33150+ unsigned int count = USER_PGD_PTRS;
33151
33152+ if (!pax_user_shadow_base)
33153+ return;
33154+
33155+ while (count--)
33156+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33157+}
33158+#endif
33159+
33160+#ifdef CONFIG_PAX_PER_CPU_PGD
33161+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33162+{
33163+ unsigned int count = USER_PGD_PTRS;
33164+
33165+ while (count--) {
33166+ pgd_t pgd;
33167+
33168+#ifdef CONFIG_X86_64
33169+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33170+#else
33171+ pgd = *src++;
33172+#endif
33173+
33174+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33175+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33176+#endif
33177+
33178+ *dst++ = pgd;
33179+ }
33180+
33181+}
33182+#endif
33183+
33184+#ifdef CONFIG_X86_64
33185+#define pxd_t pud_t
33186+#define pyd_t pgd_t
33187+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33188+#define pgtable_pxd_page_ctor(page) true
33189+#define pgtable_pxd_page_dtor(page)
33190+#define pxd_free(mm, pud) pud_free((mm), (pud))
33191+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33192+#define pyd_offset(mm, address) pgd_offset((mm), (address))
33193+#define PYD_SIZE PGDIR_SIZE
33194+#else
33195+#define pxd_t pmd_t
33196+#define pyd_t pud_t
33197+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33198+#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33199+#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33200+#define pxd_free(mm, pud) pmd_free((mm), (pud))
33201+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33202+#define pyd_offset(mm, address) pud_offset((mm), (address))
33203+#define PYD_SIZE PUD_SIZE
33204+#endif
33205+
33206+#ifdef CONFIG_PAX_PER_CPU_PGD
33207+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33208+static inline void pgd_dtor(pgd_t *pgd) {}
33209+#else
33210 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33211 {
33212 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33213@@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33214 pgd_list_del(pgd);
33215 spin_unlock(&pgd_lock);
33216 }
33217+#endif
33218
33219 /*
33220 * List of all pgd's needed for non-PAE so it can invalidate entries
33221@@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33222 * -- nyc
33223 */
33224
33225-#ifdef CONFIG_X86_PAE
33226+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33227 /*
33228 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33229 * updating the top-level pagetable entries to guarantee the
33230@@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33231 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33232 * and initialize the kernel pmds here.
33233 */
33234-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33235+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33236
33237 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33238 {
33239@@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33240 */
33241 flush_tlb_mm(mm);
33242 }
33243+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33244+#define PREALLOCATED_PXDS USER_PGD_PTRS
33245 #else /* !CONFIG_X86_PAE */
33246
33247 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33248-#define PREALLOCATED_PMDS 0
33249+#define PREALLOCATED_PXDS 0
33250
33251 #endif /* CONFIG_X86_PAE */
33252
33253-static void free_pmds(pmd_t *pmds[])
33254+static void free_pxds(pxd_t *pxds[])
33255 {
33256 int i;
33257
33258- for(i = 0; i < PREALLOCATED_PMDS; i++)
33259- if (pmds[i]) {
33260- pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33261- free_page((unsigned long)pmds[i]);
33262+ for(i = 0; i < PREALLOCATED_PXDS; i++)
33263+ if (pxds[i]) {
33264+ pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33265+ free_page((unsigned long)pxds[i]);
33266 }
33267 }
33268
33269-static int preallocate_pmds(pmd_t *pmds[])
33270+static int preallocate_pxds(pxd_t *pxds[])
33271 {
33272 int i;
33273 bool failed = false;
33274
33275- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33276- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33277- if (!pmd)
33278+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33279+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33280+ if (!pxd)
33281 failed = true;
33282- if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33283- free_page((unsigned long)pmd);
33284- pmd = NULL;
33285+ if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33286+ free_page((unsigned long)pxd);
33287+ pxd = NULL;
33288 failed = true;
33289 }
33290- pmds[i] = pmd;
33291+ pxds[i] = pxd;
33292 }
33293
33294 if (failed) {
33295- free_pmds(pmds);
33296+ free_pxds(pxds);
33297 return -ENOMEM;
33298 }
33299
33300@@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33301 * preallocate which never got a corresponding vma will need to be
33302 * freed manually.
33303 */
33304-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33305+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33306 {
33307 int i;
33308
33309- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33310+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33311 pgd_t pgd = pgdp[i];
33312
33313 if (pgd_val(pgd) != 0) {
33314- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33315+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33316
33317- pgdp[i] = native_make_pgd(0);
33318+ set_pgd(pgdp + i, native_make_pgd(0));
33319
33320- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33321- pmd_free(mm, pmd);
33322+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33323+ pxd_free(mm, pxd);
33324 }
33325 }
33326 }
33327
33328-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33329+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33330 {
33331- pud_t *pud;
33332+ pyd_t *pyd;
33333 int i;
33334
33335- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33336+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33337 return;
33338
33339- pud = pud_offset(pgd, 0);
33340-
33341- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33342- pmd_t *pmd = pmds[i];
33343+#ifdef CONFIG_X86_64
33344+ pyd = pyd_offset(mm, 0L);
33345+#else
33346+ pyd = pyd_offset(pgd, 0L);
33347+#endif
33348
33349+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33350+ pxd_t *pxd = pxds[i];
33351 if (i >= KERNEL_PGD_BOUNDARY)
33352- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33353- sizeof(pmd_t) * PTRS_PER_PMD);
33354+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33355+ sizeof(pxd_t) * PTRS_PER_PMD);
33356
33357- pud_populate(mm, pud, pmd);
33358+ pyd_populate(mm, pyd, pxd);
33359 }
33360 }
33361
33362 pgd_t *pgd_alloc(struct mm_struct *mm)
33363 {
33364 pgd_t *pgd;
33365- pmd_t *pmds[PREALLOCATED_PMDS];
33366+ pxd_t *pxds[PREALLOCATED_PXDS];
33367
33368 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33369
33370@@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33371
33372 mm->pgd = pgd;
33373
33374- if (preallocate_pmds(pmds) != 0)
33375+ if (preallocate_pxds(pxds) != 0)
33376 goto out_free_pgd;
33377
33378 if (paravirt_pgd_alloc(mm) != 0)
33379- goto out_free_pmds;
33380+ goto out_free_pxds;
33381
33382 /*
33383 * Make sure that pre-populating the pmds is atomic with
33384@@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33385 spin_lock(&pgd_lock);
33386
33387 pgd_ctor(mm, pgd);
33388- pgd_prepopulate_pmd(mm, pgd, pmds);
33389+ pgd_prepopulate_pxd(mm, pgd, pxds);
33390
33391 spin_unlock(&pgd_lock);
33392
33393 return pgd;
33394
33395-out_free_pmds:
33396- free_pmds(pmds);
33397+out_free_pxds:
33398+ free_pxds(pxds);
33399 out_free_pgd:
33400 free_page((unsigned long)pgd);
33401 out:
33402@@ -313,7 +380,7 @@ out:
33403
33404 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33405 {
33406- pgd_mop_up_pmds(mm, pgd);
33407+ pgd_mop_up_pxds(mm, pgd);
33408 pgd_dtor(pgd);
33409 paravirt_pgd_free(mm, pgd);
33410 free_page((unsigned long)pgd);
33411diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33412index a69bcb8..19068ab 100644
33413--- a/arch/x86/mm/pgtable_32.c
33414+++ b/arch/x86/mm/pgtable_32.c
33415@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33416 return;
33417 }
33418 pte = pte_offset_kernel(pmd, vaddr);
33419+
33420+ pax_open_kernel();
33421 if (pte_val(pteval))
33422 set_pte_at(&init_mm, vaddr, pte, pteval);
33423 else
33424 pte_clear(&init_mm, vaddr, pte);
33425+ pax_close_kernel();
33426
33427 /*
33428 * It's enough to flush this one mapping.
33429diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33430index e666cbb..61788c45 100644
33431--- a/arch/x86/mm/physaddr.c
33432+++ b/arch/x86/mm/physaddr.c
33433@@ -10,7 +10,7 @@
33434 #ifdef CONFIG_X86_64
33435
33436 #ifdef CONFIG_DEBUG_VIRTUAL
33437-unsigned long __phys_addr(unsigned long x)
33438+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33439 {
33440 unsigned long y = x - __START_KERNEL_map;
33441
33442@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33443 #else
33444
33445 #ifdef CONFIG_DEBUG_VIRTUAL
33446-unsigned long __phys_addr(unsigned long x)
33447+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33448 {
33449 unsigned long phys_addr = x - PAGE_OFFSET;
33450 /* VMALLOC_* aren't constants */
33451diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33452index 90555bf..f5f1828 100644
33453--- a/arch/x86/mm/setup_nx.c
33454+++ b/arch/x86/mm/setup_nx.c
33455@@ -5,8 +5,10 @@
33456 #include <asm/pgtable.h>
33457 #include <asm/proto.h>
33458
33459+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33460 static int disable_nx;
33461
33462+#ifndef CONFIG_PAX_PAGEEXEC
33463 /*
33464 * noexec = on|off
33465 *
33466@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33467 return 0;
33468 }
33469 early_param("noexec", noexec_setup);
33470+#endif
33471+
33472+#endif
33473
33474 void x86_configure_nx(void)
33475 {
33476+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33477 if (cpu_has_nx && !disable_nx)
33478 __supported_pte_mask |= _PAGE_NX;
33479 else
33480+#endif
33481 __supported_pte_mask &= ~_PAGE_NX;
33482 }
33483
33484diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
33485index ae699b3..f1b2ad2 100644
33486--- a/arch/x86/mm/tlb.c
33487+++ b/arch/x86/mm/tlb.c
33488@@ -48,7 +48,11 @@ void leave_mm(int cpu)
33489 BUG();
33490 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
33491 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
33492+
33493+#ifndef CONFIG_PAX_PER_CPU_PGD
33494 load_cr3(swapper_pg_dir);
33495+#endif
33496+
33497 }
33498 }
33499 EXPORT_SYMBOL_GPL(leave_mm);
33500diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
33501new file mode 100644
33502index 0000000..dace51c
33503--- /dev/null
33504+++ b/arch/x86/mm/uderef_64.c
33505@@ -0,0 +1,37 @@
33506+#include <linux/mm.h>
33507+#include <asm/pgtable.h>
33508+#include <asm/uaccess.h>
33509+
33510+#ifdef CONFIG_PAX_MEMORY_UDEREF
33511+/* PaX: due to the special call convention these functions must
33512+ * - remain leaf functions under all configurations,
33513+ * - never be called directly, only dereferenced from the wrappers.
33514+ */
33515+void __pax_open_userland(void)
33516+{
33517+ unsigned int cpu;
33518+
33519+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33520+ return;
33521+
33522+ cpu = raw_get_cpu();
33523+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
33524+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
33525+ raw_put_cpu_no_resched();
33526+}
33527+EXPORT_SYMBOL(__pax_open_userland);
33528+
33529+void __pax_close_userland(void)
33530+{
33531+ unsigned int cpu;
33532+
33533+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33534+ return;
33535+
33536+ cpu = raw_get_cpu();
33537+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
33538+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
33539+ raw_put_cpu_no_resched();
33540+}
33541+EXPORT_SYMBOL(__pax_close_userland);
33542+#endif
33543diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
33544index 0149575..f746de8 100644
33545--- a/arch/x86/net/bpf_jit.S
33546+++ b/arch/x86/net/bpf_jit.S
33547@@ -9,6 +9,7 @@
33548 */
33549 #include <linux/linkage.h>
33550 #include <asm/dwarf2.h>
33551+#include <asm/alternative-asm.h>
33552
33553 /*
33554 * Calling convention :
33555@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33556 jle bpf_slow_path_word
33557 mov (SKBDATA,%rsi),%eax
33558 bswap %eax /* ntohl() */
33559+ pax_force_retaddr
33560 ret
33561
33562 sk_load_half:
33563@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
33564 jle bpf_slow_path_half
33565 movzwl (SKBDATA,%rsi),%eax
33566 rol $8,%ax # ntohs()
33567+ pax_force_retaddr
33568 ret
33569
33570 sk_load_byte:
33571@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
33572 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
33573 jle bpf_slow_path_byte
33574 movzbl (SKBDATA,%rsi),%eax
33575+ pax_force_retaddr
33576 ret
33577
33578 /**
33579@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
33580 movzbl (SKBDATA,%rsi),%ebx
33581 and $15,%bl
33582 shl $2,%bl
33583+ pax_force_retaddr
33584 ret
33585
33586 /* rsi contains offset and can be scratched */
33587@@ -109,6 +114,7 @@ bpf_slow_path_word:
33588 js bpf_error
33589 mov -12(%rbp),%eax
33590 bswap %eax
33591+ pax_force_retaddr
33592 ret
33593
33594 bpf_slow_path_half:
33595@@ -117,12 +123,14 @@ bpf_slow_path_half:
33596 mov -12(%rbp),%ax
33597 rol $8,%ax
33598 movzwl %ax,%eax
33599+ pax_force_retaddr
33600 ret
33601
33602 bpf_slow_path_byte:
33603 bpf_slow_path_common(1)
33604 js bpf_error
33605 movzbl -12(%rbp),%eax
33606+ pax_force_retaddr
33607 ret
33608
33609 bpf_slow_path_byte_msh:
33610@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33611 and $15,%al
33612 shl $2,%al
33613 xchg %eax,%ebx
33614+ pax_force_retaddr
33615 ret
33616
33617 #define sk_negative_common(SIZE) \
33618@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33619 sk_negative_common(4)
33620 mov (%rax), %eax
33621 bswap %eax
33622+ pax_force_retaddr
33623 ret
33624
33625 bpf_slow_path_half_neg:
33626@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33627 mov (%rax),%ax
33628 rol $8,%ax
33629 movzwl %ax,%eax
33630+ pax_force_retaddr
33631 ret
33632
33633 bpf_slow_path_byte_neg:
33634@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33635 .globl sk_load_byte_negative_offset
33636 sk_negative_common(1)
33637 movzbl (%rax), %eax
33638+ pax_force_retaddr
33639 ret
33640
33641 bpf_slow_path_byte_msh_neg:
33642@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33643 and $15,%al
33644 shl $2,%al
33645 xchg %eax,%ebx
33646+ pax_force_retaddr
33647 ret
33648
33649 bpf_error:
33650@@ -197,4 +210,5 @@ bpf_error:
33651 xor %eax,%eax
33652 mov -8(%rbp),%rbx
33653 leaveq
33654+ pax_force_retaddr
33655 ret
33656diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33657index 4ed75dd..3cf24f0b 100644
33658--- a/arch/x86/net/bpf_jit_comp.c
33659+++ b/arch/x86/net/bpf_jit_comp.c
33660@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33661 return ptr + len;
33662 }
33663
33664+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33665+#define MAX_INSTR_CODE_SIZE 96
33666+#else
33667+#define MAX_INSTR_CODE_SIZE 64
33668+#endif
33669+
33670 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33671
33672 #define EMIT1(b1) EMIT(b1, 1)
33673 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33674 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33675 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33676+
33677+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33678+/* original constant will appear in ecx */
33679+#define DILUTE_CONST_SEQUENCE(_off, _key) \
33680+do { \
33681+ /* mov ecx, randkey */ \
33682+ EMIT1(0xb9); \
33683+ EMIT(_key, 4); \
33684+ /* xor ecx, randkey ^ off */ \
33685+ EMIT2(0x81, 0xf1); \
33686+ EMIT((_key) ^ (_off), 4); \
33687+} while (0)
33688+
33689+#define EMIT1_off32(b1, _off) \
33690+do { \
33691+ switch (b1) { \
33692+ case 0x05: /* add eax, imm32 */ \
33693+ case 0x2d: /* sub eax, imm32 */ \
33694+ case 0x25: /* and eax, imm32 */ \
33695+ case 0x0d: /* or eax, imm32 */ \
33696+ case 0xb8: /* mov eax, imm32 */ \
33697+ case 0x35: /* xor eax, imm32 */ \
33698+ case 0x3d: /* cmp eax, imm32 */ \
33699+ case 0xa9: /* test eax, imm32 */ \
33700+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33701+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33702+ break; \
33703+ case 0xbb: /* mov ebx, imm32 */ \
33704+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33705+ /* mov ebx, ecx */ \
33706+ EMIT2(0x89, 0xcb); \
33707+ break; \
33708+ case 0xbe: /* mov esi, imm32 */ \
33709+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33710+ /* mov esi, ecx */ \
33711+ EMIT2(0x89, 0xce); \
33712+ break; \
33713+ case 0xe8: /* call rel imm32, always to known funcs */ \
33714+ EMIT1(b1); \
33715+ EMIT(_off, 4); \
33716+ break; \
33717+ case 0xe9: /* jmp rel imm32 */ \
33718+ EMIT1(b1); \
33719+ EMIT(_off, 4); \
33720+ /* prevent fall-through, we're not called if off = 0 */ \
33721+ EMIT(0xcccccccc, 4); \
33722+ EMIT(0xcccccccc, 4); \
33723+ break; \
33724+ default: \
33725+ BUILD_BUG(); \
33726+ } \
33727+} while (0)
33728+
33729+#define EMIT2_off32(b1, b2, _off) \
33730+do { \
33731+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33732+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33733+ EMIT(randkey, 4); \
33734+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33735+ EMIT((_off) - randkey, 4); \
33736+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33737+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33738+ /* imul eax, ecx */ \
33739+ EMIT3(0x0f, 0xaf, 0xc1); \
33740+ } else { \
33741+ BUILD_BUG(); \
33742+ } \
33743+} while (0)
33744+#else
33745 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33746+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33747+#endif
33748
33749 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33750 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33751@@ -91,6 +168,24 @@ do { \
33752 #define X86_JBE 0x76
33753 #define X86_JA 0x77
33754
33755+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33756+#define APPEND_FLOW_VERIFY() \
33757+do { \
33758+ /* mov ecx, randkey */ \
33759+ EMIT1(0xb9); \
33760+ EMIT(randkey, 4); \
33761+ /* cmp ecx, randkey */ \
33762+ EMIT2(0x81, 0xf9); \
33763+ EMIT(randkey, 4); \
33764+ /* jz after 8 int 3s */ \
33765+ EMIT2(0x74, 0x08); \
33766+ EMIT(0xcccccccc, 4); \
33767+ EMIT(0xcccccccc, 4); \
33768+} while (0)
33769+#else
33770+#define APPEND_FLOW_VERIFY() do { } while (0)
33771+#endif
33772+
33773 #define EMIT_COND_JMP(op, offset) \
33774 do { \
33775 if (is_near(offset)) \
33776@@ -98,6 +193,7 @@ do { \
33777 else { \
33778 EMIT2(0x0f, op + 0x10); \
33779 EMIT(offset, 4); /* jxx .+off32 */ \
33780+ APPEND_FLOW_VERIFY(); \
33781 } \
33782 } while (0)
33783
33784@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
33785 return -1;
33786 }
33787
33788-struct bpf_binary_header {
33789- unsigned int pages;
33790- /* Note : for security reasons, bpf code will follow a randomly
33791- * sized amount of int3 instructions
33792- */
33793- u8 image[];
33794-};
33795-
33796-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
33797+/* Note : for security reasons, bpf code will follow a randomly
33798+ * sized amount of int3 instructions
33799+ */
33800+static u8 *bpf_alloc_binary(unsigned int proglen,
33801 u8 **image_ptr)
33802 {
33803 unsigned int sz, hole;
33804- struct bpf_binary_header *header;
33805+ u8 *header;
33806
33807 /* Most of BPF filters are really small,
33808 * but if some of them fill a page, allow at least
33809 * 128 extra bytes to insert a random section of int3
33810 */
33811- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
33812- header = module_alloc(sz);
33813+ sz = round_up(proglen + 128, PAGE_SIZE);
33814+ header = module_alloc_exec(sz);
33815 if (!header)
33816 return NULL;
33817
33818+ pax_open_kernel();
33819 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
33820+ pax_close_kernel();
33821
33822- header->pages = sz / PAGE_SIZE;
33823- hole = sz - (proglen + sizeof(*header));
33824+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
33825
33826 /* insert a random number of int3 instructions before BPF code */
33827- *image_ptr = &header->image[prandom_u32() % hole];
33828+ *image_ptr = &header[prandom_u32() % hole];
33829 return header;
33830 }
33831
33832 void bpf_jit_compile(struct sk_filter *fp)
33833 {
33834- u8 temp[64];
33835+ u8 temp[MAX_INSTR_CODE_SIZE];
33836 u8 *prog;
33837 unsigned int proglen, oldproglen = 0;
33838 int ilen, i;
33839 int t_offset, f_offset;
33840 u8 t_op, f_op, seen = 0, pass;
33841 u8 *image = NULL;
33842- struct bpf_binary_header *header = NULL;
33843+ u8 *header = NULL;
33844 u8 *func;
33845 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
33846 unsigned int cleanup_addr; /* epilogue code offset */
33847 unsigned int *addrs;
33848 const struct sock_filter *filter = fp->insns;
33849 int flen = fp->len;
33850+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33851+ unsigned int randkey;
33852+#endif
33853
33854 if (!bpf_jit_enable)
33855 return;
33856@@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
33857 return;
33858
33859 /* Before first pass, make a rough estimation of addrs[]
33860- * each bpf instruction is translated to less than 64 bytes
33861+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
33862 */
33863 for (proglen = 0, i = 0; i < flen; i++) {
33864- proglen += 64;
33865+ proglen += MAX_INSTR_CODE_SIZE;
33866 addrs[i] = proglen;
33867 }
33868 cleanup_addr = proglen; /* epilogue address */
33869@@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
33870 for (i = 0; i < flen; i++) {
33871 unsigned int K = filter[i].k;
33872
33873+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33874+ randkey = prandom_u32();
33875+#endif
33876+
33877 switch (filter[i].code) {
33878 case BPF_S_ALU_ADD_X: /* A += X; */
33879 seen |= SEEN_XREG;
33880@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
33881 case BPF_S_ALU_MUL_K: /* A *= K */
33882 if (is_imm8(K))
33883 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
33884- else {
33885- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
33886- EMIT(K, 4);
33887- }
33888+ else
33889+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
33890 break;
33891 case BPF_S_ALU_DIV_X: /* A /= X; */
33892 seen |= SEEN_XREG;
33893@@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33894 break;
33895 }
33896 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33897+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33898+ DILUTE_CONST_SEQUENCE(K, randkey);
33899+#else
33900 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33901+#endif
33902 EMIT2(0xf7, 0xf1); /* div %ecx */
33903 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
33904 break;
33905@@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33906 if (K == 1)
33907 break;
33908 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33909+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33910+ DILUTE_CONST_SEQUENCE(K, randkey);
33911+#else
33912 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33913+#endif
33914 EMIT2(0xf7, 0xf1); /* div %ecx */
33915 break;
33916 case BPF_S_ALU_AND_X:
33917@@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
33918 if (is_imm8(K)) {
33919 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
33920 } else {
33921- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
33922- EMIT(K, 4);
33923+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
33924 }
33925 } else {
33926 EMIT2(0x89,0xde); /* mov %ebx,%esi */
33927@@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33928 if (unlikely(proglen + ilen > oldproglen)) {
33929 pr_err("bpb_jit_compile fatal error\n");
33930 kfree(addrs);
33931- module_free(NULL, header);
33932+ module_free_exec(NULL, image);
33933 return;
33934 }
33935+ pax_open_kernel();
33936 memcpy(image + proglen, temp, ilen);
33937+ pax_close_kernel();
33938 }
33939 proglen += ilen;
33940 addrs[i] = proglen;
33941@@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33942
33943 if (image) {
33944 bpf_flush_icache(header, image + proglen);
33945- set_memory_ro((unsigned long)header, header->pages);
33946 fp->bpf_func = (void *)image;
33947 }
33948 out:
33949@@ -782,10 +887,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
33950 {
33951 struct sk_filter *fp = container_of(work, struct sk_filter, work);
33952 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
33953- struct bpf_binary_header *header = (void *)addr;
33954
33955- set_memory_rw(addr, header->pages);
33956- module_free(NULL, header);
33957+ set_memory_rw(addr, 1);
33958+ module_free_exec(NULL, (void *)addr);
33959 kfree(fp);
33960 }
33961
33962diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
33963index 5d04be5..2beeaa2 100644
33964--- a/arch/x86/oprofile/backtrace.c
33965+++ b/arch/x86/oprofile/backtrace.c
33966@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
33967 struct stack_frame_ia32 *fp;
33968 unsigned long bytes;
33969
33970- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33971+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33972 if (bytes != 0)
33973 return NULL;
33974
33975- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
33976+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
33977
33978 oprofile_add_trace(bufhead[0].return_address);
33979
33980@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
33981 struct stack_frame bufhead[2];
33982 unsigned long bytes;
33983
33984- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33985+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33986 if (bytes != 0)
33987 return NULL;
33988
33989@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
33990 {
33991 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
33992
33993- if (!user_mode_vm(regs)) {
33994+ if (!user_mode(regs)) {
33995 unsigned long stack = kernel_stack_pointer(regs);
33996 if (depth)
33997 dump_trace(NULL, regs, (unsigned long *)stack, 0,
33998diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
33999index 6890d84..1dad1f1 100644
34000--- a/arch/x86/oprofile/nmi_int.c
34001+++ b/arch/x86/oprofile/nmi_int.c
34002@@ -23,6 +23,7 @@
34003 #include <asm/nmi.h>
34004 #include <asm/msr.h>
34005 #include <asm/apic.h>
34006+#include <asm/pgtable.h>
34007
34008 #include "op_counter.h"
34009 #include "op_x86_model.h"
34010@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34011 if (ret)
34012 return ret;
34013
34014- if (!model->num_virt_counters)
34015- model->num_virt_counters = model->num_counters;
34016+ if (!model->num_virt_counters) {
34017+ pax_open_kernel();
34018+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
34019+ pax_close_kernel();
34020+ }
34021
34022 mux_init(ops);
34023
34024diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34025index 50d86c0..7985318 100644
34026--- a/arch/x86/oprofile/op_model_amd.c
34027+++ b/arch/x86/oprofile/op_model_amd.c
34028@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34029 num_counters = AMD64_NUM_COUNTERS;
34030 }
34031
34032- op_amd_spec.num_counters = num_counters;
34033- op_amd_spec.num_controls = num_counters;
34034- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34035+ pax_open_kernel();
34036+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34037+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34038+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34039+ pax_close_kernel();
34040
34041 return 0;
34042 }
34043diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34044index d90528e..0127e2b 100644
34045--- a/arch/x86/oprofile/op_model_ppro.c
34046+++ b/arch/x86/oprofile/op_model_ppro.c
34047@@ -19,6 +19,7 @@
34048 #include <asm/msr.h>
34049 #include <asm/apic.h>
34050 #include <asm/nmi.h>
34051+#include <asm/pgtable.h>
34052
34053 #include "op_x86_model.h"
34054 #include "op_counter.h"
34055@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34056
34057 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34058
34059- op_arch_perfmon_spec.num_counters = num_counters;
34060- op_arch_perfmon_spec.num_controls = num_counters;
34061+ pax_open_kernel();
34062+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34063+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34064+ pax_close_kernel();
34065 }
34066
34067 static int arch_perfmon_init(struct oprofile_operations *ignore)
34068diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34069index 71e8a67..6a313bb 100644
34070--- a/arch/x86/oprofile/op_x86_model.h
34071+++ b/arch/x86/oprofile/op_x86_model.h
34072@@ -52,7 +52,7 @@ struct op_x86_model_spec {
34073 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34074 struct op_msrs const * const msrs);
34075 #endif
34076-};
34077+} __do_const;
34078
34079 struct op_counter_config;
34080
34081diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34082index 51384ca..a25f51e 100644
34083--- a/arch/x86/pci/intel_mid_pci.c
34084+++ b/arch/x86/pci/intel_mid_pci.c
34085@@ -241,7 +241,7 @@ int __init intel_mid_pci_init(void)
34086 pr_info("Intel MID platform detected, using MID PCI ops\n");
34087 pci_mmcfg_late_init();
34088 pcibios_enable_irq = intel_mid_pci_irq_enable;
34089- pci_root_ops = intel_mid_pci_ops;
34090+ memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34091 pci_soc_mode = 1;
34092 /* Continue with standard init */
34093 return 1;
34094diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34095index 372e9b8..e775a6c 100644
34096--- a/arch/x86/pci/irq.c
34097+++ b/arch/x86/pci/irq.c
34098@@ -50,7 +50,7 @@ struct irq_router {
34099 struct irq_router_handler {
34100 u16 vendor;
34101 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34102-};
34103+} __do_const;
34104
34105 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34106 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
34107@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34108 return 0;
34109 }
34110
34111-static __initdata struct irq_router_handler pirq_routers[] = {
34112+static __initconst const struct irq_router_handler pirq_routers[] = {
34113 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34114 { PCI_VENDOR_ID_AL, ali_router_probe },
34115 { PCI_VENDOR_ID_ITE, ite_router_probe },
34116@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
34117 static void __init pirq_find_router(struct irq_router *r)
34118 {
34119 struct irq_routing_table *rt = pirq_table;
34120- struct irq_router_handler *h;
34121+ const struct irq_router_handler *h;
34122
34123 #ifdef CONFIG_PCI_BIOS
34124 if (!rt->signature) {
34125@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34126 return 0;
34127 }
34128
34129-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34130+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34131 {
34132 .callback = fix_broken_hp_bios_irq9,
34133 .ident = "HP Pavilion N5400 Series Laptop",
34134diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34135index c77b24a..c979855 100644
34136--- a/arch/x86/pci/pcbios.c
34137+++ b/arch/x86/pci/pcbios.c
34138@@ -79,7 +79,7 @@ union bios32 {
34139 static struct {
34140 unsigned long address;
34141 unsigned short segment;
34142-} bios32_indirect = { 0, __KERNEL_CS };
34143+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
34144
34145 /*
34146 * Returns the entry point for the given service, NULL on error
34147@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
34148 unsigned long length; /* %ecx */
34149 unsigned long entry; /* %edx */
34150 unsigned long flags;
34151+ struct desc_struct d, *gdt;
34152
34153 local_irq_save(flags);
34154- __asm__("lcall *(%%edi); cld"
34155+
34156+ gdt = get_cpu_gdt_table(smp_processor_id());
34157+
34158+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34159+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34160+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34161+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34162+
34163+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34164 : "=a" (return_code),
34165 "=b" (address),
34166 "=c" (length),
34167 "=d" (entry)
34168 : "0" (service),
34169 "1" (0),
34170- "D" (&bios32_indirect));
34171+ "D" (&bios32_indirect),
34172+ "r"(__PCIBIOS_DS)
34173+ : "memory");
34174+
34175+ pax_open_kernel();
34176+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34177+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34178+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34179+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34180+ pax_close_kernel();
34181+
34182 local_irq_restore(flags);
34183
34184 switch (return_code) {
34185- case 0:
34186- return address + entry;
34187- case 0x80: /* Not present */
34188- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34189- return 0;
34190- default: /* Shouldn't happen */
34191- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34192- service, return_code);
34193+ case 0: {
34194+ int cpu;
34195+ unsigned char flags;
34196+
34197+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34198+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34199+ printk(KERN_WARNING "bios32_service: not valid\n");
34200 return 0;
34201+ }
34202+ address = address + PAGE_OFFSET;
34203+ length += 16UL; /* some BIOSs underreport this... */
34204+ flags = 4;
34205+ if (length >= 64*1024*1024) {
34206+ length >>= PAGE_SHIFT;
34207+ flags |= 8;
34208+ }
34209+
34210+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34211+ gdt = get_cpu_gdt_table(cpu);
34212+ pack_descriptor(&d, address, length, 0x9b, flags);
34213+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34214+ pack_descriptor(&d, address, length, 0x93, flags);
34215+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34216+ }
34217+ return entry;
34218+ }
34219+ case 0x80: /* Not present */
34220+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34221+ return 0;
34222+ default: /* Shouldn't happen */
34223+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34224+ service, return_code);
34225+ return 0;
34226 }
34227 }
34228
34229 static struct {
34230 unsigned long address;
34231 unsigned short segment;
34232-} pci_indirect = { 0, __KERNEL_CS };
34233+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34234
34235-static int pci_bios_present;
34236+static int pci_bios_present __read_only;
34237
34238 static int check_pcibios(void)
34239 {
34240@@ -131,11 +174,13 @@ static int check_pcibios(void)
34241 unsigned long flags, pcibios_entry;
34242
34243 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34244- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34245+ pci_indirect.address = pcibios_entry;
34246
34247 local_irq_save(flags);
34248- __asm__(
34249- "lcall *(%%edi); cld\n\t"
34250+ __asm__("movw %w6, %%ds\n\t"
34251+ "lcall *%%ss:(%%edi); cld\n\t"
34252+ "push %%ss\n\t"
34253+ "pop %%ds\n\t"
34254 "jc 1f\n\t"
34255 "xor %%ah, %%ah\n"
34256 "1:"
34257@@ -144,7 +189,8 @@ static int check_pcibios(void)
34258 "=b" (ebx),
34259 "=c" (ecx)
34260 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34261- "D" (&pci_indirect)
34262+ "D" (&pci_indirect),
34263+ "r" (__PCIBIOS_DS)
34264 : "memory");
34265 local_irq_restore(flags);
34266
34267@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34268
34269 switch (len) {
34270 case 1:
34271- __asm__("lcall *(%%esi); cld\n\t"
34272+ __asm__("movw %w6, %%ds\n\t"
34273+ "lcall *%%ss:(%%esi); cld\n\t"
34274+ "push %%ss\n\t"
34275+ "pop %%ds\n\t"
34276 "jc 1f\n\t"
34277 "xor %%ah, %%ah\n"
34278 "1:"
34279@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34280 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34281 "b" (bx),
34282 "D" ((long)reg),
34283- "S" (&pci_indirect));
34284+ "S" (&pci_indirect),
34285+ "r" (__PCIBIOS_DS));
34286 /*
34287 * Zero-extend the result beyond 8 bits, do not trust the
34288 * BIOS having done it:
34289@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34290 *value &= 0xff;
34291 break;
34292 case 2:
34293- __asm__("lcall *(%%esi); cld\n\t"
34294+ __asm__("movw %w6, %%ds\n\t"
34295+ "lcall *%%ss:(%%esi); cld\n\t"
34296+ "push %%ss\n\t"
34297+ "pop %%ds\n\t"
34298 "jc 1f\n\t"
34299 "xor %%ah, %%ah\n"
34300 "1:"
34301@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34302 : "1" (PCIBIOS_READ_CONFIG_WORD),
34303 "b" (bx),
34304 "D" ((long)reg),
34305- "S" (&pci_indirect));
34306+ "S" (&pci_indirect),
34307+ "r" (__PCIBIOS_DS));
34308 /*
34309 * Zero-extend the result beyond 16 bits, do not trust the
34310 * BIOS having done it:
34311@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34312 *value &= 0xffff;
34313 break;
34314 case 4:
34315- __asm__("lcall *(%%esi); cld\n\t"
34316+ __asm__("movw %w6, %%ds\n\t"
34317+ "lcall *%%ss:(%%esi); cld\n\t"
34318+ "push %%ss\n\t"
34319+ "pop %%ds\n\t"
34320 "jc 1f\n\t"
34321 "xor %%ah, %%ah\n"
34322 "1:"
34323@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34324 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34325 "b" (bx),
34326 "D" ((long)reg),
34327- "S" (&pci_indirect));
34328+ "S" (&pci_indirect),
34329+ "r" (__PCIBIOS_DS));
34330 break;
34331 }
34332
34333@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34334
34335 switch (len) {
34336 case 1:
34337- __asm__("lcall *(%%esi); cld\n\t"
34338+ __asm__("movw %w6, %%ds\n\t"
34339+ "lcall *%%ss:(%%esi); cld\n\t"
34340+ "push %%ss\n\t"
34341+ "pop %%ds\n\t"
34342 "jc 1f\n\t"
34343 "xor %%ah, %%ah\n"
34344 "1:"
34345@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34346 "c" (value),
34347 "b" (bx),
34348 "D" ((long)reg),
34349- "S" (&pci_indirect));
34350+ "S" (&pci_indirect),
34351+ "r" (__PCIBIOS_DS));
34352 break;
34353 case 2:
34354- __asm__("lcall *(%%esi); cld\n\t"
34355+ __asm__("movw %w6, %%ds\n\t"
34356+ "lcall *%%ss:(%%esi); cld\n\t"
34357+ "push %%ss\n\t"
34358+ "pop %%ds\n\t"
34359 "jc 1f\n\t"
34360 "xor %%ah, %%ah\n"
34361 "1:"
34362@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34363 "c" (value),
34364 "b" (bx),
34365 "D" ((long)reg),
34366- "S" (&pci_indirect));
34367+ "S" (&pci_indirect),
34368+ "r" (__PCIBIOS_DS));
34369 break;
34370 case 4:
34371- __asm__("lcall *(%%esi); cld\n\t"
34372+ __asm__("movw %w6, %%ds\n\t"
34373+ "lcall *%%ss:(%%esi); cld\n\t"
34374+ "push %%ss\n\t"
34375+ "pop %%ds\n\t"
34376 "jc 1f\n\t"
34377 "xor %%ah, %%ah\n"
34378 "1:"
34379@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34380 "c" (value),
34381 "b" (bx),
34382 "D" ((long)reg),
34383- "S" (&pci_indirect));
34384+ "S" (&pci_indirect),
34385+ "r" (__PCIBIOS_DS));
34386 break;
34387 }
34388
34389@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34390
34391 DBG("PCI: Fetching IRQ routing table... ");
34392 __asm__("push %%es\n\t"
34393+ "movw %w8, %%ds\n\t"
34394 "push %%ds\n\t"
34395 "pop %%es\n\t"
34396- "lcall *(%%esi); cld\n\t"
34397+ "lcall *%%ss:(%%esi); cld\n\t"
34398 "pop %%es\n\t"
34399+ "push %%ss\n\t"
34400+ "pop %%ds\n"
34401 "jc 1f\n\t"
34402 "xor %%ah, %%ah\n"
34403 "1:"
34404@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34405 "1" (0),
34406 "D" ((long) &opt),
34407 "S" (&pci_indirect),
34408- "m" (opt)
34409+ "m" (opt),
34410+ "r" (__PCIBIOS_DS)
34411 : "memory");
34412 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34413 if (ret & 0xff00)
34414@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34415 {
34416 int ret;
34417
34418- __asm__("lcall *(%%esi); cld\n\t"
34419+ __asm__("movw %w5, %%ds\n\t"
34420+ "lcall *%%ss:(%%esi); cld\n\t"
34421+ "push %%ss\n\t"
34422+ "pop %%ds\n"
34423 "jc 1f\n\t"
34424 "xor %%ah, %%ah\n"
34425 "1:"
34426@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34427 : "0" (PCIBIOS_SET_PCI_HW_INT),
34428 "b" ((dev->bus->number << 8) | dev->devfn),
34429 "c" ((irq << 8) | (pin + 10)),
34430- "S" (&pci_indirect));
34431+ "S" (&pci_indirect),
34432+ "r" (__PCIBIOS_DS));
34433 return !(ret & 0xff00);
34434 }
34435 EXPORT_SYMBOL(pcibios_set_irq_routing);
34436diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34437index 40e4469..d915bf9 100644
34438--- a/arch/x86/platform/efi/efi_32.c
34439+++ b/arch/x86/platform/efi/efi_32.c
34440@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
34441 {
34442 struct desc_ptr gdt_descr;
34443
34444+#ifdef CONFIG_PAX_KERNEXEC
34445+ struct desc_struct d;
34446+#endif
34447+
34448 local_irq_save(efi_rt_eflags);
34449
34450 load_cr3(initial_page_table);
34451 __flush_tlb_all();
34452
34453+#ifdef CONFIG_PAX_KERNEXEC
34454+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34455+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34456+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34457+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34458+#endif
34459+
34460 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34461 gdt_descr.size = GDT_SIZE - 1;
34462 load_gdt(&gdt_descr);
34463@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
34464 {
34465 struct desc_ptr gdt_descr;
34466
34467+#ifdef CONFIG_PAX_KERNEXEC
34468+ struct desc_struct d;
34469+
34470+ memset(&d, 0, sizeof d);
34471+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34472+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34473+#endif
34474+
34475 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34476 gdt_descr.size = GDT_SIZE - 1;
34477 load_gdt(&gdt_descr);
34478
34479+#ifdef CONFIG_PAX_PER_CPU_PGD
34480+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34481+#else
34482 load_cr3(swapper_pg_dir);
34483+#endif
34484+
34485 __flush_tlb_all();
34486
34487 local_irq_restore(efi_rt_eflags);
34488diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34489index 39a0e7f1..872396e 100644
34490--- a/arch/x86/platform/efi/efi_64.c
34491+++ b/arch/x86/platform/efi/efi_64.c
34492@@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
34493 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34494 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34495 }
34496+
34497+#ifdef CONFIG_PAX_PER_CPU_PGD
34498+ load_cr3(swapper_pg_dir);
34499+#endif
34500+
34501 __flush_tlb_all();
34502 }
34503
34504@@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
34505 for (pgd = 0; pgd < n_pgds; pgd++)
34506 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34507 kfree(save_pgd);
34508+
34509+#ifdef CONFIG_PAX_PER_CPU_PGD
34510+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34511+#endif
34512+
34513 __flush_tlb_all();
34514 local_irq_restore(efi_flags);
34515 early_code_mapping_set_exec(0);
34516diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34517index fbe66e6..eae5e38 100644
34518--- a/arch/x86/platform/efi/efi_stub_32.S
34519+++ b/arch/x86/platform/efi/efi_stub_32.S
34520@@ -6,7 +6,9 @@
34521 */
34522
34523 #include <linux/linkage.h>
34524+#include <linux/init.h>
34525 #include <asm/page_types.h>
34526+#include <asm/segment.h>
34527
34528 /*
34529 * efi_call_phys(void *, ...) is a function with variable parameters.
34530@@ -20,7 +22,7 @@
34531 * service functions will comply with gcc calling convention, too.
34532 */
34533
34534-.text
34535+__INIT
34536 ENTRY(efi_call_phys)
34537 /*
34538 * 0. The function can only be called in Linux kernel. So CS has been
34539@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34540 * The mapping of lower virtual memory has been created in prelog and
34541 * epilog.
34542 */
34543- movl $1f, %edx
34544- subl $__PAGE_OFFSET, %edx
34545- jmp *%edx
34546+#ifdef CONFIG_PAX_KERNEXEC
34547+ movl $(__KERNEXEC_EFI_DS), %edx
34548+ mov %edx, %ds
34549+ mov %edx, %es
34550+ mov %edx, %ss
34551+ addl $2f,(1f)
34552+ ljmp *(1f)
34553+
34554+__INITDATA
34555+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34556+.previous
34557+
34558+2:
34559+ subl $2b,(1b)
34560+#else
34561+ jmp 1f-__PAGE_OFFSET
34562 1:
34563+#endif
34564
34565 /*
34566 * 2. Now on the top of stack is the return
34567@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34568 * parameter 2, ..., param n. To make things easy, we save the return
34569 * address of efi_call_phys in a global variable.
34570 */
34571- popl %edx
34572- movl %edx, saved_return_addr
34573- /* get the function pointer into ECX*/
34574- popl %ecx
34575- movl %ecx, efi_rt_function_ptr
34576- movl $2f, %edx
34577- subl $__PAGE_OFFSET, %edx
34578- pushl %edx
34579+ popl (saved_return_addr)
34580+ popl (efi_rt_function_ptr)
34581
34582 /*
34583 * 3. Clear PG bit in %CR0.
34584@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34585 /*
34586 * 5. Call the physical function.
34587 */
34588- jmp *%ecx
34589+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
34590
34591-2:
34592 /*
34593 * 6. After EFI runtime service returns, control will return to
34594 * following instruction. We'd better readjust stack pointer first.
34595@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34596 movl %cr0, %edx
34597 orl $0x80000000, %edx
34598 movl %edx, %cr0
34599- jmp 1f
34600-1:
34601+
34602 /*
34603 * 8. Now restore the virtual mode from flat mode by
34604 * adding EIP with PAGE_OFFSET.
34605 */
34606- movl $1f, %edx
34607- jmp *%edx
34608+#ifdef CONFIG_PAX_KERNEXEC
34609+ movl $(__KERNEL_DS), %edx
34610+ mov %edx, %ds
34611+ mov %edx, %es
34612+ mov %edx, %ss
34613+ ljmp $(__KERNEL_CS),$1f
34614+#else
34615+ jmp 1f+__PAGE_OFFSET
34616+#endif
34617 1:
34618
34619 /*
34620 * 9. Balance the stack. And because EAX contain the return value,
34621 * we'd better not clobber it.
34622 */
34623- leal efi_rt_function_ptr, %edx
34624- movl (%edx), %ecx
34625- pushl %ecx
34626+ pushl (efi_rt_function_ptr)
34627
34628 /*
34629- * 10. Push the saved return address onto the stack and return.
34630+ * 10. Return to the saved return address.
34631 */
34632- leal saved_return_addr, %edx
34633- movl (%edx), %ecx
34634- pushl %ecx
34635- ret
34636+ jmpl *(saved_return_addr)
34637 ENDPROC(efi_call_phys)
34638 .previous
34639
34640-.data
34641+__INITDATA
34642 saved_return_addr:
34643 .long 0
34644 efi_rt_function_ptr:
34645diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34646index 4c07cca..2c8427d 100644
34647--- a/arch/x86/platform/efi/efi_stub_64.S
34648+++ b/arch/x86/platform/efi/efi_stub_64.S
34649@@ -7,6 +7,7 @@
34650 */
34651
34652 #include <linux/linkage.h>
34653+#include <asm/alternative-asm.h>
34654
34655 #define SAVE_XMM \
34656 mov %rsp, %rax; \
34657@@ -40,6 +41,7 @@ ENTRY(efi_call0)
34658 call *%rdi
34659 addq $32, %rsp
34660 RESTORE_XMM
34661+ pax_force_retaddr 0, 1
34662 ret
34663 ENDPROC(efi_call0)
34664
34665@@ -50,6 +52,7 @@ ENTRY(efi_call1)
34666 call *%rdi
34667 addq $32, %rsp
34668 RESTORE_XMM
34669+ pax_force_retaddr 0, 1
34670 ret
34671 ENDPROC(efi_call1)
34672
34673@@ -60,6 +63,7 @@ ENTRY(efi_call2)
34674 call *%rdi
34675 addq $32, %rsp
34676 RESTORE_XMM
34677+ pax_force_retaddr 0, 1
34678 ret
34679 ENDPROC(efi_call2)
34680
34681@@ -71,6 +75,7 @@ ENTRY(efi_call3)
34682 call *%rdi
34683 addq $32, %rsp
34684 RESTORE_XMM
34685+ pax_force_retaddr 0, 1
34686 ret
34687 ENDPROC(efi_call3)
34688
34689@@ -83,6 +88,7 @@ ENTRY(efi_call4)
34690 call *%rdi
34691 addq $32, %rsp
34692 RESTORE_XMM
34693+ pax_force_retaddr 0, 1
34694 ret
34695 ENDPROC(efi_call4)
34696
34697@@ -96,6 +102,7 @@ ENTRY(efi_call5)
34698 call *%rdi
34699 addq $48, %rsp
34700 RESTORE_XMM
34701+ pax_force_retaddr 0, 1
34702 ret
34703 ENDPROC(efi_call5)
34704
34705@@ -112,5 +119,6 @@ ENTRY(efi_call6)
34706 call *%rdi
34707 addq $48, %rsp
34708 RESTORE_XMM
34709+ pax_force_retaddr 0, 1
34710 ret
34711 ENDPROC(efi_call6)
34712diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34713index f90e290..435f0dd 100644
34714--- a/arch/x86/platform/intel-mid/intel-mid.c
34715+++ b/arch/x86/platform/intel-mid/intel-mid.c
34716@@ -65,9 +65,10 @@ static void intel_mid_power_off(void)
34717 {
34718 }
34719
34720-static void intel_mid_reboot(void)
34721+static void __noreturn intel_mid_reboot(void)
34722 {
34723 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34724+ BUG();
34725 }
34726
34727 static unsigned long __init intel_mid_calibrate_tsc(void)
34728diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34729index d6ee929..3637cb5 100644
34730--- a/arch/x86/platform/olpc/olpc_dt.c
34731+++ b/arch/x86/platform/olpc/olpc_dt.c
34732@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34733 return res;
34734 }
34735
34736-static struct of_pdt_ops prom_olpc_ops __initdata = {
34737+static struct of_pdt_ops prom_olpc_ops __initconst = {
34738 .nextprop = olpc_dt_nextprop,
34739 .getproplen = olpc_dt_getproplen,
34740 .getproperty = olpc_dt_getproperty,
34741diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34742index 424f4c9..f2a2988 100644
34743--- a/arch/x86/power/cpu.c
34744+++ b/arch/x86/power/cpu.c
34745@@ -137,11 +137,8 @@ static void do_fpu_end(void)
34746 static void fix_processor_context(void)
34747 {
34748 int cpu = smp_processor_id();
34749- struct tss_struct *t = &per_cpu(init_tss, cpu);
34750-#ifdef CONFIG_X86_64
34751- struct desc_struct *desc = get_cpu_gdt_table(cpu);
34752- tss_desc tss;
34753-#endif
34754+ struct tss_struct *t = init_tss + cpu;
34755+
34756 set_tss_desc(cpu, t); /*
34757 * This just modifies memory; should not be
34758 * necessary. But... This is necessary, because
34759@@ -150,10 +147,6 @@ static void fix_processor_context(void)
34760 */
34761
34762 #ifdef CONFIG_X86_64
34763- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
34764- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
34765- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
34766-
34767 syscall_init(); /* This sets MSR_*STAR and related */
34768 #endif
34769 load_TR_desc(); /* This does ltr */
34770diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
34771index a44f457..9140171 100644
34772--- a/arch/x86/realmode/init.c
34773+++ b/arch/x86/realmode/init.c
34774@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
34775 __va(real_mode_header->trampoline_header);
34776
34777 #ifdef CONFIG_X86_32
34778- trampoline_header->start = __pa_symbol(startup_32_smp);
34779+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
34780+
34781+#ifdef CONFIG_PAX_KERNEXEC
34782+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
34783+#endif
34784+
34785+ trampoline_header->boot_cs = __BOOT_CS;
34786 trampoline_header->gdt_limit = __BOOT_DS + 7;
34787 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
34788 #else
34789@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
34790 *trampoline_cr4_features = read_cr4();
34791
34792 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
34793- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
34794+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
34795 trampoline_pgd[511] = init_level4_pgt[511].pgd;
34796 #endif
34797 }
34798diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
34799index 9cac825..4890b25 100644
34800--- a/arch/x86/realmode/rm/Makefile
34801+++ b/arch/x86/realmode/rm/Makefile
34802@@ -79,5 +79,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
34803 $(call cc-option, -fno-unit-at-a-time)) \
34804 $(call cc-option, -fno-stack-protector) \
34805 $(call cc-option, -mpreferred-stack-boundary=2)
34806+ifdef CONSTIFY_PLUGIN
34807+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
34808+endif
34809 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
34810 GCOV_PROFILE := n
34811diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
34812index a28221d..93c40f1 100644
34813--- a/arch/x86/realmode/rm/header.S
34814+++ b/arch/x86/realmode/rm/header.S
34815@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
34816 #endif
34817 /* APM/BIOS reboot */
34818 .long pa_machine_real_restart_asm
34819-#ifdef CONFIG_X86_64
34820+#ifdef CONFIG_X86_32
34821+ .long __KERNEL_CS
34822+#else
34823 .long __KERNEL32_CS
34824 #endif
34825 END(real_mode_header)
34826diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
34827index c1b2791..f9e31c7 100644
34828--- a/arch/x86/realmode/rm/trampoline_32.S
34829+++ b/arch/x86/realmode/rm/trampoline_32.S
34830@@ -25,6 +25,12 @@
34831 #include <asm/page_types.h>
34832 #include "realmode.h"
34833
34834+#ifdef CONFIG_PAX_KERNEXEC
34835+#define ta(X) (X)
34836+#else
34837+#define ta(X) (pa_ ## X)
34838+#endif
34839+
34840 .text
34841 .code16
34842
34843@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
34844
34845 cli # We should be safe anyway
34846
34847- movl tr_start, %eax # where we need to go
34848-
34849 movl $0xA5A5A5A5, trampoline_status
34850 # write marker for master knows we're running
34851
34852@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
34853 movw $1, %dx # protected mode (PE) bit
34854 lmsw %dx # into protected mode
34855
34856- ljmpl $__BOOT_CS, $pa_startup_32
34857+ ljmpl *(trampoline_header)
34858
34859 .section ".text32","ax"
34860 .code32
34861@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
34862 .balign 8
34863 GLOBAL(trampoline_header)
34864 tr_start: .space 4
34865- tr_gdt_pad: .space 2
34866+ tr_boot_cs: .space 2
34867 tr_gdt: .space 6
34868 END(trampoline_header)
34869
34870diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
34871index bb360dc..d0fd8f8 100644
34872--- a/arch/x86/realmode/rm/trampoline_64.S
34873+++ b/arch/x86/realmode/rm/trampoline_64.S
34874@@ -94,6 +94,7 @@ ENTRY(startup_32)
34875 movl %edx, %gs
34876
34877 movl pa_tr_cr4, %eax
34878+ andl $~X86_CR4_PCIDE, %eax
34879 movl %eax, %cr4 # Enable PAE mode
34880
34881 # Setup trampoline 4 level pagetables
34882@@ -107,7 +108,7 @@ ENTRY(startup_32)
34883 wrmsr
34884
34885 # Enable paging and in turn activate Long Mode
34886- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
34887+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
34888 movl %eax, %cr0
34889
34890 /*
34891diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
34892index e812034..c747134 100644
34893--- a/arch/x86/tools/Makefile
34894+++ b/arch/x86/tools/Makefile
34895@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
34896
34897 $(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
34898
34899-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
34900+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
34901 hostprogs-y += relocs
34902 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
34903 relocs: $(obj)/relocs
34904diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
34905index f7bab68..b6d9886 100644
34906--- a/arch/x86/tools/relocs.c
34907+++ b/arch/x86/tools/relocs.c
34908@@ -1,5 +1,7 @@
34909 /* This is included from relocs_32/64.c */
34910
34911+#include "../../../include/generated/autoconf.h"
34912+
34913 #define ElfW(type) _ElfW(ELF_BITS, type)
34914 #define _ElfW(bits, type) __ElfW(bits, type)
34915 #define __ElfW(bits, type) Elf##bits##_##type
34916@@ -11,6 +13,7 @@
34917 #define Elf_Sym ElfW(Sym)
34918
34919 static Elf_Ehdr ehdr;
34920+static Elf_Phdr *phdr;
34921
34922 struct relocs {
34923 uint32_t *offset;
34924@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
34925 }
34926 }
34927
34928+static void read_phdrs(FILE *fp)
34929+{
34930+ unsigned int i;
34931+
34932+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
34933+ if (!phdr) {
34934+ die("Unable to allocate %d program headers\n",
34935+ ehdr.e_phnum);
34936+ }
34937+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
34938+ die("Seek to %d failed: %s\n",
34939+ ehdr.e_phoff, strerror(errno));
34940+ }
34941+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
34942+ die("Cannot read ELF program headers: %s\n",
34943+ strerror(errno));
34944+ }
34945+ for(i = 0; i < ehdr.e_phnum; i++) {
34946+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
34947+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
34948+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
34949+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
34950+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
34951+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
34952+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
34953+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
34954+ }
34955+
34956+}
34957+
34958 static void read_shdrs(FILE *fp)
34959 {
34960- int i;
34961+ unsigned int i;
34962 Elf_Shdr shdr;
34963
34964 secs = calloc(ehdr.e_shnum, sizeof(struct section));
34965@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
34966
34967 static void read_strtabs(FILE *fp)
34968 {
34969- int i;
34970+ unsigned int i;
34971 for (i = 0; i < ehdr.e_shnum; i++) {
34972 struct section *sec = &secs[i];
34973 if (sec->shdr.sh_type != SHT_STRTAB) {
34974@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
34975
34976 static void read_symtabs(FILE *fp)
34977 {
34978- int i,j;
34979+ unsigned int i,j;
34980 for (i = 0; i < ehdr.e_shnum; i++) {
34981 struct section *sec = &secs[i];
34982 if (sec->shdr.sh_type != SHT_SYMTAB) {
34983@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
34984 }
34985
34986
34987-static void read_relocs(FILE *fp)
34988+static void read_relocs(FILE *fp, int use_real_mode)
34989 {
34990- int i,j;
34991+ unsigned int i,j;
34992+ uint32_t base;
34993+
34994 for (i = 0; i < ehdr.e_shnum; i++) {
34995 struct section *sec = &secs[i];
34996 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34997@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
34998 die("Cannot read symbol table: %s\n",
34999 strerror(errno));
35000 }
35001+ base = 0;
35002+
35003+#ifdef CONFIG_X86_32
35004+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35005+ if (phdr[j].p_type != PT_LOAD )
35006+ continue;
35007+ 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)
35008+ continue;
35009+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35010+ break;
35011+ }
35012+#endif
35013+
35014 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35015 Elf_Rel *rel = &sec->reltab[j];
35016- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35017+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35018 rel->r_info = elf_xword_to_cpu(rel->r_info);
35019 #if (SHT_REL_TYPE == SHT_RELA)
35020 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35021@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35022
35023 static void print_absolute_symbols(void)
35024 {
35025- int i;
35026+ unsigned int i;
35027 const char *format;
35028
35029 if (ELF_BITS == 64)
35030@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35031 for (i = 0; i < ehdr.e_shnum; i++) {
35032 struct section *sec = &secs[i];
35033 char *sym_strtab;
35034- int j;
35035+ unsigned int j;
35036
35037 if (sec->shdr.sh_type != SHT_SYMTAB) {
35038 continue;
35039@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35040
35041 static void print_absolute_relocs(void)
35042 {
35043- int i, printed = 0;
35044+ unsigned int i, printed = 0;
35045 const char *format;
35046
35047 if (ELF_BITS == 64)
35048@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35049 struct section *sec_applies, *sec_symtab;
35050 char *sym_strtab;
35051 Elf_Sym *sh_symtab;
35052- int j;
35053+ unsigned int j;
35054 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35055 continue;
35056 }
35057@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35058 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35059 Elf_Sym *sym, const char *symname))
35060 {
35061- int i;
35062+ unsigned int i;
35063 /* Walk through the relocations */
35064 for (i = 0; i < ehdr.e_shnum; i++) {
35065 char *sym_strtab;
35066 Elf_Sym *sh_symtab;
35067 struct section *sec_applies, *sec_symtab;
35068- int j;
35069+ unsigned int j;
35070 struct section *sec = &secs[i];
35071
35072 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35073@@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35074 {
35075 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35076 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35077+ char *sym_strtab = sec->link->link->strtab;
35078+
35079+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35080+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35081+ return 0;
35082+
35083+#ifdef CONFIG_PAX_KERNEXEC
35084+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35085+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35086+ return 0;
35087+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35088+ return 0;
35089+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35090+ return 0;
35091+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35092+ return 0;
35093+#endif
35094
35095 switch (r_type) {
35096 case R_386_NONE:
35097@@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35098
35099 static void emit_relocs(int as_text, int use_real_mode)
35100 {
35101- int i;
35102+ unsigned int i;
35103 int (*write_reloc)(uint32_t, FILE *) = write32;
35104 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35105 const char *symname);
35106@@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35107 {
35108 regex_init(use_real_mode);
35109 read_ehdr(fp);
35110+ read_phdrs(fp);
35111 read_shdrs(fp);
35112 read_strtabs(fp);
35113 read_symtabs(fp);
35114- read_relocs(fp);
35115+ read_relocs(fp, use_real_mode);
35116 if (ELF_BITS == 64)
35117 percpu_init();
35118 if (show_absolute_syms) {
35119diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35120index 80ffa5b..a33bd15 100644
35121--- a/arch/x86/um/tls_32.c
35122+++ b/arch/x86/um/tls_32.c
35123@@ -260,7 +260,7 @@ out:
35124 if (unlikely(task == current &&
35125 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35126 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35127- "without flushed TLS.", current->pid);
35128+ "without flushed TLS.", task_pid_nr(current));
35129 }
35130
35131 return 0;
35132diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35133index fd14be1..e3c79c0 100644
35134--- a/arch/x86/vdso/Makefile
35135+++ b/arch/x86/vdso/Makefile
35136@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
35137 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35138 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35139
35140-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35141+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35142 GCOV_PROFILE := n
35143
35144 #
35145diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35146index d6bfb87..876ee18 100644
35147--- a/arch/x86/vdso/vdso32-setup.c
35148+++ b/arch/x86/vdso/vdso32-setup.c
35149@@ -25,6 +25,7 @@
35150 #include <asm/tlbflush.h>
35151 #include <asm/vdso.h>
35152 #include <asm/proto.h>
35153+#include <asm/mman.h>
35154
35155 enum {
35156 VDSO_DISABLED = 0,
35157@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
35158 void enable_sep_cpu(void)
35159 {
35160 int cpu = get_cpu();
35161- struct tss_struct *tss = &per_cpu(init_tss, cpu);
35162+ struct tss_struct *tss = init_tss + cpu;
35163
35164 if (!boot_cpu_has(X86_FEATURE_SEP)) {
35165 put_cpu();
35166@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
35167 gate_vma.vm_start = FIXADDR_USER_START;
35168 gate_vma.vm_end = FIXADDR_USER_END;
35169 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35170- gate_vma.vm_page_prot = __P101;
35171+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35172
35173 return 0;
35174 }
35175@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35176 if (compat)
35177 addr = VDSO_HIGH_BASE;
35178 else {
35179- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
35180+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
35181 if (IS_ERR_VALUE(addr)) {
35182 ret = addr;
35183 goto up_fail;
35184 }
35185 }
35186
35187- current->mm->context.vdso = (void *)addr;
35188+ current->mm->context.vdso = addr;
35189
35190 if (compat_uses_vma || !compat) {
35191 /*
35192@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35193 }
35194
35195 current_thread_info()->sysenter_return =
35196- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35197+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35198
35199 up_fail:
35200 if (ret)
35201- current->mm->context.vdso = NULL;
35202+ current->mm->context.vdso = 0;
35203
35204 up_write(&mm->mmap_sem);
35205
35206@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
35207
35208 const char *arch_vma_name(struct vm_area_struct *vma)
35209 {
35210- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
35211+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
35212 return "[vdso]";
35213+
35214+#ifdef CONFIG_PAX_SEGMEXEC
35215+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
35216+ return "[vdso]";
35217+#endif
35218+
35219 return NULL;
35220 }
35221
35222@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
35223 * Check to see if the corresponding task was created in compat vdso
35224 * mode.
35225 */
35226- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
35227+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
35228 return &gate_vma;
35229 return NULL;
35230 }
35231diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35232index 431e875..cbb23f3 100644
35233--- a/arch/x86/vdso/vma.c
35234+++ b/arch/x86/vdso/vma.c
35235@@ -16,8 +16,6 @@
35236 #include <asm/vdso.h>
35237 #include <asm/page.h>
35238
35239-unsigned int __read_mostly vdso_enabled = 1;
35240-
35241 extern char vdso_start[], vdso_end[];
35242 extern unsigned short vdso_sync_cpuid;
35243
35244@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
35245 * unaligned here as a result of stack start randomization.
35246 */
35247 addr = PAGE_ALIGN(addr);
35248- addr = align_vdso_addr(addr);
35249
35250 return addr;
35251 }
35252@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
35253 unsigned size)
35254 {
35255 struct mm_struct *mm = current->mm;
35256- unsigned long addr;
35257+ unsigned long addr = 0;
35258 int ret;
35259
35260- if (!vdso_enabled)
35261- return 0;
35262-
35263 down_write(&mm->mmap_sem);
35264+
35265+#ifdef CONFIG_PAX_RANDMMAP
35266+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
35267+#endif
35268+
35269 addr = vdso_addr(mm->start_stack, size);
35270+ addr = align_vdso_addr(addr);
35271 addr = get_unmapped_area(NULL, addr, size, 0, 0);
35272 if (IS_ERR_VALUE(addr)) {
35273 ret = addr;
35274 goto up_fail;
35275 }
35276
35277- current->mm->context.vdso = (void *)addr;
35278+ mm->context.vdso = addr;
35279
35280 ret = install_special_mapping(mm, addr, size,
35281 VM_READ|VM_EXEC|
35282 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
35283 pages);
35284- if (ret) {
35285- current->mm->context.vdso = NULL;
35286- goto up_fail;
35287- }
35288+ if (ret)
35289+ mm->context.vdso = 0;
35290
35291 up_fail:
35292 up_write(&mm->mmap_sem);
35293@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35294 vdsox32_size);
35295 }
35296 #endif
35297-
35298-static __init int vdso_setup(char *s)
35299-{
35300- vdso_enabled = simple_strtoul(s, NULL, 0);
35301- return 0;
35302-}
35303-__setup("vdso=", vdso_setup);
35304diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35305index 1a3c765..3d2e8d1 100644
35306--- a/arch/x86/xen/Kconfig
35307+++ b/arch/x86/xen/Kconfig
35308@@ -9,6 +9,7 @@ config XEN
35309 select XEN_HAVE_PVMMU
35310 depends on X86_64 || (X86_32 && X86_PAE && !X86_VISWS)
35311 depends on X86_TSC
35312+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35313 help
35314 This is the Linux Xen port. Enabling this will allow the
35315 kernel to boot in a paravirtualized environment under the
35316diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35317index fa6ade7..73da73a5 100644
35318--- a/arch/x86/xen/enlighten.c
35319+++ b/arch/x86/xen/enlighten.c
35320@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35321
35322 struct shared_info xen_dummy_shared_info;
35323
35324-void *xen_initial_gdt;
35325-
35326 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35327 __read_mostly int xen_have_vector_callback;
35328 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35329@@ -541,8 +539,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35330 {
35331 unsigned long va = dtr->address;
35332 unsigned int size = dtr->size + 1;
35333- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35334- unsigned long frames[pages];
35335+ unsigned long frames[65536 / PAGE_SIZE];
35336 int f;
35337
35338 /*
35339@@ -590,8 +587,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35340 {
35341 unsigned long va = dtr->address;
35342 unsigned int size = dtr->size + 1;
35343- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35344- unsigned long frames[pages];
35345+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35346 int f;
35347
35348 /*
35349@@ -599,7 +595,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35350 * 8-byte entries, or 16 4k pages..
35351 */
35352
35353- BUG_ON(size > 65536);
35354+ BUG_ON(size > GDT_SIZE);
35355 BUG_ON(va & ~PAGE_MASK);
35356
35357 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35358@@ -988,7 +984,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35359 return 0;
35360 }
35361
35362-static void set_xen_basic_apic_ops(void)
35363+static void __init set_xen_basic_apic_ops(void)
35364 {
35365 apic->read = xen_apic_read;
35366 apic->write = xen_apic_write;
35367@@ -1293,30 +1289,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35368 #endif
35369 };
35370
35371-static void xen_reboot(int reason)
35372+static __noreturn void xen_reboot(int reason)
35373 {
35374 struct sched_shutdown r = { .reason = reason };
35375
35376- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35377- BUG();
35378+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35379+ BUG();
35380 }
35381
35382-static void xen_restart(char *msg)
35383+static __noreturn void xen_restart(char *msg)
35384 {
35385 xen_reboot(SHUTDOWN_reboot);
35386 }
35387
35388-static void xen_emergency_restart(void)
35389+static __noreturn void xen_emergency_restart(void)
35390 {
35391 xen_reboot(SHUTDOWN_reboot);
35392 }
35393
35394-static void xen_machine_halt(void)
35395+static __noreturn void xen_machine_halt(void)
35396 {
35397 xen_reboot(SHUTDOWN_poweroff);
35398 }
35399
35400-static void xen_machine_power_off(void)
35401+static __noreturn void xen_machine_power_off(void)
35402 {
35403 if (pm_power_off)
35404 pm_power_off();
35405@@ -1467,7 +1463,17 @@ asmlinkage void __init xen_start_kernel(void)
35406 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35407
35408 /* Work out if we support NX */
35409- x86_configure_nx();
35410+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35411+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35412+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35413+ unsigned l, h;
35414+
35415+ __supported_pte_mask |= _PAGE_NX;
35416+ rdmsr(MSR_EFER, l, h);
35417+ l |= EFER_NX;
35418+ wrmsr(MSR_EFER, l, h);
35419+ }
35420+#endif
35421
35422 xen_setup_features();
35423
35424@@ -1498,13 +1504,6 @@ asmlinkage void __init xen_start_kernel(void)
35425
35426 machine_ops = xen_machine_ops;
35427
35428- /*
35429- * The only reliable way to retain the initial address of the
35430- * percpu gdt_page is to remember it here, so we can go and
35431- * mark it RW later, when the initial percpu area is freed.
35432- */
35433- xen_initial_gdt = &per_cpu(gdt_page, 0);
35434-
35435 xen_smp_init();
35436
35437 #ifdef CONFIG_ACPI_NUMA
35438diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35439index ce563be..7327d91 100644
35440--- a/arch/x86/xen/mmu.c
35441+++ b/arch/x86/xen/mmu.c
35442@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35443 return val;
35444 }
35445
35446-static pteval_t pte_pfn_to_mfn(pteval_t val)
35447+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35448 {
35449 if (val & _PAGE_PRESENT) {
35450 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35451@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35452 /* L3_k[510] -> level2_kernel_pgt
35453 * L3_i[511] -> level2_fixmap_pgt */
35454 convert_pfn_mfn(level3_kernel_pgt);
35455+ convert_pfn_mfn(level3_vmalloc_start_pgt);
35456+ convert_pfn_mfn(level3_vmalloc_end_pgt);
35457+ convert_pfn_mfn(level3_vmemmap_pgt);
35458
35459 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35460 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
35461@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35462 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35463 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35464 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35465+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35466+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35467+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35468 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35469 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35470+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35471 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35472 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35473
35474@@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
35475 pv_mmu_ops.set_pud = xen_set_pud;
35476 #if PAGETABLE_LEVELS == 4
35477 pv_mmu_ops.set_pgd = xen_set_pgd;
35478+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35479 #endif
35480
35481 /* This will work as long as patching hasn't happened yet
35482@@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35483 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35484 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35485 .set_pgd = xen_set_pgd_hyper,
35486+ .set_pgd_batched = xen_set_pgd_hyper,
35487
35488 .alloc_pud = xen_alloc_pmd_init,
35489 .release_pud = xen_release_pmd_init,
35490diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35491index c36b325..b0f1518 100644
35492--- a/arch/x86/xen/smp.c
35493+++ b/arch/x86/xen/smp.c
35494@@ -274,17 +274,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35495 native_smp_prepare_boot_cpu();
35496
35497 if (xen_pv_domain()) {
35498- /* We've switched to the "real" per-cpu gdt, so make sure the
35499- old memory can be recycled */
35500- make_lowmem_page_readwrite(xen_initial_gdt);
35501-
35502 #ifdef CONFIG_X86_32
35503 /*
35504 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35505 * expects __USER_DS
35506 */
35507- loadsegment(ds, __USER_DS);
35508- loadsegment(es, __USER_DS);
35509+ loadsegment(ds, __KERNEL_DS);
35510+ loadsegment(es, __KERNEL_DS);
35511 #endif
35512
35513 xen_filter_cpu_maps();
35514@@ -364,7 +360,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35515 ctxt->user_regs.ss = __KERNEL_DS;
35516 #ifdef CONFIG_X86_32
35517 ctxt->user_regs.fs = __KERNEL_PERCPU;
35518- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35519+ savesegment(gs, ctxt->user_regs.gs);
35520 #else
35521 ctxt->gs_base_kernel = per_cpu_offset(cpu);
35522 #endif
35523@@ -374,8 +370,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35524
35525 {
35526 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35527- ctxt->user_regs.ds = __USER_DS;
35528- ctxt->user_regs.es = __USER_DS;
35529+ ctxt->user_regs.ds = __KERNEL_DS;
35530+ ctxt->user_regs.es = __KERNEL_DS;
35531
35532 xen_copy_trap_info(ctxt->trap_ctxt);
35533
35534@@ -420,13 +416,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35535 int rc;
35536
35537 per_cpu(current_task, cpu) = idle;
35538+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
35539 #ifdef CONFIG_X86_32
35540 irq_ctx_init(cpu);
35541 #else
35542 clear_tsk_thread_flag(idle, TIF_FORK);
35543- per_cpu(kernel_stack, cpu) =
35544- (unsigned long)task_stack_page(idle) -
35545- KERNEL_STACK_OFFSET + THREAD_SIZE;
35546+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35547 #endif
35548 xen_setup_runstate_info(cpu);
35549 xen_setup_timer(cpu);
35550@@ -702,7 +697,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35551
35552 void __init xen_smp_init(void)
35553 {
35554- smp_ops = xen_smp_ops;
35555+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35556 xen_fill_possible_map();
35557 }
35558
35559diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35560index 33ca6e4..0ded929 100644
35561--- a/arch/x86/xen/xen-asm_32.S
35562+++ b/arch/x86/xen/xen-asm_32.S
35563@@ -84,14 +84,14 @@ ENTRY(xen_iret)
35564 ESP_OFFSET=4 # bytes pushed onto stack
35565
35566 /*
35567- * Store vcpu_info pointer for easy access. Do it this way to
35568- * avoid having to reload %fs
35569+ * Store vcpu_info pointer for easy access.
35570 */
35571 #ifdef CONFIG_SMP
35572- GET_THREAD_INFO(%eax)
35573- movl %ss:TI_cpu(%eax), %eax
35574- movl %ss:__per_cpu_offset(,%eax,4), %eax
35575- mov %ss:xen_vcpu(%eax), %eax
35576+ push %fs
35577+ mov $(__KERNEL_PERCPU), %eax
35578+ mov %eax, %fs
35579+ mov PER_CPU_VAR(xen_vcpu), %eax
35580+ pop %fs
35581 #else
35582 movl %ss:xen_vcpu, %eax
35583 #endif
35584diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35585index 7faed58..ba4427c 100644
35586--- a/arch/x86/xen/xen-head.S
35587+++ b/arch/x86/xen/xen-head.S
35588@@ -19,6 +19,17 @@ ENTRY(startup_xen)
35589 #ifdef CONFIG_X86_32
35590 mov %esi,xen_start_info
35591 mov $init_thread_union+THREAD_SIZE,%esp
35592+#ifdef CONFIG_SMP
35593+ movl $cpu_gdt_table,%edi
35594+ movl $__per_cpu_load,%eax
35595+ movw %ax,__KERNEL_PERCPU + 2(%edi)
35596+ rorl $16,%eax
35597+ movb %al,__KERNEL_PERCPU + 4(%edi)
35598+ movb %ah,__KERNEL_PERCPU + 7(%edi)
35599+ movl $__per_cpu_end - 1,%eax
35600+ subl $__per_cpu_start,%eax
35601+ movw %ax,__KERNEL_PERCPU + 0(%edi)
35602+#endif
35603 #else
35604 mov %rsi,xen_start_info
35605 mov $init_thread_union+THREAD_SIZE,%rsp
35606diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35607index 95f8c61..611d6e8 100644
35608--- a/arch/x86/xen/xen-ops.h
35609+++ b/arch/x86/xen/xen-ops.h
35610@@ -10,8 +10,6 @@
35611 extern const char xen_hypervisor_callback[];
35612 extern const char xen_failsafe_callback[];
35613
35614-extern void *xen_initial_gdt;
35615-
35616 struct trap_info;
35617 void xen_copy_trap_info(struct trap_info *traps);
35618
35619diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35620index 525bd3d..ef888b1 100644
35621--- a/arch/xtensa/variants/dc232b/include/variant/core.h
35622+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35623@@ -119,9 +119,9 @@
35624 ----------------------------------------------------------------------*/
35625
35626 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35627-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35628 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35629 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35630+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35631
35632 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35633 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35634diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35635index 2f33760..835e50a 100644
35636--- a/arch/xtensa/variants/fsf/include/variant/core.h
35637+++ b/arch/xtensa/variants/fsf/include/variant/core.h
35638@@ -11,6 +11,7 @@
35639 #ifndef _XTENSA_CORE_H
35640 #define _XTENSA_CORE_H
35641
35642+#include <linux/const.h>
35643
35644 /****************************************************************************
35645 Parameters Useful for Any Code, USER or PRIVILEGED
35646@@ -112,9 +113,9 @@
35647 ----------------------------------------------------------------------*/
35648
35649 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35650-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35651 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35652 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35653+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35654
35655 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35656 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35657diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35658index af00795..2bb8105 100644
35659--- a/arch/xtensa/variants/s6000/include/variant/core.h
35660+++ b/arch/xtensa/variants/s6000/include/variant/core.h
35661@@ -11,6 +11,7 @@
35662 #ifndef _XTENSA_CORE_CONFIGURATION_H
35663 #define _XTENSA_CORE_CONFIGURATION_H
35664
35665+#include <linux/const.h>
35666
35667 /****************************************************************************
35668 Parameters Useful for Any Code, USER or PRIVILEGED
35669@@ -118,9 +119,9 @@
35670 ----------------------------------------------------------------------*/
35671
35672 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35673-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35674 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35675 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35676+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35677
35678 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35679 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35680diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35681index 4e491d9..c8e18e4 100644
35682--- a/block/blk-cgroup.c
35683+++ b/block/blk-cgroup.c
35684@@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35685 static struct cgroup_subsys_state *
35686 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35687 {
35688- static atomic64_t id_seq = ATOMIC64_INIT(0);
35689+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35690 struct blkcg *blkcg;
35691
35692 if (!parent_css) {
35693@@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35694
35695 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35696 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35697- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35698+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35699 done:
35700 spin_lock_init(&blkcg->lock);
35701 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35702diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35703index 1855bf5..af12b06 100644
35704--- a/block/blk-iopoll.c
35705+++ b/block/blk-iopoll.c
35706@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35707 }
35708 EXPORT_SYMBOL(blk_iopoll_complete);
35709
35710-static void blk_iopoll_softirq(struct softirq_action *h)
35711+static __latent_entropy void blk_iopoll_softirq(void)
35712 {
35713 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
35714 int rearm = 0, budget = blk_iopoll_budget;
35715diff --git a/block/blk-map.c b/block/blk-map.c
35716index 623e1cd..ca1e109 100644
35717--- a/block/blk-map.c
35718+++ b/block/blk-map.c
35719@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35720 if (!len || !kbuf)
35721 return -EINVAL;
35722
35723- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35724+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35725 if (do_copy)
35726 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35727 else
35728diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35729index 57790c1..5e988dd 100644
35730--- a/block/blk-softirq.c
35731+++ b/block/blk-softirq.c
35732@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35733 * Softirq action handler - move entries to local list and loop over them
35734 * while passing them to the queue registered handler.
35735 */
35736-static void blk_done_softirq(struct softirq_action *h)
35737+static __latent_entropy void blk_done_softirq(void)
35738 {
35739 struct list_head *cpu_list, local_list;
35740
35741diff --git a/block/bsg.c b/block/bsg.c
35742index 420a5a9..23834aa 100644
35743--- a/block/bsg.c
35744+++ b/block/bsg.c
35745@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35746 struct sg_io_v4 *hdr, struct bsg_device *bd,
35747 fmode_t has_write_perm)
35748 {
35749+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35750+ unsigned char *cmdptr;
35751+
35752 if (hdr->request_len > BLK_MAX_CDB) {
35753 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35754 if (!rq->cmd)
35755 return -ENOMEM;
35756- }
35757+ cmdptr = rq->cmd;
35758+ } else
35759+ cmdptr = tmpcmd;
35760
35761- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
35762+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
35763 hdr->request_len))
35764 return -EFAULT;
35765
35766+ if (cmdptr != rq->cmd)
35767+ memcpy(rq->cmd, cmdptr, hdr->request_len);
35768+
35769 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
35770 if (blk_verify_command(rq->cmd, has_write_perm))
35771 return -EPERM;
35772diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
35773index fbd5a67..f24fd95 100644
35774--- a/block/compat_ioctl.c
35775+++ b/block/compat_ioctl.c
35776@@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
35777 cgc = compat_alloc_user_space(sizeof(*cgc));
35778 cgc32 = compat_ptr(arg);
35779
35780- if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
35781+ if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
35782 get_user(data, &cgc32->buffer) ||
35783 put_user(compat_ptr(data), &cgc->buffer) ||
35784 copy_in_user(&cgc->buflen, &cgc32->buflen,
35785@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
35786 err |= __get_user(f->spec1, &uf->spec1);
35787 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
35788 err |= __get_user(name, &uf->name);
35789- f->name = compat_ptr(name);
35790+ f->name = (void __force_kernel *)compat_ptr(name);
35791 if (err) {
35792 err = -EFAULT;
35793 goto out;
35794diff --git a/block/genhd.c b/block/genhd.c
35795index 791f419..89f21c4 100644
35796--- a/block/genhd.c
35797+++ b/block/genhd.c
35798@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
35799
35800 /*
35801 * Register device numbers dev..(dev+range-1)
35802- * range must be nonzero
35803+ * Noop if @range is zero.
35804 * The hash chain is sorted on range, so that subranges can override.
35805 */
35806 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
35807 struct kobject *(*probe)(dev_t, int *, void *),
35808 int (*lock)(dev_t, void *), void *data)
35809 {
35810- kobj_map(bdev_map, devt, range, module, probe, lock, data);
35811+ if (range)
35812+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
35813 }
35814
35815 EXPORT_SYMBOL(blk_register_region);
35816
35817+/* undo blk_register_region(), noop if @range is zero */
35818 void blk_unregister_region(dev_t devt, unsigned long range)
35819 {
35820- kobj_unmap(bdev_map, devt, range);
35821+ if (range)
35822+ kobj_unmap(bdev_map, devt, range);
35823 }
35824
35825 EXPORT_SYMBOL(blk_unregister_region);
35826diff --git a/block/partitions/efi.c b/block/partitions/efi.c
35827index dc51f46..d5446a8 100644
35828--- a/block/partitions/efi.c
35829+++ b/block/partitions/efi.c
35830@@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
35831 if (!gpt)
35832 return NULL;
35833
35834+ if (!le32_to_cpu(gpt->num_partition_entries))
35835+ return NULL;
35836+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
35837+ if (!pte)
35838+ return NULL;
35839+
35840 count = le32_to_cpu(gpt->num_partition_entries) *
35841 le32_to_cpu(gpt->sizeof_partition_entry);
35842- if (!count)
35843- return NULL;
35844- pte = kmalloc(count, GFP_KERNEL);
35845- if (!pte)
35846- return NULL;
35847-
35848 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
35849 (u8 *) pte, count) < count) {
35850 kfree(pte);
35851diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
35852index 625e3e4..b5339f9 100644
35853--- a/block/scsi_ioctl.c
35854+++ b/block/scsi_ioctl.c
35855@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
35856 return put_user(0, p);
35857 }
35858
35859-static int sg_get_timeout(struct request_queue *q)
35860+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
35861 {
35862 return jiffies_to_clock_t(q->sg_timeout);
35863 }
35864@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
35865 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
35866 struct sg_io_hdr *hdr, fmode_t mode)
35867 {
35868- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
35869+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35870+ unsigned char *cmdptr;
35871+
35872+ if (rq->cmd != rq->__cmd)
35873+ cmdptr = rq->cmd;
35874+ else
35875+ cmdptr = tmpcmd;
35876+
35877+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
35878 return -EFAULT;
35879+
35880+ if (cmdptr != rq->cmd)
35881+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
35882+
35883 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
35884 return -EPERM;
35885
35886@@ -415,6 +427,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35887 int err;
35888 unsigned int in_len, out_len, bytes, opcode, cmdlen;
35889 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
35890+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35891+ unsigned char *cmdptr;
35892
35893 if (!sic)
35894 return -EINVAL;
35895@@ -448,9 +462,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35896 */
35897 err = -EFAULT;
35898 rq->cmd_len = cmdlen;
35899- if (copy_from_user(rq->cmd, sic->data, cmdlen))
35900+
35901+ if (rq->cmd != rq->__cmd)
35902+ cmdptr = rq->cmd;
35903+ else
35904+ cmdptr = tmpcmd;
35905+
35906+ if (copy_from_user(cmdptr, sic->data, cmdlen))
35907 goto error;
35908
35909+ if (rq->cmd != cmdptr)
35910+ memcpy(rq->cmd, cmdptr, cmdlen);
35911+
35912 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
35913 goto error;
35914
35915diff --git a/crypto/cryptd.c b/crypto/cryptd.c
35916index 7bdd61b..afec999 100644
35917--- a/crypto/cryptd.c
35918+++ b/crypto/cryptd.c
35919@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
35920
35921 struct cryptd_blkcipher_request_ctx {
35922 crypto_completion_t complete;
35923-};
35924+} __no_const;
35925
35926 struct cryptd_hash_ctx {
35927 struct crypto_shash *child;
35928@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
35929
35930 struct cryptd_aead_request_ctx {
35931 crypto_completion_t complete;
35932-};
35933+} __no_const;
35934
35935 static void cryptd_queue_worker(struct work_struct *work);
35936
35937diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
35938index f8c920c..ab2cb5a 100644
35939--- a/crypto/pcrypt.c
35940+++ b/crypto/pcrypt.c
35941@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
35942 int ret;
35943
35944 pinst->kobj.kset = pcrypt_kset;
35945- ret = kobject_add(&pinst->kobj, NULL, name);
35946+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
35947 if (!ret)
35948 kobject_uevent(&pinst->kobj, KOBJ_ADD);
35949
35950diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
35951index 15dddc1..b61cf0c 100644
35952--- a/drivers/acpi/acpica/hwxfsleep.c
35953+++ b/drivers/acpi/acpica/hwxfsleep.c
35954@@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
35955 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
35956
35957 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
35958- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35959- acpi_hw_extended_sleep},
35960- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35961- acpi_hw_extended_wake_prep},
35962- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
35963+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35964+ .extended_function = acpi_hw_extended_sleep},
35965+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35966+ .extended_function = acpi_hw_extended_wake_prep},
35967+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
35968+ .extended_function = acpi_hw_extended_wake}
35969 };
35970
35971 /*
35972diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
35973index 21ba34a..cb05966 100644
35974--- a/drivers/acpi/apei/apei-internal.h
35975+++ b/drivers/acpi/apei/apei-internal.h
35976@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
35977 struct apei_exec_ins_type {
35978 u32 flags;
35979 apei_exec_ins_func_t run;
35980-};
35981+} __do_const;
35982
35983 struct apei_exec_context {
35984 u32 ip;
35985diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
35986index a30bc31..b91c4d5 100644
35987--- a/drivers/acpi/apei/ghes.c
35988+++ b/drivers/acpi/apei/ghes.c
35989@@ -498,7 +498,7 @@ static void __ghes_print_estatus(const char *pfx,
35990 const struct acpi_hest_generic *generic,
35991 const struct acpi_generic_status *estatus)
35992 {
35993- static atomic_t seqno;
35994+ static atomic_unchecked_t seqno;
35995 unsigned int curr_seqno;
35996 char pfx_seq[64];
35997
35998@@ -509,7 +509,7 @@ static void __ghes_print_estatus(const char *pfx,
35999 else
36000 pfx = KERN_ERR;
36001 }
36002- curr_seqno = atomic_inc_return(&seqno);
36003+ curr_seqno = atomic_inc_return_unchecked(&seqno);
36004 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36005 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36006 pfx_seq, generic->header.source_id);
36007diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36008index a83e3c6..c3d617f 100644
36009--- a/drivers/acpi/bgrt.c
36010+++ b/drivers/acpi/bgrt.c
36011@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36012 if (!bgrt_image)
36013 return -ENODEV;
36014
36015- bin_attr_image.private = bgrt_image;
36016- bin_attr_image.size = bgrt_image_size;
36017+ pax_open_kernel();
36018+ *(void **)&bin_attr_image.private = bgrt_image;
36019+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
36020+ pax_close_kernel();
36021
36022 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36023 if (!bgrt_kobj)
36024diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36025index 078c4f7..410e272 100644
36026--- a/drivers/acpi/blacklist.c
36027+++ b/drivers/acpi/blacklist.c
36028@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
36029 u32 is_critical_error;
36030 };
36031
36032-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36033+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36034
36035 /*
36036 * POLICY: If *anything* doesn't work, put it on the blacklist.
36037@@ -164,7 +164,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36038 return 0;
36039 }
36040
36041-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36042+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36043 {
36044 .callback = dmi_disable_osi_vista,
36045 .ident = "Fujitsu Siemens",
36046diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36047index 12b62f2..dc2aac8 100644
36048--- a/drivers/acpi/custom_method.c
36049+++ b/drivers/acpi/custom_method.c
36050@@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36051 struct acpi_table_header table;
36052 acpi_status status;
36053
36054+#ifdef CONFIG_GRKERNSEC_KMEM
36055+ return -EPERM;
36056+#endif
36057+
36058 if (!(*ppos)) {
36059 /* parse the table header to get the table length */
36060 if (count <= sizeof(struct acpi_table_header))
36061diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36062index 644516d..643937e 100644
36063--- a/drivers/acpi/processor_idle.c
36064+++ b/drivers/acpi/processor_idle.c
36065@@ -963,7 +963,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36066 {
36067 int i, count = CPUIDLE_DRIVER_STATE_START;
36068 struct acpi_processor_cx *cx;
36069- struct cpuidle_state *state;
36070+ cpuidle_state_no_const *state;
36071 struct cpuidle_driver *drv = &acpi_idle_driver;
36072
36073 if (!pr->flags.power_setup_done)
36074diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36075index 6dbc3ca..b8b59a0 100644
36076--- a/drivers/acpi/sysfs.c
36077+++ b/drivers/acpi/sysfs.c
36078@@ -425,11 +425,11 @@ static u32 num_counters;
36079 static struct attribute **all_attrs;
36080 static u32 acpi_gpe_count;
36081
36082-static struct attribute_group interrupt_stats_attr_group = {
36083+static attribute_group_no_const interrupt_stats_attr_group = {
36084 .name = "interrupts",
36085 };
36086
36087-static struct kobj_attribute *counter_attrs;
36088+static kobj_attribute_no_const *counter_attrs;
36089
36090 static void delete_gpe_attr_array(void)
36091 {
36092diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36093index c482f8c..c832240 100644
36094--- a/drivers/ata/libahci.c
36095+++ b/drivers/ata/libahci.c
36096@@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
36097 }
36098 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36099
36100-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36101+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36102 struct ata_taskfile *tf, int is_cmd, u16 flags,
36103 unsigned long timeout_msec)
36104 {
36105diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36106index 8cb2522..a815e54 100644
36107--- a/drivers/ata/libata-core.c
36108+++ b/drivers/ata/libata-core.c
36109@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36110 static void ata_dev_xfermask(struct ata_device *dev);
36111 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36112
36113-atomic_t ata_print_id = ATOMIC_INIT(0);
36114+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36115
36116 struct ata_force_param {
36117 const char *name;
36118@@ -4851,7 +4851,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36119 struct ata_port *ap;
36120 unsigned int tag;
36121
36122- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36123+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36124 ap = qc->ap;
36125
36126 qc->flags = 0;
36127@@ -4867,7 +4867,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36128 struct ata_port *ap;
36129 struct ata_link *link;
36130
36131- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36132+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36133 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36134 ap = qc->ap;
36135 link = qc->dev->link;
36136@@ -5986,6 +5986,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36137 return;
36138
36139 spin_lock(&lock);
36140+ pax_open_kernel();
36141
36142 for (cur = ops->inherits; cur; cur = cur->inherits) {
36143 void **inherit = (void **)cur;
36144@@ -5999,8 +6000,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36145 if (IS_ERR(*pp))
36146 *pp = NULL;
36147
36148- ops->inherits = NULL;
36149+ *(struct ata_port_operations **)&ops->inherits = NULL;
36150
36151+ pax_close_kernel();
36152 spin_unlock(&lock);
36153 }
36154
36155@@ -6193,7 +6195,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36156
36157 /* give ports names and add SCSI hosts */
36158 for (i = 0; i < host->n_ports; i++) {
36159- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36160+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36161 host->ports[i]->local_port_no = i + 1;
36162 }
36163
36164diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36165index ef8567d..8bdbd03 100644
36166--- a/drivers/ata/libata-scsi.c
36167+++ b/drivers/ata/libata-scsi.c
36168@@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
36169
36170 if (rc)
36171 return rc;
36172- ap->print_id = atomic_inc_return(&ata_print_id);
36173+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36174 return 0;
36175 }
36176 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36177diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36178index 45b5ab3..98446b8 100644
36179--- a/drivers/ata/libata.h
36180+++ b/drivers/ata/libata.h
36181@@ -53,7 +53,7 @@ enum {
36182 ATA_DNXFER_QUIET = (1 << 31),
36183 };
36184
36185-extern atomic_t ata_print_id;
36186+extern atomic_unchecked_t ata_print_id;
36187 extern int atapi_passthru16;
36188 extern int libata_fua;
36189 extern int libata_noacpi;
36190diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36191index 73492dd..ca2bff5 100644
36192--- a/drivers/ata/pata_arasan_cf.c
36193+++ b/drivers/ata/pata_arasan_cf.c
36194@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36195 /* Handle platform specific quirks */
36196 if (quirk) {
36197 if (quirk & CF_BROKEN_PIO) {
36198- ap->ops->set_piomode = NULL;
36199+ pax_open_kernel();
36200+ *(void **)&ap->ops->set_piomode = NULL;
36201+ pax_close_kernel();
36202 ap->pio_mask = 0;
36203 }
36204 if (quirk & CF_BROKEN_MWDMA)
36205diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36206index f9b983a..887b9d8 100644
36207--- a/drivers/atm/adummy.c
36208+++ b/drivers/atm/adummy.c
36209@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36210 vcc->pop(vcc, skb);
36211 else
36212 dev_kfree_skb_any(skb);
36213- atomic_inc(&vcc->stats->tx);
36214+ atomic_inc_unchecked(&vcc->stats->tx);
36215
36216 return 0;
36217 }
36218diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36219index 62a7607..cc4be104 100644
36220--- a/drivers/atm/ambassador.c
36221+++ b/drivers/atm/ambassador.c
36222@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36223 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36224
36225 // VC layer stats
36226- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36227+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36228
36229 // free the descriptor
36230 kfree (tx_descr);
36231@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36232 dump_skb ("<<<", vc, skb);
36233
36234 // VC layer stats
36235- atomic_inc(&atm_vcc->stats->rx);
36236+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36237 __net_timestamp(skb);
36238 // end of our responsibility
36239 atm_vcc->push (atm_vcc, skb);
36240@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36241 } else {
36242 PRINTK (KERN_INFO, "dropped over-size frame");
36243 // should we count this?
36244- atomic_inc(&atm_vcc->stats->rx_drop);
36245+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36246 }
36247
36248 } else {
36249@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36250 }
36251
36252 if (check_area (skb->data, skb->len)) {
36253- atomic_inc(&atm_vcc->stats->tx_err);
36254+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36255 return -ENOMEM; // ?
36256 }
36257
36258diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36259index 0e3f8f9..765a7a5 100644
36260--- a/drivers/atm/atmtcp.c
36261+++ b/drivers/atm/atmtcp.c
36262@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36263 if (vcc->pop) vcc->pop(vcc,skb);
36264 else dev_kfree_skb(skb);
36265 if (dev_data) return 0;
36266- atomic_inc(&vcc->stats->tx_err);
36267+ atomic_inc_unchecked(&vcc->stats->tx_err);
36268 return -ENOLINK;
36269 }
36270 size = skb->len+sizeof(struct atmtcp_hdr);
36271@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36272 if (!new_skb) {
36273 if (vcc->pop) vcc->pop(vcc,skb);
36274 else dev_kfree_skb(skb);
36275- atomic_inc(&vcc->stats->tx_err);
36276+ atomic_inc_unchecked(&vcc->stats->tx_err);
36277 return -ENOBUFS;
36278 }
36279 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36280@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36281 if (vcc->pop) vcc->pop(vcc,skb);
36282 else dev_kfree_skb(skb);
36283 out_vcc->push(out_vcc,new_skb);
36284- atomic_inc(&vcc->stats->tx);
36285- atomic_inc(&out_vcc->stats->rx);
36286+ atomic_inc_unchecked(&vcc->stats->tx);
36287+ atomic_inc_unchecked(&out_vcc->stats->rx);
36288 return 0;
36289 }
36290
36291@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36292 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
36293 read_unlock(&vcc_sklist_lock);
36294 if (!out_vcc) {
36295- atomic_inc(&vcc->stats->tx_err);
36296+ atomic_inc_unchecked(&vcc->stats->tx_err);
36297 goto done;
36298 }
36299 skb_pull(skb,sizeof(struct atmtcp_hdr));
36300@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36301 __net_timestamp(new_skb);
36302 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36303 out_vcc->push(out_vcc,new_skb);
36304- atomic_inc(&vcc->stats->tx);
36305- atomic_inc(&out_vcc->stats->rx);
36306+ atomic_inc_unchecked(&vcc->stats->tx);
36307+ atomic_inc_unchecked(&out_vcc->stats->rx);
36308 done:
36309 if (vcc->pop) vcc->pop(vcc,skb);
36310 else dev_kfree_skb(skb);
36311diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36312index b1955ba..b179940 100644
36313--- a/drivers/atm/eni.c
36314+++ b/drivers/atm/eni.c
36315@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36316 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36317 vcc->dev->number);
36318 length = 0;
36319- atomic_inc(&vcc->stats->rx_err);
36320+ atomic_inc_unchecked(&vcc->stats->rx_err);
36321 }
36322 else {
36323 length = ATM_CELL_SIZE-1; /* no HEC */
36324@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36325 size);
36326 }
36327 eff = length = 0;
36328- atomic_inc(&vcc->stats->rx_err);
36329+ atomic_inc_unchecked(&vcc->stats->rx_err);
36330 }
36331 else {
36332 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36333@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36334 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36335 vcc->dev->number,vcc->vci,length,size << 2,descr);
36336 length = eff = 0;
36337- atomic_inc(&vcc->stats->rx_err);
36338+ atomic_inc_unchecked(&vcc->stats->rx_err);
36339 }
36340 }
36341 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36342@@ -767,7 +767,7 @@ rx_dequeued++;
36343 vcc->push(vcc,skb);
36344 pushed++;
36345 }
36346- atomic_inc(&vcc->stats->rx);
36347+ atomic_inc_unchecked(&vcc->stats->rx);
36348 }
36349 wake_up(&eni_dev->rx_wait);
36350 }
36351@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36352 PCI_DMA_TODEVICE);
36353 if (vcc->pop) vcc->pop(vcc,skb);
36354 else dev_kfree_skb_irq(skb);
36355- atomic_inc(&vcc->stats->tx);
36356+ atomic_inc_unchecked(&vcc->stats->tx);
36357 wake_up(&eni_dev->tx_wait);
36358 dma_complete++;
36359 }
36360diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36361index b41c948..a002b17 100644
36362--- a/drivers/atm/firestream.c
36363+++ b/drivers/atm/firestream.c
36364@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36365 }
36366 }
36367
36368- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36369+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36370
36371 fs_dprintk (FS_DEBUG_TXMEM, "i");
36372 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36373@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36374 #endif
36375 skb_put (skb, qe->p1 & 0xffff);
36376 ATM_SKB(skb)->vcc = atm_vcc;
36377- atomic_inc(&atm_vcc->stats->rx);
36378+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36379 __net_timestamp(skb);
36380 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36381 atm_vcc->push (atm_vcc, skb);
36382@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36383 kfree (pe);
36384 }
36385 if (atm_vcc)
36386- atomic_inc(&atm_vcc->stats->rx_drop);
36387+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36388 break;
36389 case 0x1f: /* Reassembly abort: no buffers. */
36390 /* Silently increment error counter. */
36391 if (atm_vcc)
36392- atomic_inc(&atm_vcc->stats->rx_drop);
36393+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36394 break;
36395 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36396 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36397diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36398index 204814e..cede831 100644
36399--- a/drivers/atm/fore200e.c
36400+++ b/drivers/atm/fore200e.c
36401@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36402 #endif
36403 /* check error condition */
36404 if (*entry->status & STATUS_ERROR)
36405- atomic_inc(&vcc->stats->tx_err);
36406+ atomic_inc_unchecked(&vcc->stats->tx_err);
36407 else
36408- atomic_inc(&vcc->stats->tx);
36409+ atomic_inc_unchecked(&vcc->stats->tx);
36410 }
36411 }
36412
36413@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36414 if (skb == NULL) {
36415 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36416
36417- atomic_inc(&vcc->stats->rx_drop);
36418+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36419 return -ENOMEM;
36420 }
36421
36422@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36423
36424 dev_kfree_skb_any(skb);
36425
36426- atomic_inc(&vcc->stats->rx_drop);
36427+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36428 return -ENOMEM;
36429 }
36430
36431 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36432
36433 vcc->push(vcc, skb);
36434- atomic_inc(&vcc->stats->rx);
36435+ atomic_inc_unchecked(&vcc->stats->rx);
36436
36437 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36438
36439@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36440 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36441 fore200e->atm_dev->number,
36442 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36443- atomic_inc(&vcc->stats->rx_err);
36444+ atomic_inc_unchecked(&vcc->stats->rx_err);
36445 }
36446 }
36447
36448@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36449 goto retry_here;
36450 }
36451
36452- atomic_inc(&vcc->stats->tx_err);
36453+ atomic_inc_unchecked(&vcc->stats->tx_err);
36454
36455 fore200e->tx_sat++;
36456 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36457diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36458index 8557adc..3fb5d55 100644
36459--- a/drivers/atm/he.c
36460+++ b/drivers/atm/he.c
36461@@ -1691,7 +1691,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36462
36463 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36464 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36465- atomic_inc(&vcc->stats->rx_drop);
36466+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36467 goto return_host_buffers;
36468 }
36469
36470@@ -1718,7 +1718,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36471 RBRQ_LEN_ERR(he_dev->rbrq_head)
36472 ? "LEN_ERR" : "",
36473 vcc->vpi, vcc->vci);
36474- atomic_inc(&vcc->stats->rx_err);
36475+ atomic_inc_unchecked(&vcc->stats->rx_err);
36476 goto return_host_buffers;
36477 }
36478
36479@@ -1770,7 +1770,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36480 vcc->push(vcc, skb);
36481 spin_lock(&he_dev->global_lock);
36482
36483- atomic_inc(&vcc->stats->rx);
36484+ atomic_inc_unchecked(&vcc->stats->rx);
36485
36486 return_host_buffers:
36487 ++pdus_assembled;
36488@@ -2096,7 +2096,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36489 tpd->vcc->pop(tpd->vcc, tpd->skb);
36490 else
36491 dev_kfree_skb_any(tpd->skb);
36492- atomic_inc(&tpd->vcc->stats->tx_err);
36493+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36494 }
36495 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36496 return;
36497@@ -2508,7 +2508,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36498 vcc->pop(vcc, skb);
36499 else
36500 dev_kfree_skb_any(skb);
36501- atomic_inc(&vcc->stats->tx_err);
36502+ atomic_inc_unchecked(&vcc->stats->tx_err);
36503 return -EINVAL;
36504 }
36505
36506@@ -2519,7 +2519,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36507 vcc->pop(vcc, skb);
36508 else
36509 dev_kfree_skb_any(skb);
36510- atomic_inc(&vcc->stats->tx_err);
36511+ atomic_inc_unchecked(&vcc->stats->tx_err);
36512 return -EINVAL;
36513 }
36514 #endif
36515@@ -2531,7 +2531,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36516 vcc->pop(vcc, skb);
36517 else
36518 dev_kfree_skb_any(skb);
36519- atomic_inc(&vcc->stats->tx_err);
36520+ atomic_inc_unchecked(&vcc->stats->tx_err);
36521 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36522 return -ENOMEM;
36523 }
36524@@ -2573,7 +2573,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36525 vcc->pop(vcc, skb);
36526 else
36527 dev_kfree_skb_any(skb);
36528- atomic_inc(&vcc->stats->tx_err);
36529+ atomic_inc_unchecked(&vcc->stats->tx_err);
36530 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36531 return -ENOMEM;
36532 }
36533@@ -2604,7 +2604,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36534 __enqueue_tpd(he_dev, tpd, cid);
36535 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36536
36537- atomic_inc(&vcc->stats->tx);
36538+ atomic_inc_unchecked(&vcc->stats->tx);
36539
36540 return 0;
36541 }
36542diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36543index 1dc0519..1aadaf7 100644
36544--- a/drivers/atm/horizon.c
36545+++ b/drivers/atm/horizon.c
36546@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36547 {
36548 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36549 // VC layer stats
36550- atomic_inc(&vcc->stats->rx);
36551+ atomic_inc_unchecked(&vcc->stats->rx);
36552 __net_timestamp(skb);
36553 // end of our responsibility
36554 vcc->push (vcc, skb);
36555@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36556 dev->tx_iovec = NULL;
36557
36558 // VC layer stats
36559- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36560+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36561
36562 // free the skb
36563 hrz_kfree_skb (skb);
36564diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36565index 1bdf104..9dc44b1 100644
36566--- a/drivers/atm/idt77252.c
36567+++ b/drivers/atm/idt77252.c
36568@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36569 else
36570 dev_kfree_skb(skb);
36571
36572- atomic_inc(&vcc->stats->tx);
36573+ atomic_inc_unchecked(&vcc->stats->tx);
36574 }
36575
36576 atomic_dec(&scq->used);
36577@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36578 if ((sb = dev_alloc_skb(64)) == NULL) {
36579 printk("%s: Can't allocate buffers for aal0.\n",
36580 card->name);
36581- atomic_add(i, &vcc->stats->rx_drop);
36582+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
36583 break;
36584 }
36585 if (!atm_charge(vcc, sb->truesize)) {
36586 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36587 card->name);
36588- atomic_add(i - 1, &vcc->stats->rx_drop);
36589+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36590 dev_kfree_skb(sb);
36591 break;
36592 }
36593@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36594 ATM_SKB(sb)->vcc = vcc;
36595 __net_timestamp(sb);
36596 vcc->push(vcc, sb);
36597- atomic_inc(&vcc->stats->rx);
36598+ atomic_inc_unchecked(&vcc->stats->rx);
36599
36600 cell += ATM_CELL_PAYLOAD;
36601 }
36602@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36603 "(CDC: %08x)\n",
36604 card->name, len, rpp->len, readl(SAR_REG_CDC));
36605 recycle_rx_pool_skb(card, rpp);
36606- atomic_inc(&vcc->stats->rx_err);
36607+ atomic_inc_unchecked(&vcc->stats->rx_err);
36608 return;
36609 }
36610 if (stat & SAR_RSQE_CRC) {
36611 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36612 recycle_rx_pool_skb(card, rpp);
36613- atomic_inc(&vcc->stats->rx_err);
36614+ atomic_inc_unchecked(&vcc->stats->rx_err);
36615 return;
36616 }
36617 if (skb_queue_len(&rpp->queue) > 1) {
36618@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36619 RXPRINTK("%s: Can't alloc RX skb.\n",
36620 card->name);
36621 recycle_rx_pool_skb(card, rpp);
36622- atomic_inc(&vcc->stats->rx_err);
36623+ atomic_inc_unchecked(&vcc->stats->rx_err);
36624 return;
36625 }
36626 if (!atm_charge(vcc, skb->truesize)) {
36627@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36628 __net_timestamp(skb);
36629
36630 vcc->push(vcc, skb);
36631- atomic_inc(&vcc->stats->rx);
36632+ atomic_inc_unchecked(&vcc->stats->rx);
36633
36634 return;
36635 }
36636@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36637 __net_timestamp(skb);
36638
36639 vcc->push(vcc, skb);
36640- atomic_inc(&vcc->stats->rx);
36641+ atomic_inc_unchecked(&vcc->stats->rx);
36642
36643 if (skb->truesize > SAR_FB_SIZE_3)
36644 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36645@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36646 if (vcc->qos.aal != ATM_AAL0) {
36647 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36648 card->name, vpi, vci);
36649- atomic_inc(&vcc->stats->rx_drop);
36650+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36651 goto drop;
36652 }
36653
36654 if ((sb = dev_alloc_skb(64)) == NULL) {
36655 printk("%s: Can't allocate buffers for AAL0.\n",
36656 card->name);
36657- atomic_inc(&vcc->stats->rx_err);
36658+ atomic_inc_unchecked(&vcc->stats->rx_err);
36659 goto drop;
36660 }
36661
36662@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36663 ATM_SKB(sb)->vcc = vcc;
36664 __net_timestamp(sb);
36665 vcc->push(vcc, sb);
36666- atomic_inc(&vcc->stats->rx);
36667+ atomic_inc_unchecked(&vcc->stats->rx);
36668
36669 drop:
36670 skb_pull(queue, 64);
36671@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36672
36673 if (vc == NULL) {
36674 printk("%s: NULL connection in send().\n", card->name);
36675- atomic_inc(&vcc->stats->tx_err);
36676+ atomic_inc_unchecked(&vcc->stats->tx_err);
36677 dev_kfree_skb(skb);
36678 return -EINVAL;
36679 }
36680 if (!test_bit(VCF_TX, &vc->flags)) {
36681 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36682- atomic_inc(&vcc->stats->tx_err);
36683+ atomic_inc_unchecked(&vcc->stats->tx_err);
36684 dev_kfree_skb(skb);
36685 return -EINVAL;
36686 }
36687@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36688 break;
36689 default:
36690 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
36691- atomic_inc(&vcc->stats->tx_err);
36692+ atomic_inc_unchecked(&vcc->stats->tx_err);
36693 dev_kfree_skb(skb);
36694 return -EINVAL;
36695 }
36696
36697 if (skb_shinfo(skb)->nr_frags != 0) {
36698 printk("%s: No scatter-gather yet.\n", card->name);
36699- atomic_inc(&vcc->stats->tx_err);
36700+ atomic_inc_unchecked(&vcc->stats->tx_err);
36701 dev_kfree_skb(skb);
36702 return -EINVAL;
36703 }
36704@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36705
36706 err = queue_skb(card, vc, skb, oam);
36707 if (err) {
36708- atomic_inc(&vcc->stats->tx_err);
36709+ atomic_inc_unchecked(&vcc->stats->tx_err);
36710 dev_kfree_skb(skb);
36711 return err;
36712 }
36713@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36714 skb = dev_alloc_skb(64);
36715 if (!skb) {
36716 printk("%s: Out of memory in send_oam().\n", card->name);
36717- atomic_inc(&vcc->stats->tx_err);
36718+ atomic_inc_unchecked(&vcc->stats->tx_err);
36719 return -ENOMEM;
36720 }
36721 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36722diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36723index 4217f29..88f547a 100644
36724--- a/drivers/atm/iphase.c
36725+++ b/drivers/atm/iphase.c
36726@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36727 status = (u_short) (buf_desc_ptr->desc_mode);
36728 if (status & (RX_CER | RX_PTE | RX_OFL))
36729 {
36730- atomic_inc(&vcc->stats->rx_err);
36731+ atomic_inc_unchecked(&vcc->stats->rx_err);
36732 IF_ERR(printk("IA: bad packet, dropping it");)
36733 if (status & RX_CER) {
36734 IF_ERR(printk(" cause: packet CRC error\n");)
36735@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36736 len = dma_addr - buf_addr;
36737 if (len > iadev->rx_buf_sz) {
36738 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36739- atomic_inc(&vcc->stats->rx_err);
36740+ atomic_inc_unchecked(&vcc->stats->rx_err);
36741 goto out_free_desc;
36742 }
36743
36744@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36745 ia_vcc = INPH_IA_VCC(vcc);
36746 if (ia_vcc == NULL)
36747 {
36748- atomic_inc(&vcc->stats->rx_err);
36749+ atomic_inc_unchecked(&vcc->stats->rx_err);
36750 atm_return(vcc, skb->truesize);
36751 dev_kfree_skb_any(skb);
36752 goto INCR_DLE;
36753@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36754 if ((length > iadev->rx_buf_sz) || (length >
36755 (skb->len - sizeof(struct cpcs_trailer))))
36756 {
36757- atomic_inc(&vcc->stats->rx_err);
36758+ atomic_inc_unchecked(&vcc->stats->rx_err);
36759 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
36760 length, skb->len);)
36761 atm_return(vcc, skb->truesize);
36762@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36763
36764 IF_RX(printk("rx_dle_intr: skb push");)
36765 vcc->push(vcc,skb);
36766- atomic_inc(&vcc->stats->rx);
36767+ atomic_inc_unchecked(&vcc->stats->rx);
36768 iadev->rx_pkt_cnt++;
36769 }
36770 INCR_DLE:
36771@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
36772 {
36773 struct k_sonet_stats *stats;
36774 stats = &PRIV(_ia_dev[board])->sonet_stats;
36775- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
36776- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
36777- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
36778- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
36779- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
36780- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
36781- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
36782- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
36783- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
36784+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
36785+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
36786+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
36787+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
36788+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
36789+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
36790+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
36791+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
36792+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
36793 }
36794 ia_cmds.status = 0;
36795 break;
36796@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36797 if ((desc == 0) || (desc > iadev->num_tx_desc))
36798 {
36799 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
36800- atomic_inc(&vcc->stats->tx);
36801+ atomic_inc_unchecked(&vcc->stats->tx);
36802 if (vcc->pop)
36803 vcc->pop(vcc, skb);
36804 else
36805@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36806 ATM_DESC(skb) = vcc->vci;
36807 skb_queue_tail(&iadev->tx_dma_q, skb);
36808
36809- atomic_inc(&vcc->stats->tx);
36810+ atomic_inc_unchecked(&vcc->stats->tx);
36811 iadev->tx_pkt_cnt++;
36812 /* Increment transaction counter */
36813 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
36814
36815 #if 0
36816 /* add flow control logic */
36817- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
36818+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
36819 if (iavcc->vc_desc_cnt > 10) {
36820 vcc->tx_quota = vcc->tx_quota * 3 / 4;
36821 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
36822diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
36823index fa7d701..1e404c7 100644
36824--- a/drivers/atm/lanai.c
36825+++ b/drivers/atm/lanai.c
36826@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
36827 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
36828 lanai_endtx(lanai, lvcc);
36829 lanai_free_skb(lvcc->tx.atmvcc, skb);
36830- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
36831+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
36832 }
36833
36834 /* Try to fill the buffer - don't call unless there is backlog */
36835@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
36836 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
36837 __net_timestamp(skb);
36838 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
36839- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
36840+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
36841 out:
36842 lvcc->rx.buf.ptr = end;
36843 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
36844@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36845 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
36846 "vcc %d\n", lanai->number, (unsigned int) s, vci);
36847 lanai->stats.service_rxnotaal5++;
36848- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36849+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36850 return 0;
36851 }
36852 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
36853@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36854 int bytes;
36855 read_unlock(&vcc_sklist_lock);
36856 DPRINTK("got trashed rx pdu on vci %d\n", vci);
36857- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36858+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36859 lvcc->stats.x.aal5.service_trash++;
36860 bytes = (SERVICE_GET_END(s) * 16) -
36861 (((unsigned long) lvcc->rx.buf.ptr) -
36862@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36863 }
36864 if (s & SERVICE_STREAM) {
36865 read_unlock(&vcc_sklist_lock);
36866- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36867+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36868 lvcc->stats.x.aal5.service_stream++;
36869 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
36870 "PDU on VCI %d!\n", lanai->number, vci);
36871@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36872 return 0;
36873 }
36874 DPRINTK("got rx crc error on vci %d\n", vci);
36875- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36876+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36877 lvcc->stats.x.aal5.service_rxcrc++;
36878 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
36879 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
36880diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
36881index 5aca5f4..ce3a6b0 100644
36882--- a/drivers/atm/nicstar.c
36883+++ b/drivers/atm/nicstar.c
36884@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36885 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
36886 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
36887 card->index);
36888- atomic_inc(&vcc->stats->tx_err);
36889+ atomic_inc_unchecked(&vcc->stats->tx_err);
36890 dev_kfree_skb_any(skb);
36891 return -EINVAL;
36892 }
36893@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36894 if (!vc->tx) {
36895 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
36896 card->index);
36897- atomic_inc(&vcc->stats->tx_err);
36898+ atomic_inc_unchecked(&vcc->stats->tx_err);
36899 dev_kfree_skb_any(skb);
36900 return -EINVAL;
36901 }
36902@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36903 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
36904 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
36905 card->index);
36906- atomic_inc(&vcc->stats->tx_err);
36907+ atomic_inc_unchecked(&vcc->stats->tx_err);
36908 dev_kfree_skb_any(skb);
36909 return -EINVAL;
36910 }
36911
36912 if (skb_shinfo(skb)->nr_frags != 0) {
36913 printk("nicstar%d: No scatter-gather yet.\n", card->index);
36914- atomic_inc(&vcc->stats->tx_err);
36915+ atomic_inc_unchecked(&vcc->stats->tx_err);
36916 dev_kfree_skb_any(skb);
36917 return -EINVAL;
36918 }
36919@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36920 }
36921
36922 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
36923- atomic_inc(&vcc->stats->tx_err);
36924+ atomic_inc_unchecked(&vcc->stats->tx_err);
36925 dev_kfree_skb_any(skb);
36926 return -EIO;
36927 }
36928- atomic_inc(&vcc->stats->tx);
36929+ atomic_inc_unchecked(&vcc->stats->tx);
36930
36931 return 0;
36932 }
36933@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36934 printk
36935 ("nicstar%d: Can't allocate buffers for aal0.\n",
36936 card->index);
36937- atomic_add(i, &vcc->stats->rx_drop);
36938+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
36939 break;
36940 }
36941 if (!atm_charge(vcc, sb->truesize)) {
36942 RXPRINTK
36943 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
36944 card->index);
36945- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36946+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36947 dev_kfree_skb_any(sb);
36948 break;
36949 }
36950@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36951 ATM_SKB(sb)->vcc = vcc;
36952 __net_timestamp(sb);
36953 vcc->push(vcc, sb);
36954- atomic_inc(&vcc->stats->rx);
36955+ atomic_inc_unchecked(&vcc->stats->rx);
36956 cell += ATM_CELL_PAYLOAD;
36957 }
36958
36959@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36960 if (iovb == NULL) {
36961 printk("nicstar%d: Out of iovec buffers.\n",
36962 card->index);
36963- atomic_inc(&vcc->stats->rx_drop);
36964+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36965 recycle_rx_buf(card, skb);
36966 return;
36967 }
36968@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36969 small or large buffer itself. */
36970 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
36971 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
36972- atomic_inc(&vcc->stats->rx_err);
36973+ atomic_inc_unchecked(&vcc->stats->rx_err);
36974 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36975 NS_MAX_IOVECS);
36976 NS_PRV_IOVCNT(iovb) = 0;
36977@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36978 ("nicstar%d: Expected a small buffer, and this is not one.\n",
36979 card->index);
36980 which_list(card, skb);
36981- atomic_inc(&vcc->stats->rx_err);
36982+ atomic_inc_unchecked(&vcc->stats->rx_err);
36983 recycle_rx_buf(card, skb);
36984 vc->rx_iov = NULL;
36985 recycle_iov_buf(card, iovb);
36986@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36987 ("nicstar%d: Expected a large buffer, and this is not one.\n",
36988 card->index);
36989 which_list(card, skb);
36990- atomic_inc(&vcc->stats->rx_err);
36991+ atomic_inc_unchecked(&vcc->stats->rx_err);
36992 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36993 NS_PRV_IOVCNT(iovb));
36994 vc->rx_iov = NULL;
36995@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36996 printk(" - PDU size mismatch.\n");
36997 else
36998 printk(".\n");
36999- atomic_inc(&vcc->stats->rx_err);
37000+ atomic_inc_unchecked(&vcc->stats->rx_err);
37001 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37002 NS_PRV_IOVCNT(iovb));
37003 vc->rx_iov = NULL;
37004@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37005 /* skb points to a small buffer */
37006 if (!atm_charge(vcc, skb->truesize)) {
37007 push_rxbufs(card, skb);
37008- atomic_inc(&vcc->stats->rx_drop);
37009+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37010 } else {
37011 skb_put(skb, len);
37012 dequeue_sm_buf(card, skb);
37013@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37014 ATM_SKB(skb)->vcc = vcc;
37015 __net_timestamp(skb);
37016 vcc->push(vcc, skb);
37017- atomic_inc(&vcc->stats->rx);
37018+ atomic_inc_unchecked(&vcc->stats->rx);
37019 }
37020 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37021 struct sk_buff *sb;
37022@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37023 if (len <= NS_SMBUFSIZE) {
37024 if (!atm_charge(vcc, sb->truesize)) {
37025 push_rxbufs(card, sb);
37026- atomic_inc(&vcc->stats->rx_drop);
37027+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37028 } else {
37029 skb_put(sb, len);
37030 dequeue_sm_buf(card, sb);
37031@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37032 ATM_SKB(sb)->vcc = vcc;
37033 __net_timestamp(sb);
37034 vcc->push(vcc, sb);
37035- atomic_inc(&vcc->stats->rx);
37036+ atomic_inc_unchecked(&vcc->stats->rx);
37037 }
37038
37039 push_rxbufs(card, skb);
37040@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37041
37042 if (!atm_charge(vcc, skb->truesize)) {
37043 push_rxbufs(card, skb);
37044- atomic_inc(&vcc->stats->rx_drop);
37045+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37046 } else {
37047 dequeue_lg_buf(card, skb);
37048 #ifdef NS_USE_DESTRUCTORS
37049@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37050 ATM_SKB(skb)->vcc = vcc;
37051 __net_timestamp(skb);
37052 vcc->push(vcc, skb);
37053- atomic_inc(&vcc->stats->rx);
37054+ atomic_inc_unchecked(&vcc->stats->rx);
37055 }
37056
37057 push_rxbufs(card, sb);
37058@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37059 printk
37060 ("nicstar%d: Out of huge buffers.\n",
37061 card->index);
37062- atomic_inc(&vcc->stats->rx_drop);
37063+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37064 recycle_iovec_rx_bufs(card,
37065 (struct iovec *)
37066 iovb->data,
37067@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37068 card->hbpool.count++;
37069 } else
37070 dev_kfree_skb_any(hb);
37071- atomic_inc(&vcc->stats->rx_drop);
37072+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37073 } else {
37074 /* Copy the small buffer to the huge buffer */
37075 sb = (struct sk_buff *)iov->iov_base;
37076@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37077 #endif /* NS_USE_DESTRUCTORS */
37078 __net_timestamp(hb);
37079 vcc->push(vcc, hb);
37080- atomic_inc(&vcc->stats->rx);
37081+ atomic_inc_unchecked(&vcc->stats->rx);
37082 }
37083 }
37084
37085diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37086index 32784d1..4a8434a 100644
37087--- a/drivers/atm/solos-pci.c
37088+++ b/drivers/atm/solos-pci.c
37089@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
37090 }
37091 atm_charge(vcc, skb->truesize);
37092 vcc->push(vcc, skb);
37093- atomic_inc(&vcc->stats->rx);
37094+ atomic_inc_unchecked(&vcc->stats->rx);
37095 break;
37096
37097 case PKT_STATUS:
37098@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37099 vcc = SKB_CB(oldskb)->vcc;
37100
37101 if (vcc) {
37102- atomic_inc(&vcc->stats->tx);
37103+ atomic_inc_unchecked(&vcc->stats->tx);
37104 solos_pop(vcc, oldskb);
37105 } else {
37106 dev_kfree_skb_irq(oldskb);
37107diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37108index 0215934..ce9f5b1 100644
37109--- a/drivers/atm/suni.c
37110+++ b/drivers/atm/suni.c
37111@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37112
37113
37114 #define ADD_LIMITED(s,v) \
37115- atomic_add((v),&stats->s); \
37116- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37117+ atomic_add_unchecked((v),&stats->s); \
37118+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37119
37120
37121 static void suni_hz(unsigned long from_timer)
37122diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37123index 5120a96..e2572bd 100644
37124--- a/drivers/atm/uPD98402.c
37125+++ b/drivers/atm/uPD98402.c
37126@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37127 struct sonet_stats tmp;
37128 int error = 0;
37129
37130- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37131+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37132 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37133 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37134 if (zero && !error) {
37135@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37136
37137
37138 #define ADD_LIMITED(s,v) \
37139- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37140- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37141- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37142+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37143+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37144+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37145
37146
37147 static void stat_event(struct atm_dev *dev)
37148@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37149 if (reason & uPD98402_INT_PFM) stat_event(dev);
37150 if (reason & uPD98402_INT_PCO) {
37151 (void) GET(PCOCR); /* clear interrupt cause */
37152- atomic_add(GET(HECCT),
37153+ atomic_add_unchecked(GET(HECCT),
37154 &PRIV(dev)->sonet_stats.uncorr_hcs);
37155 }
37156 if ((reason & uPD98402_INT_RFO) &&
37157@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37158 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37159 uPD98402_INT_LOS),PIMR); /* enable them */
37160 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37161- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37162- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37163- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37164+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37165+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37166+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37167 return 0;
37168 }
37169
37170diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37171index 969c3c2..9b72956 100644
37172--- a/drivers/atm/zatm.c
37173+++ b/drivers/atm/zatm.c
37174@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37175 }
37176 if (!size) {
37177 dev_kfree_skb_irq(skb);
37178- if (vcc) atomic_inc(&vcc->stats->rx_err);
37179+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37180 continue;
37181 }
37182 if (!atm_charge(vcc,skb->truesize)) {
37183@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37184 skb->len = size;
37185 ATM_SKB(skb)->vcc = vcc;
37186 vcc->push(vcc,skb);
37187- atomic_inc(&vcc->stats->rx);
37188+ atomic_inc_unchecked(&vcc->stats->rx);
37189 }
37190 zout(pos & 0xffff,MTA(mbx));
37191 #if 0 /* probably a stupid idea */
37192@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37193 skb_queue_head(&zatm_vcc->backlog,skb);
37194 break;
37195 }
37196- atomic_inc(&vcc->stats->tx);
37197+ atomic_inc_unchecked(&vcc->stats->tx);
37198 wake_up(&zatm_vcc->tx_wait);
37199 }
37200
37201diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37202index 73f6c29..b0c0e13 100644
37203--- a/drivers/base/bus.c
37204+++ b/drivers/base/bus.c
37205@@ -1115,7 +1115,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37206 return -EINVAL;
37207
37208 mutex_lock(&subsys->p->mutex);
37209- list_add_tail(&sif->node, &subsys->p->interfaces);
37210+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37211 if (sif->add_dev) {
37212 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37213 while ((dev = subsys_dev_iter_next(&iter)))
37214@@ -1140,7 +1140,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37215 subsys = sif->subsys;
37216
37217 mutex_lock(&subsys->p->mutex);
37218- list_del_init(&sif->node);
37219+ pax_list_del_init((struct list_head *)&sif->node);
37220 if (sif->remove_dev) {
37221 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37222 while ((dev = subsys_dev_iter_next(&iter)))
37223diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37224index 0f38201..6c2b444 100644
37225--- a/drivers/base/devtmpfs.c
37226+++ b/drivers/base/devtmpfs.c
37227@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37228 if (!thread)
37229 return 0;
37230
37231- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37232+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37233 if (err)
37234 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37235 else
37236@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37237 *err = sys_unshare(CLONE_NEWNS);
37238 if (*err)
37239 goto out;
37240- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37241+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37242 if (*err)
37243 goto out;
37244- sys_chdir("/.."); /* will traverse into overmounted root */
37245- sys_chroot(".");
37246+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37247+ sys_chroot((char __force_user *)".");
37248 complete(&setup_done);
37249 while (1) {
37250 spin_lock(&req_lock);
37251diff --git a/drivers/base/node.c b/drivers/base/node.c
37252index bc9f43b..29703b8 100644
37253--- a/drivers/base/node.c
37254+++ b/drivers/base/node.c
37255@@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37256 struct node_attr {
37257 struct device_attribute attr;
37258 enum node_states state;
37259-};
37260+} __do_const;
37261
37262 static ssize_t show_node_state(struct device *dev,
37263 struct device_attribute *attr, char *buf)
37264diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37265index bfb8955..4ebff34 100644
37266--- a/drivers/base/power/domain.c
37267+++ b/drivers/base/power/domain.c
37268@@ -1809,9 +1809,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
37269
37270 if (dev->power.subsys_data->domain_data) {
37271 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
37272- gpd_data->ops = (struct gpd_dev_ops){ NULL };
37273+ memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
37274 if (clear_td)
37275- gpd_data->td = (struct gpd_timing_data){ 0 };
37276+ memset(&gpd_data->td, 0, sizeof(gpd_data->td));
37277
37278 if (--gpd_data->refcount == 0) {
37279 dev->power.subsys_data->domain_data = NULL;
37280@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37281 {
37282 struct cpuidle_driver *cpuidle_drv;
37283 struct gpd_cpu_data *cpu_data;
37284- struct cpuidle_state *idle_state;
37285+ cpuidle_state_no_const *idle_state;
37286 int ret = 0;
37287
37288 if (IS_ERR_OR_NULL(genpd) || state < 0)
37289@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37290 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37291 {
37292 struct gpd_cpu_data *cpu_data;
37293- struct cpuidle_state *idle_state;
37294+ cpuidle_state_no_const *idle_state;
37295 int ret = 0;
37296
37297 if (IS_ERR_OR_NULL(genpd))
37298diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37299index 03e089a..0e9560c 100644
37300--- a/drivers/base/power/sysfs.c
37301+++ b/drivers/base/power/sysfs.c
37302@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37303 return -EIO;
37304 }
37305 }
37306- return sprintf(buf, p);
37307+ return sprintf(buf, "%s", p);
37308 }
37309
37310 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37311diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37312index 2d56f41..8830f19 100644
37313--- a/drivers/base/power/wakeup.c
37314+++ b/drivers/base/power/wakeup.c
37315@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
37316 * They need to be modified together atomically, so it's better to use one
37317 * atomic variable to hold them both.
37318 */
37319-static atomic_t combined_event_count = ATOMIC_INIT(0);
37320+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37321
37322 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37323 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37324
37325 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37326 {
37327- unsigned int comb = atomic_read(&combined_event_count);
37328+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
37329
37330 *cnt = (comb >> IN_PROGRESS_BITS);
37331 *inpr = comb & MAX_IN_PROGRESS;
37332@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37333 ws->start_prevent_time = ws->last_time;
37334
37335 /* Increment the counter of events in progress. */
37336- cec = atomic_inc_return(&combined_event_count);
37337+ cec = atomic_inc_return_unchecked(&combined_event_count);
37338
37339 trace_wakeup_source_activate(ws->name, cec);
37340 }
37341@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37342 * Increment the counter of registered wakeup events and decrement the
37343 * couter of wakeup events in progress simultaneously.
37344 */
37345- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37346+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37347 trace_wakeup_source_deactivate(ws->name, cec);
37348
37349 split_counters(&cnt, &inpr);
37350diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37351index e8d11b6..7b1b36f 100644
37352--- a/drivers/base/syscore.c
37353+++ b/drivers/base/syscore.c
37354@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37355 void register_syscore_ops(struct syscore_ops *ops)
37356 {
37357 mutex_lock(&syscore_ops_lock);
37358- list_add_tail(&ops->node, &syscore_ops_list);
37359+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37360 mutex_unlock(&syscore_ops_lock);
37361 }
37362 EXPORT_SYMBOL_GPL(register_syscore_ops);
37363@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37364 void unregister_syscore_ops(struct syscore_ops *ops)
37365 {
37366 mutex_lock(&syscore_ops_lock);
37367- list_del(&ops->node);
37368+ pax_list_del((struct list_head *)&ops->node);
37369 mutex_unlock(&syscore_ops_lock);
37370 }
37371 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37372diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37373index b35fc4f..c902870 100644
37374--- a/drivers/block/cciss.c
37375+++ b/drivers/block/cciss.c
37376@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
37377 while (!list_empty(&h->reqQ)) {
37378 c = list_entry(h->reqQ.next, CommandList_struct, list);
37379 /* can't do anything if fifo is full */
37380- if ((h->access.fifo_full(h))) {
37381+ if ((h->access->fifo_full(h))) {
37382 dev_warn(&h->pdev->dev, "fifo full\n");
37383 break;
37384 }
37385@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
37386 h->Qdepth--;
37387
37388 /* Tell the controller execute command */
37389- h->access.submit_command(h, c);
37390+ h->access->submit_command(h, c);
37391
37392 /* Put job onto the completed Q */
37393 addQ(&h->cmpQ, c);
37394@@ -3447,17 +3447,17 @@ startio:
37395
37396 static inline unsigned long get_next_completion(ctlr_info_t *h)
37397 {
37398- return h->access.command_completed(h);
37399+ return h->access->command_completed(h);
37400 }
37401
37402 static inline int interrupt_pending(ctlr_info_t *h)
37403 {
37404- return h->access.intr_pending(h);
37405+ return h->access->intr_pending(h);
37406 }
37407
37408 static inline long interrupt_not_for_us(ctlr_info_t *h)
37409 {
37410- return ((h->access.intr_pending(h) == 0) ||
37411+ return ((h->access->intr_pending(h) == 0) ||
37412 (h->interrupts_enabled == 0));
37413 }
37414
37415@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
37416 u32 a;
37417
37418 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37419- return h->access.command_completed(h);
37420+ return h->access->command_completed(h);
37421
37422 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37423 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37424@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37425 trans_support & CFGTBL_Trans_use_short_tags);
37426
37427 /* Change the access methods to the performant access methods */
37428- h->access = SA5_performant_access;
37429+ h->access = &SA5_performant_access;
37430 h->transMethod = CFGTBL_Trans_Performant;
37431
37432 return;
37433@@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37434 if (prod_index < 0)
37435 return -ENODEV;
37436 h->product_name = products[prod_index].product_name;
37437- h->access = *(products[prod_index].access);
37438+ h->access = products[prod_index].access;
37439
37440 if (cciss_board_disabled(h)) {
37441 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37442@@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
37443 }
37444
37445 /* make sure the board interrupts are off */
37446- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37447+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37448 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37449 if (rc)
37450 goto clean2;
37451@@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
37452 * fake ones to scoop up any residual completions.
37453 */
37454 spin_lock_irqsave(&h->lock, flags);
37455- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37456+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37457 spin_unlock_irqrestore(&h->lock, flags);
37458 free_irq(h->intr[h->intr_mode], h);
37459 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37460@@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
37461 dev_info(&h->pdev->dev, "Board READY.\n");
37462 dev_info(&h->pdev->dev,
37463 "Waiting for stale completions to drain.\n");
37464- h->access.set_intr_mask(h, CCISS_INTR_ON);
37465+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37466 msleep(10000);
37467- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37468+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37469
37470 rc = controller_reset_failed(h->cfgtable);
37471 if (rc)
37472@@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
37473 cciss_scsi_setup(h);
37474
37475 /* Turn the interrupts on so we can service requests */
37476- h->access.set_intr_mask(h, CCISS_INTR_ON);
37477+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37478
37479 /* Get the firmware version */
37480 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37481@@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37482 kfree(flush_buf);
37483 if (return_code != IO_OK)
37484 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37485- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37486+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37487 free_irq(h->intr[h->intr_mode], h);
37488 }
37489
37490diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37491index 7fda30e..2f27946 100644
37492--- a/drivers/block/cciss.h
37493+++ b/drivers/block/cciss.h
37494@@ -101,7 +101,7 @@ struct ctlr_info
37495 /* information about each logical volume */
37496 drive_info_struct *drv[CISS_MAX_LUN];
37497
37498- struct access_method access;
37499+ struct access_method *access;
37500
37501 /* queue and queue Info */
37502 struct list_head reqQ;
37503@@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37504 }
37505
37506 static struct access_method SA5_access = {
37507- SA5_submit_command,
37508- SA5_intr_mask,
37509- SA5_fifo_full,
37510- SA5_intr_pending,
37511- SA5_completed,
37512+ .submit_command = SA5_submit_command,
37513+ .set_intr_mask = SA5_intr_mask,
37514+ .fifo_full = SA5_fifo_full,
37515+ .intr_pending = SA5_intr_pending,
37516+ .command_completed = SA5_completed,
37517 };
37518
37519 static struct access_method SA5B_access = {
37520- SA5_submit_command,
37521- SA5B_intr_mask,
37522- SA5_fifo_full,
37523- SA5B_intr_pending,
37524- SA5_completed,
37525+ .submit_command = SA5_submit_command,
37526+ .set_intr_mask = SA5B_intr_mask,
37527+ .fifo_full = SA5_fifo_full,
37528+ .intr_pending = SA5B_intr_pending,
37529+ .command_completed = SA5_completed,
37530 };
37531
37532 static struct access_method SA5_performant_access = {
37533- SA5_submit_command,
37534- SA5_performant_intr_mask,
37535- SA5_fifo_full,
37536- SA5_performant_intr_pending,
37537- SA5_performant_completed,
37538+ .submit_command = SA5_submit_command,
37539+ .set_intr_mask = SA5_performant_intr_mask,
37540+ .fifo_full = SA5_fifo_full,
37541+ .intr_pending = SA5_performant_intr_pending,
37542+ .command_completed = SA5_performant_completed,
37543 };
37544
37545 struct board_type {
37546diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37547index 2b94403..fd6ad1f 100644
37548--- a/drivers/block/cpqarray.c
37549+++ b/drivers/block/cpqarray.c
37550@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37551 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37552 goto Enomem4;
37553 }
37554- hba[i]->access.set_intr_mask(hba[i], 0);
37555+ hba[i]->access->set_intr_mask(hba[i], 0);
37556 if (request_irq(hba[i]->intr, do_ida_intr,
37557 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37558 {
37559@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37560 add_timer(&hba[i]->timer);
37561
37562 /* Enable IRQ now that spinlock and rate limit timer are set up */
37563- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37564+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37565
37566 for(j=0; j<NWD; j++) {
37567 struct gendisk *disk = ida_gendisk[i][j];
37568@@ -694,7 +694,7 @@ DBGINFO(
37569 for(i=0; i<NR_PRODUCTS; i++) {
37570 if (board_id == products[i].board_id) {
37571 c->product_name = products[i].product_name;
37572- c->access = *(products[i].access);
37573+ c->access = products[i].access;
37574 break;
37575 }
37576 }
37577@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37578 hba[ctlr]->intr = intr;
37579 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37580 hba[ctlr]->product_name = products[j].product_name;
37581- hba[ctlr]->access = *(products[j].access);
37582+ hba[ctlr]->access = products[j].access;
37583 hba[ctlr]->ctlr = ctlr;
37584 hba[ctlr]->board_id = board_id;
37585 hba[ctlr]->pci_dev = NULL; /* not PCI */
37586@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37587
37588 while((c = h->reqQ) != NULL) {
37589 /* Can't do anything if we're busy */
37590- if (h->access.fifo_full(h) == 0)
37591+ if (h->access->fifo_full(h) == 0)
37592 return;
37593
37594 /* Get the first entry from the request Q */
37595@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37596 h->Qdepth--;
37597
37598 /* Tell the controller to do our bidding */
37599- h->access.submit_command(h, c);
37600+ h->access->submit_command(h, c);
37601
37602 /* Get onto the completion Q */
37603 addQ(&h->cmpQ, c);
37604@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37605 unsigned long flags;
37606 __u32 a,a1;
37607
37608- istat = h->access.intr_pending(h);
37609+ istat = h->access->intr_pending(h);
37610 /* Is this interrupt for us? */
37611 if (istat == 0)
37612 return IRQ_NONE;
37613@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37614 */
37615 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37616 if (istat & FIFO_NOT_EMPTY) {
37617- while((a = h->access.command_completed(h))) {
37618+ while((a = h->access->command_completed(h))) {
37619 a1 = a; a &= ~3;
37620 if ((c = h->cmpQ) == NULL)
37621 {
37622@@ -1448,11 +1448,11 @@ static int sendcmd(
37623 /*
37624 * Disable interrupt
37625 */
37626- info_p->access.set_intr_mask(info_p, 0);
37627+ info_p->access->set_intr_mask(info_p, 0);
37628 /* Make sure there is room in the command FIFO */
37629 /* Actually it should be completely empty at this time. */
37630 for (i = 200000; i > 0; i--) {
37631- temp = info_p->access.fifo_full(info_p);
37632+ temp = info_p->access->fifo_full(info_p);
37633 if (temp != 0) {
37634 break;
37635 }
37636@@ -1465,7 +1465,7 @@ DBG(
37637 /*
37638 * Send the cmd
37639 */
37640- info_p->access.submit_command(info_p, c);
37641+ info_p->access->submit_command(info_p, c);
37642 complete = pollcomplete(ctlr);
37643
37644 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37645@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37646 * we check the new geometry. Then turn interrupts back on when
37647 * we're done.
37648 */
37649- host->access.set_intr_mask(host, 0);
37650+ host->access->set_intr_mask(host, 0);
37651 getgeometry(ctlr);
37652- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37653+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37654
37655 for(i=0; i<NWD; i++) {
37656 struct gendisk *disk = ida_gendisk[ctlr][i];
37657@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37658 /* Wait (up to 2 seconds) for a command to complete */
37659
37660 for (i = 200000; i > 0; i--) {
37661- done = hba[ctlr]->access.command_completed(hba[ctlr]);
37662+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
37663 if (done == 0) {
37664 udelay(10); /* a short fixed delay */
37665 } else
37666diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37667index be73e9d..7fbf140 100644
37668--- a/drivers/block/cpqarray.h
37669+++ b/drivers/block/cpqarray.h
37670@@ -99,7 +99,7 @@ struct ctlr_info {
37671 drv_info_t drv[NWD];
37672 struct proc_dir_entry *proc;
37673
37674- struct access_method access;
37675+ struct access_method *access;
37676
37677 cmdlist_t *reqQ;
37678 cmdlist_t *cmpQ;
37679diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37680index 0e06f0c..c47b81d 100644
37681--- a/drivers/block/drbd/drbd_int.h
37682+++ b/drivers/block/drbd/drbd_int.h
37683@@ -582,7 +582,7 @@ struct drbd_epoch {
37684 struct drbd_tconn *tconn;
37685 struct list_head list;
37686 unsigned int barrier_nr;
37687- atomic_t epoch_size; /* increased on every request added. */
37688+ atomic_unchecked_t epoch_size; /* increased on every request added. */
37689 atomic_t active; /* increased on every req. added, and dec on every finished. */
37690 unsigned long flags;
37691 };
37692@@ -1022,7 +1022,7 @@ struct drbd_conf {
37693 unsigned int al_tr_number;
37694 int al_tr_cycle;
37695 wait_queue_head_t seq_wait;
37696- atomic_t packet_seq;
37697+ atomic_unchecked_t packet_seq;
37698 unsigned int peer_seq;
37699 spinlock_t peer_seq_lock;
37700 unsigned int minor;
37701@@ -1573,7 +1573,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37702 char __user *uoptval;
37703 int err;
37704
37705- uoptval = (char __user __force *)optval;
37706+ uoptval = (char __force_user *)optval;
37707
37708 set_fs(KERNEL_DS);
37709 if (level == SOL_SOCKET)
37710diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
37711index 89c497c..9c736ae 100644
37712--- a/drivers/block/drbd/drbd_interval.c
37713+++ b/drivers/block/drbd/drbd_interval.c
37714@@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
37715 }
37716
37717 static const struct rb_augment_callbacks augment_callbacks = {
37718- augment_propagate,
37719- augment_copy,
37720- augment_rotate,
37721+ .propagate = augment_propagate,
37722+ .copy = augment_copy,
37723+ .rotate = augment_rotate,
37724 };
37725
37726 /**
37727diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37728index 9e3818b..7b64c92 100644
37729--- a/drivers/block/drbd/drbd_main.c
37730+++ b/drivers/block/drbd/drbd_main.c
37731@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
37732 p->sector = sector;
37733 p->block_id = block_id;
37734 p->blksize = blksize;
37735- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37736+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37737 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
37738 }
37739
37740@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
37741 return -EIO;
37742 p->sector = cpu_to_be64(req->i.sector);
37743 p->block_id = (unsigned long)req;
37744- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37745+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37746 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
37747 if (mdev->state.conn >= C_SYNC_SOURCE &&
37748 mdev->state.conn <= C_PAUSED_SYNC_T)
37749@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
37750 {
37751 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
37752
37753- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
37754- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
37755+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
37756+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
37757 kfree(tconn->current_epoch);
37758
37759 idr_destroy(&tconn->volumes);
37760diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
37761index c706d50..5e1b472 100644
37762--- a/drivers/block/drbd/drbd_nl.c
37763+++ b/drivers/block/drbd/drbd_nl.c
37764@@ -3440,7 +3440,7 @@ out:
37765
37766 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37767 {
37768- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37769+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37770 struct sk_buff *msg;
37771 struct drbd_genlmsghdr *d_out;
37772 unsigned seq;
37773@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37774 return;
37775 }
37776
37777- seq = atomic_inc_return(&drbd_genl_seq);
37778+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
37779 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
37780 if (!msg)
37781 goto failed;
37782diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
37783index 6fa6673..b7f97e9 100644
37784--- a/drivers/block/drbd/drbd_receiver.c
37785+++ b/drivers/block/drbd/drbd_receiver.c
37786@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
37787 {
37788 int err;
37789
37790- atomic_set(&mdev->packet_seq, 0);
37791+ atomic_set_unchecked(&mdev->packet_seq, 0);
37792 mdev->peer_seq = 0;
37793
37794 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
37795@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37796 do {
37797 next_epoch = NULL;
37798
37799- epoch_size = atomic_read(&epoch->epoch_size);
37800+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
37801
37802 switch (ev & ~EV_CLEANUP) {
37803 case EV_PUT:
37804@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37805 rv = FE_DESTROYED;
37806 } else {
37807 epoch->flags = 0;
37808- atomic_set(&epoch->epoch_size, 0);
37809+ atomic_set_unchecked(&epoch->epoch_size, 0);
37810 /* atomic_set(&epoch->active, 0); is already zero */
37811 if (rv == FE_STILL_LIVE)
37812 rv = FE_RECYCLED;
37813@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37814 conn_wait_active_ee_empty(tconn);
37815 drbd_flush(tconn);
37816
37817- if (atomic_read(&tconn->current_epoch->epoch_size)) {
37818+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37819 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
37820 if (epoch)
37821 break;
37822@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37823 }
37824
37825 epoch->flags = 0;
37826- atomic_set(&epoch->epoch_size, 0);
37827+ atomic_set_unchecked(&epoch->epoch_size, 0);
37828 atomic_set(&epoch->active, 0);
37829
37830 spin_lock(&tconn->epoch_lock);
37831- if (atomic_read(&tconn->current_epoch->epoch_size)) {
37832+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37833 list_add(&epoch->list, &tconn->current_epoch->list);
37834 tconn->current_epoch = epoch;
37835 tconn->epochs++;
37836@@ -2163,7 +2163,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37837
37838 err = wait_for_and_update_peer_seq(mdev, peer_seq);
37839 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
37840- atomic_inc(&tconn->current_epoch->epoch_size);
37841+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
37842 err2 = drbd_drain_block(mdev, pi->size);
37843 if (!err)
37844 err = err2;
37845@@ -2197,7 +2197,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37846
37847 spin_lock(&tconn->epoch_lock);
37848 peer_req->epoch = tconn->current_epoch;
37849- atomic_inc(&peer_req->epoch->epoch_size);
37850+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
37851 atomic_inc(&peer_req->epoch->active);
37852 spin_unlock(&tconn->epoch_lock);
37853
37854@@ -4344,7 +4344,7 @@ struct data_cmd {
37855 int expect_payload;
37856 size_t pkt_size;
37857 int (*fn)(struct drbd_tconn *, struct packet_info *);
37858-};
37859+} __do_const;
37860
37861 static struct data_cmd drbd_cmd_handler[] = {
37862 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
37863@@ -4464,7 +4464,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
37864 if (!list_empty(&tconn->current_epoch->list))
37865 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
37866 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
37867- atomic_set(&tconn->current_epoch->epoch_size, 0);
37868+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
37869 tconn->send.seen_any_write_yet = false;
37870
37871 conn_info(tconn, "Connection closed\n");
37872@@ -5220,7 +5220,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
37873 struct asender_cmd {
37874 size_t pkt_size;
37875 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
37876-};
37877+} __do_const;
37878
37879 static struct asender_cmd asender_tbl[] = {
37880 [P_PING] = { 0, got_Ping },
37881diff --git a/drivers/block/loop.c b/drivers/block/loop.c
37882index c8dac73..1800093 100644
37883--- a/drivers/block/loop.c
37884+++ b/drivers/block/loop.c
37885@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
37886
37887 file_start_write(file);
37888 set_fs(get_ds());
37889- bw = file->f_op->write(file, buf, len, &pos);
37890+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
37891 set_fs(old_fs);
37892 file_end_write(file);
37893 if (likely(bw == len))
37894diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
37895index 83a598e..2de5ce3 100644
37896--- a/drivers/block/null_blk.c
37897+++ b/drivers/block/null_blk.c
37898@@ -407,14 +407,24 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
37899 return 0;
37900 }
37901
37902-static struct blk_mq_ops null_mq_ops = {
37903- .queue_rq = null_queue_rq,
37904- .map_queue = blk_mq_map_queue,
37905+static struct blk_mq_ops null_mq_single_ops = {
37906+ .queue_rq = null_queue_rq,
37907+ .map_queue = blk_mq_map_queue,
37908 .init_hctx = null_init_hctx,
37909+ .alloc_hctx = blk_mq_alloc_single_hw_queue,
37910+ .free_hctx = blk_mq_free_single_hw_queue,
37911+};
37912+
37913+static struct blk_mq_ops null_mq_per_node_ops = {
37914+ .queue_rq = null_queue_rq,
37915+ .map_queue = blk_mq_map_queue,
37916+ .init_hctx = null_init_hctx,
37917+ .alloc_hctx = null_alloc_hctx,
37918+ .free_hctx = null_free_hctx,
37919 };
37920
37921 static struct blk_mq_reg null_mq_reg = {
37922- .ops = &null_mq_ops,
37923+ .ops = &null_mq_single_ops,
37924 .queue_depth = 64,
37925 .cmd_size = sizeof(struct nullb_cmd),
37926 .flags = BLK_MQ_F_SHOULD_MERGE,
37927@@ -545,13 +555,8 @@ static int null_add_dev(void)
37928 null_mq_reg.queue_depth = hw_queue_depth;
37929 null_mq_reg.nr_hw_queues = submit_queues;
37930
37931- if (use_per_node_hctx) {
37932- null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
37933- null_mq_reg.ops->free_hctx = null_free_hctx;
37934- } else {
37935- null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
37936- null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
37937- }
37938+ if (use_per_node_hctx)
37939+ null_mq_reg.ops = &null_mq_per_node_ops;
37940
37941 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
37942 } else if (queue_mode == NULL_Q_BIO) {
37943diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
37944index ff8668c..f62167a 100644
37945--- a/drivers/block/pktcdvd.c
37946+++ b/drivers/block/pktcdvd.c
37947@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
37948
37949 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
37950 {
37951- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
37952+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
37953 }
37954
37955 /*
37956@@ -1883,7 +1883,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
37957 return -EROFS;
37958 }
37959 pd->settings.fp = ti.fp;
37960- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
37961+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
37962
37963 if (ti.nwa_v) {
37964 pd->nwa = be32_to_cpu(ti.next_writable);
37965diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
37966index e5565fb..71be10b4 100644
37967--- a/drivers/block/smart1,2.h
37968+++ b/drivers/block/smart1,2.h
37969@@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
37970 }
37971
37972 static struct access_method smart4_access = {
37973- smart4_submit_command,
37974- smart4_intr_mask,
37975- smart4_fifo_full,
37976- smart4_intr_pending,
37977- smart4_completed,
37978+ .submit_command = smart4_submit_command,
37979+ .set_intr_mask = smart4_intr_mask,
37980+ .fifo_full = smart4_fifo_full,
37981+ .intr_pending = smart4_intr_pending,
37982+ .command_completed = smart4_completed,
37983 };
37984
37985 /*
37986@@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
37987 }
37988
37989 static struct access_method smart2_access = {
37990- smart2_submit_command,
37991- smart2_intr_mask,
37992- smart2_fifo_full,
37993- smart2_intr_pending,
37994- smart2_completed,
37995+ .submit_command = smart2_submit_command,
37996+ .set_intr_mask = smart2_intr_mask,
37997+ .fifo_full = smart2_fifo_full,
37998+ .intr_pending = smart2_intr_pending,
37999+ .command_completed = smart2_completed,
38000 };
38001
38002 /*
38003@@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38004 }
38005
38006 static struct access_method smart2e_access = {
38007- smart2e_submit_command,
38008- smart2e_intr_mask,
38009- smart2e_fifo_full,
38010- smart2e_intr_pending,
38011- smart2e_completed,
38012+ .submit_command = smart2e_submit_command,
38013+ .set_intr_mask = smart2e_intr_mask,
38014+ .fifo_full = smart2e_fifo_full,
38015+ .intr_pending = smart2e_intr_pending,
38016+ .command_completed = smart2e_completed,
38017 };
38018
38019 /*
38020@@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38021 }
38022
38023 static struct access_method smart1_access = {
38024- smart1_submit_command,
38025- smart1_intr_mask,
38026- smart1_fifo_full,
38027- smart1_intr_pending,
38028- smart1_completed,
38029+ .submit_command = smart1_submit_command,
38030+ .set_intr_mask = smart1_intr_mask,
38031+ .fifo_full = smart1_fifo_full,
38032+ .intr_pending = smart1_intr_pending,
38033+ .command_completed = smart1_completed,
38034 };
38035diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38036index f038dba..bb74c08 100644
38037--- a/drivers/bluetooth/btwilink.c
38038+++ b/drivers/bluetooth/btwilink.c
38039@@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38040
38041 static int bt_ti_probe(struct platform_device *pdev)
38042 {
38043- static struct ti_st *hst;
38044+ struct ti_st *hst;
38045 struct hci_dev *hdev;
38046 int err;
38047
38048diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
38049index b6739cb..962fd35 100644
38050--- a/drivers/bus/arm-cci.c
38051+++ b/drivers/bus/arm-cci.c
38052@@ -979,7 +979,7 @@ static int cci_probe(void)
38053
38054 nb_cci_ports = cci_config->nb_ace + cci_config->nb_ace_lite;
38055
38056- ports = kcalloc(sizeof(*ports), nb_cci_ports, GFP_KERNEL);
38057+ ports = kcalloc(nb_cci_ports, sizeof(*ports), GFP_KERNEL);
38058 if (!ports)
38059 return -ENOMEM;
38060
38061diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38062index 8a3aff7..d7538c2 100644
38063--- a/drivers/cdrom/cdrom.c
38064+++ b/drivers/cdrom/cdrom.c
38065@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38066 ENSURE(reset, CDC_RESET);
38067 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38068 cdi->mc_flags = 0;
38069- cdo->n_minors = 0;
38070 cdi->options = CDO_USE_FFLAGS;
38071
38072 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
38073@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38074 else
38075 cdi->cdda_method = CDDA_OLD;
38076
38077- if (!cdo->generic_packet)
38078- cdo->generic_packet = cdrom_dummy_generic_packet;
38079+ if (!cdo->generic_packet) {
38080+ pax_open_kernel();
38081+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38082+ pax_close_kernel();
38083+ }
38084
38085 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38086 mutex_lock(&cdrom_mutex);
38087@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38088 if (cdi->exit)
38089 cdi->exit(cdi);
38090
38091- cdi->ops->n_minors--;
38092 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38093 }
38094
38095@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38096 */
38097 nr = nframes;
38098 do {
38099- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38100+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38101 if (cgc.buffer)
38102 break;
38103
38104@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38105 struct cdrom_device_info *cdi;
38106 int ret;
38107
38108- ret = scnprintf(info + *pos, max_size - *pos, header);
38109+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38110 if (!ret)
38111 return 1;
38112
38113diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38114index 5980cb9..6d7bd7e 100644
38115--- a/drivers/cdrom/gdrom.c
38116+++ b/drivers/cdrom/gdrom.c
38117@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38118 .audio_ioctl = gdrom_audio_ioctl,
38119 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38120 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38121- .n_minors = 1,
38122 };
38123
38124 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38125diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38126index fa3243d..8c98297 100644
38127--- a/drivers/char/Kconfig
38128+++ b/drivers/char/Kconfig
38129@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38130
38131 config DEVKMEM
38132 bool "/dev/kmem virtual device support"
38133- default y
38134+ default n
38135+ depends on !GRKERNSEC_KMEM
38136 help
38137 Say Y here if you want to support the /dev/kmem device. The
38138 /dev/kmem device is rarely used, but can be used for certain
38139@@ -576,6 +577,7 @@ config DEVPORT
38140 bool
38141 depends on !M68K
38142 depends on ISA || PCI
38143+ depends on !GRKERNSEC_KMEM
38144 default y
38145
38146 source "drivers/s390/char/Kconfig"
38147diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38148index a48e05b..6bac831 100644
38149--- a/drivers/char/agp/compat_ioctl.c
38150+++ b/drivers/char/agp/compat_ioctl.c
38151@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38152 return -ENOMEM;
38153 }
38154
38155- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38156+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38157 sizeof(*usegment) * ureserve.seg_count)) {
38158 kfree(usegment);
38159 kfree(ksegment);
38160diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38161index 1b19239..b87b143 100644
38162--- a/drivers/char/agp/frontend.c
38163+++ b/drivers/char/agp/frontend.c
38164@@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38165 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38166 return -EFAULT;
38167
38168- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38169+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38170 return -EFAULT;
38171
38172 client = agp_find_client_by_pid(reserve.pid);
38173@@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38174 if (segment == NULL)
38175 return -ENOMEM;
38176
38177- if (copy_from_user(segment, (void __user *) reserve.seg_list,
38178+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38179 sizeof(struct agp_segment) * reserve.seg_count)) {
38180 kfree(segment);
38181 return -EFAULT;
38182diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38183index 4f94375..413694e 100644
38184--- a/drivers/char/genrtc.c
38185+++ b/drivers/char/genrtc.c
38186@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38187 switch (cmd) {
38188
38189 case RTC_PLL_GET:
38190+ memset(&pll, 0, sizeof(pll));
38191 if (get_rtc_pll(&pll))
38192 return -EINVAL;
38193 else
38194diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38195index 5d9c31d..c94ccb5 100644
38196--- a/drivers/char/hpet.c
38197+++ b/drivers/char/hpet.c
38198@@ -578,7 +578,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38199 }
38200
38201 static int
38202-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38203+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38204 struct hpet_info *info)
38205 {
38206 struct hpet_timer __iomem *timer;
38207diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
38208index 86fe45c..c0ea948 100644
38209--- a/drivers/char/hw_random/intel-rng.c
38210+++ b/drivers/char/hw_random/intel-rng.c
38211@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
38212
38213 if (no_fwh_detect)
38214 return -ENODEV;
38215- printk(warning);
38216+ printk("%s", warning);
38217 return -EBUSY;
38218 }
38219
38220diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38221index ec4e10f..f2a763b 100644
38222--- a/drivers/char/ipmi/ipmi_msghandler.c
38223+++ b/drivers/char/ipmi/ipmi_msghandler.c
38224@@ -420,7 +420,7 @@ struct ipmi_smi {
38225 struct proc_dir_entry *proc_dir;
38226 char proc_dir_name[10];
38227
38228- atomic_t stats[IPMI_NUM_STATS];
38229+ atomic_unchecked_t stats[IPMI_NUM_STATS];
38230
38231 /*
38232 * run_to_completion duplicate of smb_info, smi_info
38233@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
38234
38235
38236 #define ipmi_inc_stat(intf, stat) \
38237- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38238+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38239 #define ipmi_get_stat(intf, stat) \
38240- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38241+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38242
38243 static int is_lan_addr(struct ipmi_addr *addr)
38244 {
38245@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38246 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38247 init_waitqueue_head(&intf->waitq);
38248 for (i = 0; i < IPMI_NUM_STATS; i++)
38249- atomic_set(&intf->stats[i], 0);
38250+ atomic_set_unchecked(&intf->stats[i], 0);
38251
38252 intf->proc_dir = NULL;
38253
38254diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38255index 15e4a60..b046093 100644
38256--- a/drivers/char/ipmi/ipmi_si_intf.c
38257+++ b/drivers/char/ipmi/ipmi_si_intf.c
38258@@ -280,7 +280,7 @@ struct smi_info {
38259 unsigned char slave_addr;
38260
38261 /* Counters and things for the proc filesystem. */
38262- atomic_t stats[SI_NUM_STATS];
38263+ atomic_unchecked_t stats[SI_NUM_STATS];
38264
38265 struct task_struct *thread;
38266
38267@@ -289,9 +289,9 @@ struct smi_info {
38268 };
38269
38270 #define smi_inc_stat(smi, stat) \
38271- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38272+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38273 #define smi_get_stat(smi, stat) \
38274- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38275+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38276
38277 #define SI_MAX_PARMS 4
38278
38279@@ -3324,7 +3324,7 @@ static int try_smi_init(struct smi_info *new_smi)
38280 atomic_set(&new_smi->req_events, 0);
38281 new_smi->run_to_completion = 0;
38282 for (i = 0; i < SI_NUM_STATS; i++)
38283- atomic_set(&new_smi->stats[i], 0);
38284+ atomic_set_unchecked(&new_smi->stats[i], 0);
38285
38286 new_smi->interrupt_disabled = 1;
38287 atomic_set(&new_smi->stop_operation, 0);
38288diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38289index f895a8c..2bc9147 100644
38290--- a/drivers/char/mem.c
38291+++ b/drivers/char/mem.c
38292@@ -18,6 +18,7 @@
38293 #include <linux/raw.h>
38294 #include <linux/tty.h>
38295 #include <linux/capability.h>
38296+#include <linux/security.h>
38297 #include <linux/ptrace.h>
38298 #include <linux/device.h>
38299 #include <linux/highmem.h>
38300@@ -37,6 +38,10 @@
38301
38302 #define DEVPORT_MINOR 4
38303
38304+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38305+extern const struct file_operations grsec_fops;
38306+#endif
38307+
38308 static inline unsigned long size_inside_page(unsigned long start,
38309 unsigned long size)
38310 {
38311@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38312
38313 while (cursor < to) {
38314 if (!devmem_is_allowed(pfn)) {
38315+#ifdef CONFIG_GRKERNSEC_KMEM
38316+ gr_handle_mem_readwrite(from, to);
38317+#else
38318 printk(KERN_INFO
38319 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38320 current->comm, from, to);
38321+#endif
38322 return 0;
38323 }
38324 cursor += PAGE_SIZE;
38325@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38326 }
38327 return 1;
38328 }
38329+#elif defined(CONFIG_GRKERNSEC_KMEM)
38330+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38331+{
38332+ return 0;
38333+}
38334 #else
38335 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38336 {
38337@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38338
38339 while (count > 0) {
38340 unsigned long remaining;
38341+ char *temp;
38342
38343 sz = size_inside_page(p, count);
38344
38345@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38346 if (!ptr)
38347 return -EFAULT;
38348
38349- remaining = copy_to_user(buf, ptr, sz);
38350+#ifdef CONFIG_PAX_USERCOPY
38351+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38352+ if (!temp) {
38353+ unxlate_dev_mem_ptr(p, ptr);
38354+ return -ENOMEM;
38355+ }
38356+ memcpy(temp, ptr, sz);
38357+#else
38358+ temp = ptr;
38359+#endif
38360+
38361+ remaining = copy_to_user(buf, temp, sz);
38362+
38363+#ifdef CONFIG_PAX_USERCOPY
38364+ kfree(temp);
38365+#endif
38366+
38367 unxlate_dev_mem_ptr(p, ptr);
38368 if (remaining)
38369 return -EFAULT;
38370@@ -364,9 +395,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38371 size_t count, loff_t *ppos)
38372 {
38373 unsigned long p = *ppos;
38374- ssize_t low_count, read, sz;
38375+ ssize_t low_count, read, sz, err = 0;
38376 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38377- int err = 0;
38378
38379 read = 0;
38380 if (p < (unsigned long) high_memory) {
38381@@ -388,6 +418,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38382 }
38383 #endif
38384 while (low_count > 0) {
38385+ char *temp;
38386+
38387 sz = size_inside_page(p, low_count);
38388
38389 /*
38390@@ -397,7 +429,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38391 */
38392 kbuf = xlate_dev_kmem_ptr((char *)p);
38393
38394- if (copy_to_user(buf, kbuf, sz))
38395+#ifdef CONFIG_PAX_USERCOPY
38396+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38397+ if (!temp)
38398+ return -ENOMEM;
38399+ memcpy(temp, kbuf, sz);
38400+#else
38401+ temp = kbuf;
38402+#endif
38403+
38404+ err = copy_to_user(buf, temp, sz);
38405+
38406+#ifdef CONFIG_PAX_USERCOPY
38407+ kfree(temp);
38408+#endif
38409+
38410+ if (err)
38411 return -EFAULT;
38412 buf += sz;
38413 p += sz;
38414@@ -822,6 +869,9 @@ static const struct memdev {
38415 #ifdef CONFIG_PRINTK
38416 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38417 #endif
38418+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38419+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38420+#endif
38421 };
38422
38423 static int memory_open(struct inode *inode, struct file *filp)
38424@@ -893,7 +943,7 @@ static int __init chr_dev_init(void)
38425 continue;
38426
38427 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38428- NULL, devlist[minor].name);
38429+ NULL, "%s", devlist[minor].name);
38430 }
38431
38432 return tty_init();
38433diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38434index 9df78e2..01ba9ae 100644
38435--- a/drivers/char/nvram.c
38436+++ b/drivers/char/nvram.c
38437@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38438
38439 spin_unlock_irq(&rtc_lock);
38440
38441- if (copy_to_user(buf, contents, tmp - contents))
38442+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38443 return -EFAULT;
38444
38445 *ppos = i;
38446diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38447index d39cca6..8c1e269 100644
38448--- a/drivers/char/pcmcia/synclink_cs.c
38449+++ b/drivers/char/pcmcia/synclink_cs.c
38450@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38451
38452 if (debug_level >= DEBUG_LEVEL_INFO)
38453 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38454- __FILE__, __LINE__, info->device_name, port->count);
38455+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38456
38457- WARN_ON(!port->count);
38458+ WARN_ON(!atomic_read(&port->count));
38459
38460 if (tty_port_close_start(port, tty, filp) == 0)
38461 goto cleanup;
38462@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38463 cleanup:
38464 if (debug_level >= DEBUG_LEVEL_INFO)
38465 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38466- tty->driver->name, port->count);
38467+ tty->driver->name, atomic_read(&port->count));
38468 }
38469
38470 /* Wait until the transmitter is empty.
38471@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38472
38473 if (debug_level >= DEBUG_LEVEL_INFO)
38474 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38475- __FILE__, __LINE__, tty->driver->name, port->count);
38476+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38477
38478 /* If port is closing, signal caller to try again */
38479 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
38480@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38481 goto cleanup;
38482 }
38483 spin_lock(&port->lock);
38484- port->count++;
38485+ atomic_inc(&port->count);
38486 spin_unlock(&port->lock);
38487 spin_unlock_irqrestore(&info->netlock, flags);
38488
38489- if (port->count == 1) {
38490+ if (atomic_read(&port->count) == 1) {
38491 /* 1st open on this device, init hardware */
38492 retval = startup(info, tty);
38493 if (retval < 0)
38494@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38495 unsigned short new_crctype;
38496
38497 /* return error if TTY interface open */
38498- if (info->port.count)
38499+ if (atomic_read(&info->port.count))
38500 return -EBUSY;
38501
38502 switch (encoding)
38503@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
38504
38505 /* arbitrate between network and tty opens */
38506 spin_lock_irqsave(&info->netlock, flags);
38507- if (info->port.count != 0 || info->netcount != 0) {
38508+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38509 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38510 spin_unlock_irqrestore(&info->netlock, flags);
38511 return -EBUSY;
38512@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38513 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38514
38515 /* return error if TTY interface open */
38516- if (info->port.count)
38517+ if (atomic_read(&info->port.count))
38518 return -EBUSY;
38519
38520 if (cmd != SIOCWANDEV)
38521diff --git a/drivers/char/random.c b/drivers/char/random.c
38522index 429b75b..a7f4145 100644
38523--- a/drivers/char/random.c
38524+++ b/drivers/char/random.c
38525@@ -270,10 +270,17 @@
38526 /*
38527 * Configuration information
38528 */
38529+#ifdef CONFIG_GRKERNSEC_RANDNET
38530+#define INPUT_POOL_SHIFT 14
38531+#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38532+#define OUTPUT_POOL_SHIFT 12
38533+#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38534+#else
38535 #define INPUT_POOL_SHIFT 12
38536 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38537 #define OUTPUT_POOL_SHIFT 10
38538 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38539+#endif
38540 #define SEC_XFER_SIZE 512
38541 #define EXTRACT_SIZE 10
38542
38543@@ -284,9 +291,6 @@
38544 /*
38545 * To allow fractional bits to be tracked, the entropy_count field is
38546 * denominated in units of 1/8th bits.
38547- *
38548- * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38549- * credit_entropy_bits() needs to be 64 bits wide.
38550 */
38551 #define ENTROPY_SHIFT 3
38552 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38553@@ -361,12 +365,19 @@ static struct poolinfo {
38554 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
38555 int tap1, tap2, tap3, tap4, tap5;
38556 } poolinfo_table[] = {
38557+#ifdef CONFIG_GRKERNSEC_RANDNET
38558+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
38559+ { S(512), 411, 308, 208, 104, 1 },
38560+ /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
38561+ { S(128), 104, 76, 51, 25, 1 },
38562+#else
38563 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
38564 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
38565 { S(128), 104, 76, 51, 25, 1 },
38566 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
38567 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
38568 { S(32), 26, 19, 14, 7, 1 },
38569+#endif
38570 #if 0
38571 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
38572 { S(2048), 1638, 1231, 819, 411, 1 },
38573@@ -433,9 +444,9 @@ struct entropy_store {
38574 };
38575
38576 static void push_to_pool(struct work_struct *work);
38577-static __u32 input_pool_data[INPUT_POOL_WORDS];
38578-static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38579-static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38580+static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38581+static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38582+static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38583
38584 static struct entropy_store input_pool = {
38585 .poolinfo = &poolinfo_table[0],
38586@@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
38587 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
38588 }
38589
38590- ACCESS_ONCE(r->input_rotate) = input_rotate;
38591- ACCESS_ONCE(r->add_ptr) = i;
38592+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
38593+ ACCESS_ONCE_RW(r->add_ptr) = i;
38594 smp_wmb();
38595
38596 if (out)
38597@@ -632,7 +643,7 @@ retry:
38598 /* The +2 corresponds to the /4 in the denominator */
38599
38600 do {
38601- unsigned int anfrac = min(pnfrac, pool_size/2);
38602+ u64 anfrac = min(pnfrac, pool_size/2);
38603 unsigned int add =
38604 ((pool_size - entropy_count)*anfrac*3) >> s;
38605
38606@@ -1151,7 +1162,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38607
38608 extract_buf(r, tmp);
38609 i = min_t(int, nbytes, EXTRACT_SIZE);
38610- if (copy_to_user(buf, tmp, i)) {
38611+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38612 ret = -EFAULT;
38613 break;
38614 }
38615@@ -1507,7 +1518,7 @@ EXPORT_SYMBOL(generate_random_uuid);
38616 #include <linux/sysctl.h>
38617
38618 static int min_read_thresh = 8, min_write_thresh;
38619-static int max_read_thresh = INPUT_POOL_WORDS * 32;
38620+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
38621 static int max_write_thresh = INPUT_POOL_WORDS * 32;
38622 static char sysctl_bootid[16];
38623
38624@@ -1523,7 +1534,7 @@ static char sysctl_bootid[16];
38625 static int proc_do_uuid(struct ctl_table *table, int write,
38626 void __user *buffer, size_t *lenp, loff_t *ppos)
38627 {
38628- struct ctl_table fake_table;
38629+ ctl_table_no_const fake_table;
38630 unsigned char buf[64], tmp_uuid[16], *uuid;
38631
38632 uuid = table->data;
38633@@ -1553,7 +1564,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38634 static int proc_do_entropy(ctl_table *table, int write,
38635 void __user *buffer, size_t *lenp, loff_t *ppos)
38636 {
38637- ctl_table fake_table;
38638+ ctl_table_no_const fake_table;
38639 int entropy_count;
38640
38641 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38642diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38643index 7cc1fe22..b602d6b 100644
38644--- a/drivers/char/sonypi.c
38645+++ b/drivers/char/sonypi.c
38646@@ -54,6 +54,7 @@
38647
38648 #include <asm/uaccess.h>
38649 #include <asm/io.h>
38650+#include <asm/local.h>
38651
38652 #include <linux/sonypi.h>
38653
38654@@ -490,7 +491,7 @@ static struct sonypi_device {
38655 spinlock_t fifo_lock;
38656 wait_queue_head_t fifo_proc_list;
38657 struct fasync_struct *fifo_async;
38658- int open_count;
38659+ local_t open_count;
38660 int model;
38661 struct input_dev *input_jog_dev;
38662 struct input_dev *input_key_dev;
38663@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38664 static int sonypi_misc_release(struct inode *inode, struct file *file)
38665 {
38666 mutex_lock(&sonypi_device.lock);
38667- sonypi_device.open_count--;
38668+ local_dec(&sonypi_device.open_count);
38669 mutex_unlock(&sonypi_device.lock);
38670 return 0;
38671 }
38672@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38673 {
38674 mutex_lock(&sonypi_device.lock);
38675 /* Flush input queue on first open */
38676- if (!sonypi_device.open_count)
38677+ if (!local_read(&sonypi_device.open_count))
38678 kfifo_reset(&sonypi_device.fifo);
38679- sonypi_device.open_count++;
38680+ local_inc(&sonypi_device.open_count);
38681 mutex_unlock(&sonypi_device.lock);
38682
38683 return 0;
38684diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38685index 64420b3..5c40b56 100644
38686--- a/drivers/char/tpm/tpm_acpi.c
38687+++ b/drivers/char/tpm/tpm_acpi.c
38688@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38689 virt = acpi_os_map_memory(start, len);
38690 if (!virt) {
38691 kfree(log->bios_event_log);
38692+ log->bios_event_log = NULL;
38693 printk("%s: ERROR - Unable to map memory\n", __func__);
38694 return -EIO;
38695 }
38696
38697- memcpy_fromio(log->bios_event_log, virt, len);
38698+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38699
38700 acpi_os_unmap_memory(virt, len);
38701 return 0;
38702diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38703index 59f7cb2..bac8b6d 100644
38704--- a/drivers/char/tpm/tpm_eventlog.c
38705+++ b/drivers/char/tpm/tpm_eventlog.c
38706@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38707 event = addr;
38708
38709 if ((event->event_type == 0 && event->event_size == 0) ||
38710- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38711+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38712 return NULL;
38713
38714 return addr;
38715@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38716 return NULL;
38717
38718 if ((event->event_type == 0 && event->event_size == 0) ||
38719- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38720+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38721 return NULL;
38722
38723 (*pos)++;
38724@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38725 int i;
38726
38727 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38728- seq_putc(m, data[i]);
38729+ if (!seq_putc(m, data[i]))
38730+ return -EFAULT;
38731
38732 return 0;
38733 }
38734diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38735index feea87c..18aefff 100644
38736--- a/drivers/char/virtio_console.c
38737+++ b/drivers/char/virtio_console.c
38738@@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38739 if (to_user) {
38740 ssize_t ret;
38741
38742- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38743+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38744 if (ret)
38745 return -EFAULT;
38746 } else {
38747@@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38748 if (!port_has_data(port) && !port->host_connected)
38749 return 0;
38750
38751- return fill_readbuf(port, ubuf, count, true);
38752+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38753 }
38754
38755 static int wait_port_writable(struct port *port, bool nonblock)
38756diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38757index a33f46f..a720eed 100644
38758--- a/drivers/clk/clk-composite.c
38759+++ b/drivers/clk/clk-composite.c
38760@@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38761 struct clk *clk;
38762 struct clk_init_data init;
38763 struct clk_composite *composite;
38764- struct clk_ops *clk_composite_ops;
38765+ clk_ops_no_const *clk_composite_ops;
38766
38767 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38768 if (!composite) {
38769diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
38770index 81dd31a..ef5c542 100644
38771--- a/drivers/clk/socfpga/clk.c
38772+++ b/drivers/clk/socfpga/clk.c
38773@@ -22,6 +22,7 @@
38774 #include <linux/clk-provider.h>
38775 #include <linux/io.h>
38776 #include <linux/of.h>
38777+#include <asm/pgtable.h>
38778
38779 /* Clock Manager offsets */
38780 #define CLKMGR_CTRL 0x0
38781@@ -152,8 +153,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
38782 streq(clk_name, "periph_pll") ||
38783 streq(clk_name, "sdram_pll")) {
38784 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
38785- clk_pll_ops.enable = clk_gate_ops.enable;
38786- clk_pll_ops.disable = clk_gate_ops.disable;
38787+ pax_open_kernel();
38788+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
38789+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
38790+ pax_close_kernel();
38791 }
38792
38793 clk = clk_register(NULL, &socfpga_clk->hw.hw);
38794@@ -244,7 +247,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
38795 return parent_rate / div;
38796 }
38797
38798-static struct clk_ops gateclk_ops = {
38799+static clk_ops_no_const gateclk_ops __read_only = {
38800 .recalc_rate = socfpga_clk_recalc_rate,
38801 .get_parent = socfpga_clk_get_parent,
38802 .set_parent = socfpga_clk_set_parent,
38803diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
38804index caf41eb..223d27a 100644
38805--- a/drivers/cpufreq/acpi-cpufreq.c
38806+++ b/drivers/cpufreq/acpi-cpufreq.c
38807@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
38808 return sprintf(buf, "%u\n", boost_enabled);
38809 }
38810
38811-static struct global_attr global_boost = __ATTR(boost, 0644,
38812+static global_attr_no_const global_boost = __ATTR(boost, 0644,
38813 show_global_boost,
38814 store_global_boost);
38815
38816@@ -693,8 +693,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38817 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
38818 per_cpu(acfreq_data, cpu) = data;
38819
38820- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
38821- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38822+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
38823+ pax_open_kernel();
38824+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38825+ pax_close_kernel();
38826+ }
38827
38828 result = acpi_processor_register_performance(data->acpi_data, cpu);
38829 if (result)
38830@@ -827,7 +830,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38831 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
38832 break;
38833 case ACPI_ADR_SPACE_FIXED_HARDWARE:
38834- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38835+ pax_open_kernel();
38836+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38837+ pax_close_kernel();
38838 break;
38839 default:
38840 break;
38841diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
38842index 99a443e..8cb6f02 100644
38843--- a/drivers/cpufreq/cpufreq.c
38844+++ b/drivers/cpufreq/cpufreq.c
38845@@ -1878,7 +1878,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
38846 #endif
38847
38848 mutex_lock(&cpufreq_governor_mutex);
38849- list_del(&governor->governor_list);
38850+ pax_list_del(&governor->governor_list);
38851 mutex_unlock(&cpufreq_governor_mutex);
38852 return;
38853 }
38854@@ -2108,7 +2108,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
38855 return NOTIFY_OK;
38856 }
38857
38858-static struct notifier_block __refdata cpufreq_cpu_notifier = {
38859+static struct notifier_block cpufreq_cpu_notifier = {
38860 .notifier_call = cpufreq_cpu_callback,
38861 };
38862
38863@@ -2141,8 +2141,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
38864
38865 pr_debug("trying to register driver %s\n", driver_data->name);
38866
38867- if (driver_data->setpolicy)
38868- driver_data->flags |= CPUFREQ_CONST_LOOPS;
38869+ if (driver_data->setpolicy) {
38870+ pax_open_kernel();
38871+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
38872+ pax_close_kernel();
38873+ }
38874
38875 write_lock_irqsave(&cpufreq_driver_lock, flags);
38876 if (cpufreq_driver) {
38877diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
38878index e6be635..f8a90dc 100644
38879--- a/drivers/cpufreq/cpufreq_governor.c
38880+++ b/drivers/cpufreq/cpufreq_governor.c
38881@@ -187,7 +187,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38882 struct dbs_data *dbs_data;
38883 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
38884 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
38885- struct od_ops *od_ops = NULL;
38886+ const struct od_ops *od_ops = NULL;
38887 struct od_dbs_tuners *od_tuners = NULL;
38888 struct cs_dbs_tuners *cs_tuners = NULL;
38889 struct cpu_dbs_common_info *cpu_cdbs;
38890@@ -253,7 +253,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38891
38892 if ((cdata->governor == GOV_CONSERVATIVE) &&
38893 (!policy->governor->initialized)) {
38894- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38895+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38896
38897 cpufreq_register_notifier(cs_ops->notifier_block,
38898 CPUFREQ_TRANSITION_NOTIFIER);
38899@@ -273,7 +273,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38900
38901 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
38902 (policy->governor->initialized == 1)) {
38903- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38904+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38905
38906 cpufreq_unregister_notifier(cs_ops->notifier_block,
38907 CPUFREQ_TRANSITION_NOTIFIER);
38908diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
38909index b5f2b86..daa801b 100644
38910--- a/drivers/cpufreq/cpufreq_governor.h
38911+++ b/drivers/cpufreq/cpufreq_governor.h
38912@@ -205,7 +205,7 @@ struct common_dbs_data {
38913 void (*exit)(struct dbs_data *dbs_data);
38914
38915 /* Governor specific ops, see below */
38916- void *gov_ops;
38917+ const void *gov_ops;
38918 };
38919
38920 /* Governor Per policy data */
38921@@ -225,7 +225,7 @@ struct od_ops {
38922 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
38923 unsigned int freq_next, unsigned int relation);
38924 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
38925-};
38926+} __no_const;
38927
38928 struct cs_ops {
38929 struct notifier_block *notifier_block;
38930diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
38931index 18d4091..434be15 100644
38932--- a/drivers/cpufreq/cpufreq_ondemand.c
38933+++ b/drivers/cpufreq/cpufreq_ondemand.c
38934@@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
38935
38936 define_get_cpu_dbs_routines(od_cpu_dbs_info);
38937
38938-static struct od_ops od_ops = {
38939+static struct od_ops od_ops __read_only = {
38940 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
38941 .powersave_bias_target = generic_powersave_bias_target,
38942 .freq_increase = dbs_freq_increase,
38943@@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
38944 (struct cpufreq_policy *, unsigned int, unsigned int),
38945 unsigned int powersave_bias)
38946 {
38947- od_ops.powersave_bias_target = f;
38948+ pax_open_kernel();
38949+ *(void **)&od_ops.powersave_bias_target = f;
38950+ pax_close_kernel();
38951 od_set_powersave_bias(powersave_bias);
38952 }
38953 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
38954
38955 void od_unregister_powersave_bias_handler(void)
38956 {
38957- od_ops.powersave_bias_target = generic_powersave_bias_target;
38958+ pax_open_kernel();
38959+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
38960+ pax_close_kernel();
38961 od_set_powersave_bias(0);
38962 }
38963 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
38964diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
38965index 4cf0d28..5830372 100644
38966--- a/drivers/cpufreq/cpufreq_stats.c
38967+++ b/drivers/cpufreq/cpufreq_stats.c
38968@@ -352,7 +352,7 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
38969 }
38970
38971 /* priority=1 so this will get called before cpufreq_remove_dev */
38972-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
38973+static struct notifier_block cpufreq_stat_cpu_notifier = {
38974 .notifier_call = cpufreq_stat_cpu_callback,
38975 .priority = 1,
38976 };
38977diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
38978index b687df8..ae733fc 100644
38979--- a/drivers/cpufreq/intel_pstate.c
38980+++ b/drivers/cpufreq/intel_pstate.c
38981@@ -123,10 +123,10 @@ struct pstate_funcs {
38982 struct cpu_defaults {
38983 struct pstate_adjust_policy pid_policy;
38984 struct pstate_funcs funcs;
38985-};
38986+} __do_const;
38987
38988 static struct pstate_adjust_policy pid_params;
38989-static struct pstate_funcs pstate_funcs;
38990+static struct pstate_funcs *pstate_funcs;
38991
38992 struct perf_limits {
38993 int no_turbo;
38994@@ -517,7 +517,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
38995
38996 cpu->pstate.current_pstate = pstate;
38997
38998- pstate_funcs.set(cpu, pstate);
38999+ pstate_funcs->set(cpu, pstate);
39000 }
39001
39002 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
39003@@ -539,12 +539,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39004 {
39005 sprintf(cpu->name, "Intel 2nd generation core");
39006
39007- cpu->pstate.min_pstate = pstate_funcs.get_min();
39008- cpu->pstate.max_pstate = pstate_funcs.get_max();
39009- cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39010+ cpu->pstate.min_pstate = pstate_funcs->get_min();
39011+ cpu->pstate.max_pstate = pstate_funcs->get_max();
39012+ cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39013
39014- if (pstate_funcs.get_vid)
39015- pstate_funcs.get_vid(cpu);
39016+ if (pstate_funcs->get_vid)
39017+ pstate_funcs->get_vid(cpu);
39018
39019 /*
39020 * goto max pstate so we don't slow up boot if we are built-in if we are
39021@@ -808,9 +808,9 @@ static int intel_pstate_msrs_not_valid(void)
39022 rdmsrl(MSR_IA32_APERF, aperf);
39023 rdmsrl(MSR_IA32_MPERF, mperf);
39024
39025- if (!pstate_funcs.get_max() ||
39026- !pstate_funcs.get_min() ||
39027- !pstate_funcs.get_turbo())
39028+ if (!pstate_funcs->get_max() ||
39029+ !pstate_funcs->get_min() ||
39030+ !pstate_funcs->get_turbo())
39031 return -ENODEV;
39032
39033 rdmsrl(MSR_IA32_APERF, tmp);
39034@@ -824,7 +824,7 @@ static int intel_pstate_msrs_not_valid(void)
39035 return 0;
39036 }
39037
39038-static void copy_pid_params(struct pstate_adjust_policy *policy)
39039+static void copy_pid_params(const struct pstate_adjust_policy *policy)
39040 {
39041 pid_params.sample_rate_ms = policy->sample_rate_ms;
39042 pid_params.p_gain_pct = policy->p_gain_pct;
39043@@ -836,11 +836,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39044
39045 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39046 {
39047- pstate_funcs.get_max = funcs->get_max;
39048- pstate_funcs.get_min = funcs->get_min;
39049- pstate_funcs.get_turbo = funcs->get_turbo;
39050- pstate_funcs.set = funcs->set;
39051- pstate_funcs.get_vid = funcs->get_vid;
39052+ pstate_funcs = funcs;
39053 }
39054
39055 #if IS_ENABLED(CONFIG_ACPI)
39056diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39057index 3d1cba9..0ab21d2 100644
39058--- a/drivers/cpufreq/p4-clockmod.c
39059+++ b/drivers/cpufreq/p4-clockmod.c
39060@@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39061 case 0x0F: /* Core Duo */
39062 case 0x16: /* Celeron Core */
39063 case 0x1C: /* Atom */
39064- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39065+ pax_open_kernel();
39066+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39067+ pax_close_kernel();
39068 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39069 case 0x0D: /* Pentium M (Dothan) */
39070- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39071+ pax_open_kernel();
39072+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39073+ pax_close_kernel();
39074 /* fall through */
39075 case 0x09: /* Pentium M (Banias) */
39076 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39077@@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39078
39079 /* on P-4s, the TSC runs with constant frequency independent whether
39080 * throttling is active or not. */
39081- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39082+ pax_open_kernel();
39083+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39084+ pax_close_kernel();
39085
39086 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39087 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39088diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39089index 724ffbd..ad83692 100644
39090--- a/drivers/cpufreq/sparc-us3-cpufreq.c
39091+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39092@@ -18,14 +18,12 @@
39093 #include <asm/head.h>
39094 #include <asm/timer.h>
39095
39096-static struct cpufreq_driver *cpufreq_us3_driver;
39097-
39098 struct us3_freq_percpu_info {
39099 struct cpufreq_frequency_table table[4];
39100 };
39101
39102 /* Indexed by cpu number. */
39103-static struct us3_freq_percpu_info *us3_freq_table;
39104+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39105
39106 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39107 * in the Safari config register.
39108@@ -156,14 +154,26 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39109
39110 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39111 {
39112- if (cpufreq_us3_driver) {
39113- cpufreq_frequency_table_put_attr(policy->cpu);
39114- us3_freq_target(policy, 0);
39115- }
39116+ cpufreq_frequency_table_put_attr(policy->cpu);
39117+ us3_freq_target(policy, 0);
39118
39119 return 0;
39120 }
39121
39122+static int __init us3_freq_init(void);
39123+static void __exit us3_freq_exit(void);
39124+
39125+static struct cpufreq_driver cpufreq_us3_driver = {
39126+ .init = us3_freq_cpu_init,
39127+ .verify = cpufreq_generic_frequency_table_verify,
39128+ .target_index = us3_freq_target,
39129+ .get = us3_freq_get,
39130+ .exit = us3_freq_cpu_exit,
39131+ .owner = THIS_MODULE,
39132+ .name = "UltraSPARC-III",
39133+
39134+};
39135+
39136 static int __init us3_freq_init(void)
39137 {
39138 unsigned long manuf, impl, ver;
39139@@ -180,55 +190,15 @@ static int __init us3_freq_init(void)
39140 (impl == CHEETAH_IMPL ||
39141 impl == CHEETAH_PLUS_IMPL ||
39142 impl == JAGUAR_IMPL ||
39143- impl == PANTHER_IMPL)) {
39144- struct cpufreq_driver *driver;
39145-
39146- ret = -ENOMEM;
39147- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39148- if (!driver)
39149- goto err_out;
39150-
39151- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39152- GFP_KERNEL);
39153- if (!us3_freq_table)
39154- goto err_out;
39155-
39156- driver->init = us3_freq_cpu_init;
39157- driver->verify = cpufreq_generic_frequency_table_verify;
39158- driver->target_index = us3_freq_target;
39159- driver->get = us3_freq_get;
39160- driver->exit = us3_freq_cpu_exit;
39161- strcpy(driver->name, "UltraSPARC-III");
39162-
39163- cpufreq_us3_driver = driver;
39164- ret = cpufreq_register_driver(driver);
39165- if (ret)
39166- goto err_out;
39167-
39168- return 0;
39169-
39170-err_out:
39171- if (driver) {
39172- kfree(driver);
39173- cpufreq_us3_driver = NULL;
39174- }
39175- kfree(us3_freq_table);
39176- us3_freq_table = NULL;
39177- return ret;
39178- }
39179+ impl == PANTHER_IMPL))
39180+ return cpufreq_register_driver(&cpufreq_us3_driver);
39181
39182 return -ENODEV;
39183 }
39184
39185 static void __exit us3_freq_exit(void)
39186 {
39187- if (cpufreq_us3_driver) {
39188- cpufreq_unregister_driver(cpufreq_us3_driver);
39189- kfree(cpufreq_us3_driver);
39190- cpufreq_us3_driver = NULL;
39191- kfree(us3_freq_table);
39192- us3_freq_table = NULL;
39193- }
39194+ cpufreq_unregister_driver(&cpufreq_us3_driver);
39195 }
39196
39197 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39198diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39199index 4e1daca..e707b61 100644
39200--- a/drivers/cpufreq/speedstep-centrino.c
39201+++ b/drivers/cpufreq/speedstep-centrino.c
39202@@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39203 !cpu_has(cpu, X86_FEATURE_EST))
39204 return -ENODEV;
39205
39206- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39207- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39208+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39209+ pax_open_kernel();
39210+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39211+ pax_close_kernel();
39212+ }
39213
39214 if (policy->cpu != 0)
39215 return -ENODEV;
39216diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39217index 06dbe7c..c2c8671 100644
39218--- a/drivers/cpuidle/driver.c
39219+++ b/drivers/cpuidle/driver.c
39220@@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39221
39222 static void poll_idle_init(struct cpuidle_driver *drv)
39223 {
39224- struct cpuidle_state *state = &drv->states[0];
39225+ cpuidle_state_no_const *state = &drv->states[0];
39226
39227 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39228 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39229diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39230index ca89412..a7b9c49 100644
39231--- a/drivers/cpuidle/governor.c
39232+++ b/drivers/cpuidle/governor.c
39233@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39234 mutex_lock(&cpuidle_lock);
39235 if (__cpuidle_find_governor(gov->name) == NULL) {
39236 ret = 0;
39237- list_add_tail(&gov->governor_list, &cpuidle_governors);
39238+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39239 if (!cpuidle_curr_governor ||
39240 cpuidle_curr_governor->rating < gov->rating)
39241 cpuidle_switch_governor(gov);
39242diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39243index e918b6d..f87ea80 100644
39244--- a/drivers/cpuidle/sysfs.c
39245+++ b/drivers/cpuidle/sysfs.c
39246@@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39247 NULL
39248 };
39249
39250-static struct attribute_group cpuidle_attr_group = {
39251+static attribute_group_no_const cpuidle_attr_group = {
39252 .attrs = cpuidle_default_attrs,
39253 .name = "cpuidle",
39254 };
39255diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39256index 12fea3e..1e28f47 100644
39257--- a/drivers/crypto/hifn_795x.c
39258+++ b/drivers/crypto/hifn_795x.c
39259@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39260 MODULE_PARM_DESC(hifn_pll_ref,
39261 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39262
39263-static atomic_t hifn_dev_number;
39264+static atomic_unchecked_t hifn_dev_number;
39265
39266 #define ACRYPTO_OP_DECRYPT 0
39267 #define ACRYPTO_OP_ENCRYPT 1
39268@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39269 goto err_out_disable_pci_device;
39270
39271 snprintf(name, sizeof(name), "hifn%d",
39272- atomic_inc_return(&hifn_dev_number)-1);
39273+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
39274
39275 err = pci_request_regions(pdev, name);
39276 if (err)
39277diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39278index a0b2f7e..1b6f028 100644
39279--- a/drivers/devfreq/devfreq.c
39280+++ b/drivers/devfreq/devfreq.c
39281@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39282 goto err_out;
39283 }
39284
39285- list_add(&governor->node, &devfreq_governor_list);
39286+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39287
39288 list_for_each_entry(devfreq, &devfreq_list, node) {
39289 int ret = 0;
39290@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39291 }
39292 }
39293
39294- list_del(&governor->node);
39295+ pax_list_del((struct list_head *)&governor->node);
39296 err_out:
39297 mutex_unlock(&devfreq_list_lock);
39298
39299diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39300index 0d765c0..60b7480 100644
39301--- a/drivers/dma/sh/shdmac.c
39302+++ b/drivers/dma/sh/shdmac.c
39303@@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39304 return ret;
39305 }
39306
39307-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39308+static struct notifier_block sh_dmae_nmi_notifier = {
39309 .notifier_call = sh_dmae_nmi_handler,
39310
39311 /* Run before NMI debug handler and KGDB */
39312diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39313index 1026743..80b081c 100644
39314--- a/drivers/edac/edac_device.c
39315+++ b/drivers/edac/edac_device.c
39316@@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39317 */
39318 int edac_device_alloc_index(void)
39319 {
39320- static atomic_t device_indexes = ATOMIC_INIT(0);
39321+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39322
39323- return atomic_inc_return(&device_indexes) - 1;
39324+ return atomic_inc_return_unchecked(&device_indexes) - 1;
39325 }
39326 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39327
39328diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39329index e5bdf21..b8f9055 100644
39330--- a/drivers/edac/edac_mc_sysfs.c
39331+++ b/drivers/edac/edac_mc_sysfs.c
39332@@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39333 struct dev_ch_attribute {
39334 struct device_attribute attr;
39335 int channel;
39336-};
39337+} __do_const;
39338
39339 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39340 struct dev_ch_attribute dev_attr_legacy_##_name = \
39341@@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39342 }
39343
39344 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39345+ pax_open_kernel();
39346 if (mci->get_sdram_scrub_rate) {
39347- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39348- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39349+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39350+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39351 }
39352 if (mci->set_sdram_scrub_rate) {
39353- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39354- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39355+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39356+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39357 }
39358+ pax_close_kernel();
39359 err = device_create_file(&mci->dev,
39360 &dev_attr_sdram_scrub_rate);
39361 if (err) {
39362diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39363index 2cf44b4d..6dd2dc7 100644
39364--- a/drivers/edac/edac_pci.c
39365+++ b/drivers/edac/edac_pci.c
39366@@ -29,7 +29,7 @@
39367
39368 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39369 static LIST_HEAD(edac_pci_list);
39370-static atomic_t pci_indexes = ATOMIC_INIT(0);
39371+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39372
39373 /*
39374 * edac_pci_alloc_ctl_info
39375@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39376 */
39377 int edac_pci_alloc_index(void)
39378 {
39379- return atomic_inc_return(&pci_indexes) - 1;
39380+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
39381 }
39382 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39383
39384diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39385index e8658e4..22746d6 100644
39386--- a/drivers/edac/edac_pci_sysfs.c
39387+++ b/drivers/edac/edac_pci_sysfs.c
39388@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39389 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39390 static int edac_pci_poll_msec = 1000; /* one second workq period */
39391
39392-static atomic_t pci_parity_count = ATOMIC_INIT(0);
39393-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39394+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39395+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39396
39397 static struct kobject *edac_pci_top_main_kobj;
39398 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39399@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39400 void *value;
39401 ssize_t(*show) (void *, char *);
39402 ssize_t(*store) (void *, const char *, size_t);
39403-};
39404+} __do_const;
39405
39406 /* Set of show/store abstract level functions for PCI Parity object */
39407 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39408@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39409 edac_printk(KERN_CRIT, EDAC_PCI,
39410 "Signaled System Error on %s\n",
39411 pci_name(dev));
39412- atomic_inc(&pci_nonparity_count);
39413+ atomic_inc_unchecked(&pci_nonparity_count);
39414 }
39415
39416 if (status & (PCI_STATUS_PARITY)) {
39417@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39418 "Master Data Parity Error on %s\n",
39419 pci_name(dev));
39420
39421- atomic_inc(&pci_parity_count);
39422+ atomic_inc_unchecked(&pci_parity_count);
39423 }
39424
39425 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39426@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39427 "Detected Parity Error on %s\n",
39428 pci_name(dev));
39429
39430- atomic_inc(&pci_parity_count);
39431+ atomic_inc_unchecked(&pci_parity_count);
39432 }
39433 }
39434
39435@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39436 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39437 "Signaled System Error on %s\n",
39438 pci_name(dev));
39439- atomic_inc(&pci_nonparity_count);
39440+ atomic_inc_unchecked(&pci_nonparity_count);
39441 }
39442
39443 if (status & (PCI_STATUS_PARITY)) {
39444@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39445 "Master Data Parity Error on "
39446 "%s\n", pci_name(dev));
39447
39448- atomic_inc(&pci_parity_count);
39449+ atomic_inc_unchecked(&pci_parity_count);
39450 }
39451
39452 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39453@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39454 "Detected Parity Error on %s\n",
39455 pci_name(dev));
39456
39457- atomic_inc(&pci_parity_count);
39458+ atomic_inc_unchecked(&pci_parity_count);
39459 }
39460 }
39461 }
39462@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39463 if (!check_pci_errors)
39464 return;
39465
39466- before_count = atomic_read(&pci_parity_count);
39467+ before_count = atomic_read_unchecked(&pci_parity_count);
39468
39469 /* scan all PCI devices looking for a Parity Error on devices and
39470 * bridges.
39471@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39472 /* Only if operator has selected panic on PCI Error */
39473 if (edac_pci_get_panic_on_pe()) {
39474 /* If the count is different 'after' from 'before' */
39475- if (before_count != atomic_read(&pci_parity_count))
39476+ if (before_count != atomic_read_unchecked(&pci_parity_count))
39477 panic("EDAC: PCI Parity Error");
39478 }
39479 }
39480diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39481index 51b7e3a..aa8a3e8 100644
39482--- a/drivers/edac/mce_amd.h
39483+++ b/drivers/edac/mce_amd.h
39484@@ -77,7 +77,7 @@ struct amd_decoder_ops {
39485 bool (*mc0_mce)(u16, u8);
39486 bool (*mc1_mce)(u16, u8);
39487 bool (*mc2_mce)(u16, u8);
39488-};
39489+} __no_const;
39490
39491 void amd_report_gart_errors(bool);
39492 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39493diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39494index 57ea7f4..af06b76 100644
39495--- a/drivers/firewire/core-card.c
39496+++ b/drivers/firewire/core-card.c
39497@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39498 const struct fw_card_driver *driver,
39499 struct device *device)
39500 {
39501- static atomic_t index = ATOMIC_INIT(-1);
39502+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
39503
39504- card->index = atomic_inc_return(&index);
39505+ card->index = atomic_inc_return_unchecked(&index);
39506 card->driver = driver;
39507 card->device = device;
39508 card->current_tlabel = 0;
39509@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39510
39511 void fw_core_remove_card(struct fw_card *card)
39512 {
39513- struct fw_card_driver dummy_driver = dummy_driver_template;
39514+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
39515
39516 card->driver->update_phy_reg(card, 4,
39517 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39518diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39519index 2c6d5e1..a2cca6b 100644
39520--- a/drivers/firewire/core-device.c
39521+++ b/drivers/firewire/core-device.c
39522@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39523 struct config_rom_attribute {
39524 struct device_attribute attr;
39525 u32 key;
39526-};
39527+} __do_const;
39528
39529 static ssize_t show_immediate(struct device *dev,
39530 struct device_attribute *dattr, char *buf)
39531diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39532index 0e79951..b180217 100644
39533--- a/drivers/firewire/core-transaction.c
39534+++ b/drivers/firewire/core-transaction.c
39535@@ -38,6 +38,7 @@
39536 #include <linux/timer.h>
39537 #include <linux/types.h>
39538 #include <linux/workqueue.h>
39539+#include <linux/sched.h>
39540
39541 #include <asm/byteorder.h>
39542
39543diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39544index 515a42c..5ecf3ba 100644
39545--- a/drivers/firewire/core.h
39546+++ b/drivers/firewire/core.h
39547@@ -111,6 +111,7 @@ struct fw_card_driver {
39548
39549 int (*stop_iso)(struct fw_iso_context *ctx);
39550 };
39551+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
39552
39553 void fw_card_initialize(struct fw_card *card,
39554 const struct fw_card_driver *driver, struct device *device);
39555diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
39556index 94a58a0..f5eba42 100644
39557--- a/drivers/firmware/dmi-id.c
39558+++ b/drivers/firmware/dmi-id.c
39559@@ -16,7 +16,7 @@
39560 struct dmi_device_attribute{
39561 struct device_attribute dev_attr;
39562 int field;
39563-};
39564+} __do_const;
39565 #define to_dmi_dev_attr(_dev_attr) \
39566 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
39567
39568diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
39569index c7e81ff..94a7401 100644
39570--- a/drivers/firmware/dmi_scan.c
39571+++ b/drivers/firmware/dmi_scan.c
39572@@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
39573 if (buf == NULL)
39574 return -1;
39575
39576- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
39577+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
39578
39579 iounmap(buf);
39580 return 0;
39581diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
39582index 1491dd4..aa910db 100644
39583--- a/drivers/firmware/efi/cper.c
39584+++ b/drivers/firmware/efi/cper.c
39585@@ -41,12 +41,12 @@
39586 */
39587 u64 cper_next_record_id(void)
39588 {
39589- static atomic64_t seq;
39590+ static atomic64_unchecked_t seq;
39591
39592- if (!atomic64_read(&seq))
39593- atomic64_set(&seq, ((u64)get_seconds()) << 32);
39594+ if (!atomic64_read_unchecked(&seq))
39595+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
39596
39597- return atomic64_inc_return(&seq);
39598+ return atomic64_inc_return_unchecked(&seq);
39599 }
39600 EXPORT_SYMBOL_GPL(cper_next_record_id);
39601
39602diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
39603index 2e2fbde..7676c8b 100644
39604--- a/drivers/firmware/efi/efi.c
39605+++ b/drivers/firmware/efi/efi.c
39606@@ -81,14 +81,16 @@ static struct attribute_group efi_subsys_attr_group = {
39607 };
39608
39609 static struct efivars generic_efivars;
39610-static struct efivar_operations generic_ops;
39611+static efivar_operations_no_const generic_ops __read_only;
39612
39613 static int generic_ops_register(void)
39614 {
39615- generic_ops.get_variable = efi.get_variable;
39616- generic_ops.set_variable = efi.set_variable;
39617- generic_ops.get_next_variable = efi.get_next_variable;
39618- generic_ops.query_variable_store = efi_query_variable_store;
39619+ pax_open_kernel();
39620+ *(void **)&generic_ops.get_variable = efi.get_variable;
39621+ *(void **)&generic_ops.set_variable = efi.set_variable;
39622+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
39623+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
39624+ pax_close_kernel();
39625
39626 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
39627 }
39628diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
39629index 3dc2482..7bd2f61 100644
39630--- a/drivers/firmware/efi/efivars.c
39631+++ b/drivers/firmware/efi/efivars.c
39632@@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
39633 static int
39634 create_efivars_bin_attributes(void)
39635 {
39636- struct bin_attribute *attr;
39637+ bin_attribute_no_const *attr;
39638 int error;
39639
39640 /* new_var */
39641diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
39642index 2a90ba6..07f3733 100644
39643--- a/drivers/firmware/google/memconsole.c
39644+++ b/drivers/firmware/google/memconsole.c
39645@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
39646 if (!found_memconsole())
39647 return -ENODEV;
39648
39649- memconsole_bin_attr.size = memconsole_length;
39650+ pax_open_kernel();
39651+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39652+ pax_close_kernel();
39653
39654 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39655
39656diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
39657index ec19036..8ffafc2 100644
39658--- a/drivers/gpio/gpio-em.c
39659+++ b/drivers/gpio/gpio-em.c
39660@@ -257,7 +257,7 @@ static int em_gio_probe(struct platform_device *pdev)
39661 struct em_gio_priv *p;
39662 struct resource *io[2], *irq[2];
39663 struct gpio_chip *gpio_chip;
39664- struct irq_chip *irq_chip;
39665+ irq_chip_no_const *irq_chip;
39666 const char *name = dev_name(&pdev->dev);
39667 int ret;
39668
39669diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39670index 814addb..0937d7f 100644
39671--- a/drivers/gpio/gpio-ich.c
39672+++ b/drivers/gpio/gpio-ich.c
39673@@ -71,7 +71,7 @@ struct ichx_desc {
39674 /* Some chipsets have quirks, let these use their own request/get */
39675 int (*request)(struct gpio_chip *chip, unsigned offset);
39676 int (*get)(struct gpio_chip *chip, unsigned offset);
39677-};
39678+} __do_const;
39679
39680 static struct {
39681 spinlock_t lock;
39682diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
39683index 8b7e719..dc089dc 100644
39684--- a/drivers/gpio/gpio-rcar.c
39685+++ b/drivers/gpio/gpio-rcar.c
39686@@ -316,7 +316,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
39687 struct gpio_rcar_priv *p;
39688 struct resource *io, *irq;
39689 struct gpio_chip *gpio_chip;
39690- struct irq_chip *irq_chip;
39691+ irq_chip_no_const *irq_chip;
39692 const char *name = dev_name(&pdev->dev);
39693 int ret;
39694
39695diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
39696index 9902732..64b62dd 100644
39697--- a/drivers/gpio/gpio-vr41xx.c
39698+++ b/drivers/gpio/gpio-vr41xx.c
39699@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
39700 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
39701 maskl, pendl, maskh, pendh);
39702
39703- atomic_inc(&irq_err_count);
39704+ atomic_inc_unchecked(&irq_err_count);
39705
39706 return -EINVAL;
39707 }
39708diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
39709index d6cf77c..2842146 100644
39710--- a/drivers/gpu/drm/drm_crtc.c
39711+++ b/drivers/gpu/drm/drm_crtc.c
39712@@ -3102,7 +3102,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
39713 goto done;
39714 }
39715
39716- if (copy_to_user(&enum_ptr[copied].name,
39717+ if (copy_to_user(enum_ptr[copied].name,
39718 &prop_enum->name, DRM_PROP_NAME_LEN)) {
39719 ret = -EFAULT;
39720 goto done;
39721diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
39722index 01361ab..891e821 100644
39723--- a/drivers/gpu/drm/drm_crtc_helper.c
39724+++ b/drivers/gpu/drm/drm_crtc_helper.c
39725@@ -338,7 +338,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
39726 struct drm_crtc *tmp;
39727 int crtc_mask = 1;
39728
39729- WARN(!crtc, "checking null crtc?\n");
39730+ BUG_ON(!crtc);
39731
39732 dev = crtc->dev;
39733
39734diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
39735index d9137e4..69b73a0 100644
39736--- a/drivers/gpu/drm/drm_drv.c
39737+++ b/drivers/gpu/drm/drm_drv.c
39738@@ -233,7 +233,7 @@ module_exit(drm_core_exit);
39739 /**
39740 * Copy and IOCTL return string to user space
39741 */
39742-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
39743+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
39744 {
39745 int len;
39746
39747@@ -303,7 +303,7 @@ long drm_ioctl(struct file *filp,
39748 struct drm_file *file_priv = filp->private_data;
39749 struct drm_device *dev;
39750 const struct drm_ioctl_desc *ioctl = NULL;
39751- drm_ioctl_t *func;
39752+ drm_ioctl_no_const_t func;
39753 unsigned int nr = DRM_IOCTL_NR(cmd);
39754 int retcode = -EINVAL;
39755 char stack_kdata[128];
39756diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
39757index c5b929c..8a3b8be 100644
39758--- a/drivers/gpu/drm/drm_fops.c
39759+++ b/drivers/gpu/drm/drm_fops.c
39760@@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
39761 if (drm_device_is_unplugged(dev))
39762 return -ENODEV;
39763
39764- if (!dev->open_count++)
39765+ if (local_inc_return(&dev->open_count) == 1)
39766 need_setup = 1;
39767 mutex_lock(&dev->struct_mutex);
39768 old_imapping = inode->i_mapping;
39769@@ -127,7 +127,7 @@ err_undo:
39770 iput(container_of(dev->dev_mapping, struct inode, i_data));
39771 dev->dev_mapping = old_mapping;
39772 mutex_unlock(&dev->struct_mutex);
39773- dev->open_count--;
39774+ local_dec(&dev->open_count);
39775 return retcode;
39776 }
39777 EXPORT_SYMBOL(drm_open);
39778@@ -467,7 +467,7 @@ int drm_release(struct inode *inode, struct file *filp)
39779
39780 mutex_lock(&drm_global_mutex);
39781
39782- DRM_DEBUG("open_count = %d\n", dev->open_count);
39783+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
39784
39785 if (dev->driver->preclose)
39786 dev->driver->preclose(dev, file_priv);
39787@@ -476,10 +476,10 @@ int drm_release(struct inode *inode, struct file *filp)
39788 * Begin inline drm_release
39789 */
39790
39791- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
39792+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
39793 task_pid_nr(current),
39794 (long)old_encode_dev(file_priv->minor->device),
39795- dev->open_count);
39796+ local_read(&dev->open_count));
39797
39798 /* Release any auth tokens that might point to this file_priv,
39799 (do that under the drm_global_mutex) */
39800@@ -577,7 +577,7 @@ int drm_release(struct inode *inode, struct file *filp)
39801 * End inline drm_release
39802 */
39803
39804- if (!--dev->open_count) {
39805+ if (local_dec_and_test(&dev->open_count)) {
39806 if (atomic_read(&dev->ioctl_count)) {
39807 DRM_ERROR("Device busy: %d\n",
39808 atomic_read(&dev->ioctl_count));
39809diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
39810index 3d2e91c..d31c4c9 100644
39811--- a/drivers/gpu/drm/drm_global.c
39812+++ b/drivers/gpu/drm/drm_global.c
39813@@ -36,7 +36,7 @@
39814 struct drm_global_item {
39815 struct mutex mutex;
39816 void *object;
39817- int refcount;
39818+ atomic_t refcount;
39819 };
39820
39821 static struct drm_global_item glob[DRM_GLOBAL_NUM];
39822@@ -49,7 +49,7 @@ void drm_global_init(void)
39823 struct drm_global_item *item = &glob[i];
39824 mutex_init(&item->mutex);
39825 item->object = NULL;
39826- item->refcount = 0;
39827+ atomic_set(&item->refcount, 0);
39828 }
39829 }
39830
39831@@ -59,7 +59,7 @@ void drm_global_release(void)
39832 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
39833 struct drm_global_item *item = &glob[i];
39834 BUG_ON(item->object != NULL);
39835- BUG_ON(item->refcount != 0);
39836+ BUG_ON(atomic_read(&item->refcount) != 0);
39837 }
39838 }
39839
39840@@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39841 struct drm_global_item *item = &glob[ref->global_type];
39842
39843 mutex_lock(&item->mutex);
39844- if (item->refcount == 0) {
39845+ if (atomic_read(&item->refcount) == 0) {
39846 item->object = kzalloc(ref->size, GFP_KERNEL);
39847 if (unlikely(item->object == NULL)) {
39848 ret = -ENOMEM;
39849@@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39850 goto out_err;
39851
39852 }
39853- ++item->refcount;
39854+ atomic_inc(&item->refcount);
39855 ref->object = item->object;
39856 mutex_unlock(&item->mutex);
39857 return 0;
39858@@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
39859 struct drm_global_item *item = &glob[ref->global_type];
39860
39861 mutex_lock(&item->mutex);
39862- BUG_ON(item->refcount == 0);
39863+ BUG_ON(atomic_read(&item->refcount) == 0);
39864 BUG_ON(ref->object != item->object);
39865- if (--item->refcount == 0) {
39866+ if (atomic_dec_and_test(&item->refcount)) {
39867 ref->release(ref);
39868 item->object = NULL;
39869 }
39870diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
39871index 7d5a152..d7186da 100644
39872--- a/drivers/gpu/drm/drm_info.c
39873+++ b/drivers/gpu/drm/drm_info.c
39874@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
39875 struct drm_local_map *map;
39876 struct drm_map_list *r_list;
39877
39878- /* Hardcoded from _DRM_FRAME_BUFFER,
39879- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
39880- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
39881- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
39882+ static const char * const types[] = {
39883+ [_DRM_FRAME_BUFFER] = "FB",
39884+ [_DRM_REGISTERS] = "REG",
39885+ [_DRM_SHM] = "SHM",
39886+ [_DRM_AGP] = "AGP",
39887+ [_DRM_SCATTER_GATHER] = "SG",
39888+ [_DRM_CONSISTENT] = "PCI",
39889+ [_DRM_GEM] = "GEM" };
39890 const char *type;
39891 int i;
39892
39893@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
39894 map = r_list->map;
39895 if (!map)
39896 continue;
39897- if (map->type < 0 || map->type > 5)
39898+ if (map->type >= ARRAY_SIZE(types))
39899 type = "??";
39900 else
39901 type = types[map->type];
39902@@ -257,7 +261,11 @@ int drm_vma_info(struct seq_file *m, void *data)
39903 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
39904 vma->vm_flags & VM_LOCKED ? 'l' : '-',
39905 vma->vm_flags & VM_IO ? 'i' : '-',
39906+#ifdef CONFIG_GRKERNSEC_HIDESYM
39907+ 0);
39908+#else
39909 vma->vm_pgoff);
39910+#endif
39911
39912 #if defined(__i386__)
39913 pgprot = pgprot_val(vma->vm_page_prot);
39914diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
39915index 2f4c4343..dd12cd2 100644
39916--- a/drivers/gpu/drm/drm_ioc32.c
39917+++ b/drivers/gpu/drm/drm_ioc32.c
39918@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
39919 request = compat_alloc_user_space(nbytes);
39920 if (!access_ok(VERIFY_WRITE, request, nbytes))
39921 return -EFAULT;
39922- list = (struct drm_buf_desc *) (request + 1);
39923+ list = (struct drm_buf_desc __user *) (request + 1);
39924
39925 if (__put_user(count, &request->count)
39926 || __put_user(list, &request->list))
39927@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
39928 request = compat_alloc_user_space(nbytes);
39929 if (!access_ok(VERIFY_WRITE, request, nbytes))
39930 return -EFAULT;
39931- list = (struct drm_buf_pub *) (request + 1);
39932+ list = (struct drm_buf_pub __user *) (request + 1);
39933
39934 if (__put_user(count, &request->count)
39935 || __put_user(list, &request->list))
39936@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
39937 return 0;
39938 }
39939
39940-drm_ioctl_compat_t *drm_compat_ioctls[] = {
39941+drm_ioctl_compat_t drm_compat_ioctls[] = {
39942 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
39943 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
39944 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
39945@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
39946 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39947 {
39948 unsigned int nr = DRM_IOCTL_NR(cmd);
39949- drm_ioctl_compat_t *fn;
39950 int ret;
39951
39952 /* Assume that ioctls without an explicit compat routine will just
39953@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39954 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
39955 return drm_ioctl(filp, cmd, arg);
39956
39957- fn = drm_compat_ioctls[nr];
39958-
39959- if (fn != NULL)
39960- ret = (*fn) (filp, cmd, arg);
39961+ if (drm_compat_ioctls[nr] != NULL)
39962+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
39963 else
39964 ret = drm_ioctl(filp, cmd, arg);
39965
39966diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
39967index 66dd3a0..3bed6c4 100644
39968--- a/drivers/gpu/drm/drm_stub.c
39969+++ b/drivers/gpu/drm/drm_stub.c
39970@@ -403,7 +403,7 @@ void drm_unplug_dev(struct drm_device *dev)
39971
39972 drm_device_set_unplugged(dev);
39973
39974- if (dev->open_count == 0) {
39975+ if (local_read(&dev->open_count) == 0) {
39976 drm_put_dev(dev);
39977 }
39978 mutex_unlock(&drm_global_mutex);
39979diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
39980index c22c309..ae758c3 100644
39981--- a/drivers/gpu/drm/drm_sysfs.c
39982+++ b/drivers/gpu/drm/drm_sysfs.c
39983@@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
39984 */
39985 int drm_sysfs_device_add(struct drm_minor *minor)
39986 {
39987- char *minor_str;
39988+ const char *minor_str;
39989 int r;
39990
39991 if (minor->type == DRM_MINOR_CONTROL)
39992diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
39993index d4d16ed..8fb0b51 100644
39994--- a/drivers/gpu/drm/i810/i810_drv.h
39995+++ b/drivers/gpu/drm/i810/i810_drv.h
39996@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
39997 int page_flipping;
39998
39999 wait_queue_head_t irq_queue;
40000- atomic_t irq_received;
40001- atomic_t irq_emitted;
40002+ atomic_unchecked_t irq_received;
40003+ atomic_unchecked_t irq_emitted;
40004
40005 int front_offset;
40006 } drm_i810_private_t;
40007diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
40008index 6ed45a9..eb6dc41 100644
40009--- a/drivers/gpu/drm/i915/i915_debugfs.c
40010+++ b/drivers/gpu/drm/i915/i915_debugfs.c
40011@@ -702,7 +702,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
40012 I915_READ(GTIMR));
40013 }
40014 seq_printf(m, "Interrupts received: %d\n",
40015- atomic_read(&dev_priv->irq_received));
40016+ atomic_read_unchecked(&dev_priv->irq_received));
40017 for_each_ring(ring, dev_priv, i) {
40018 if (INTEL_INFO(dev)->gen >= 6) {
40019 seq_printf(m,
40020diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40021index e02266a..e3411aa 100644
40022--- a/drivers/gpu/drm/i915/i915_dma.c
40023+++ b/drivers/gpu/drm/i915/i915_dma.c
40024@@ -1271,7 +1271,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40025 bool can_switch;
40026
40027 spin_lock(&dev->count_lock);
40028- can_switch = (dev->open_count == 0);
40029+ can_switch = (local_read(&dev->open_count) == 0);
40030 spin_unlock(&dev->count_lock);
40031 return can_switch;
40032 }
40033diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
40034index 221ac62..f56acc8 100644
40035--- a/drivers/gpu/drm/i915/i915_drv.h
40036+++ b/drivers/gpu/drm/i915/i915_drv.h
40037@@ -1326,7 +1326,7 @@ typedef struct drm_i915_private {
40038 drm_dma_handle_t *status_page_dmah;
40039 struct resource mch_res;
40040
40041- atomic_t irq_received;
40042+ atomic_unchecked_t irq_received;
40043
40044 /* protects the irq masks */
40045 spinlock_t irq_lock;
40046diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40047index a3ba9a8..ee52ddd 100644
40048--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40049+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40050@@ -861,9 +861,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40051
40052 static int
40053 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40054- int count)
40055+ unsigned int count)
40056 {
40057- int i;
40058+ unsigned int i;
40059 unsigned relocs_total = 0;
40060 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40061
40062diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40063index 3c59584..500f2e9 100644
40064--- a/drivers/gpu/drm/i915/i915_ioc32.c
40065+++ b/drivers/gpu/drm/i915/i915_ioc32.c
40066@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40067 (unsigned long)request);
40068 }
40069
40070-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40071+static drm_ioctl_compat_t i915_compat_ioctls[] = {
40072 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40073 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40074 [DRM_I915_GETPARAM] = compat_i915_getparam,
40075@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40076 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40077 {
40078 unsigned int nr = DRM_IOCTL_NR(cmd);
40079- drm_ioctl_compat_t *fn = NULL;
40080 int ret;
40081
40082 if (nr < DRM_COMMAND_BASE)
40083 return drm_compat_ioctl(filp, cmd, arg);
40084
40085- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40086- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40087-
40088- if (fn != NULL)
40089+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40090+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40091 ret = (*fn) (filp, cmd, arg);
40092- else
40093+ } else
40094 ret = drm_ioctl(filp, cmd, arg);
40095
40096 return ret;
40097diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
40098index 9702704..3fb9e40 100644
40099--- a/drivers/gpu/drm/i915/i915_irq.c
40100+++ b/drivers/gpu/drm/i915/i915_irq.c
40101@@ -1419,7 +1419,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
40102 int pipe;
40103 u32 pipe_stats[I915_MAX_PIPES];
40104
40105- atomic_inc(&dev_priv->irq_received);
40106+ atomic_inc_unchecked(&dev_priv->irq_received);
40107
40108 while (true) {
40109 iir = I915_READ(VLV_IIR);
40110@@ -1729,7 +1729,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
40111 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
40112 irqreturn_t ret = IRQ_NONE;
40113
40114- atomic_inc(&dev_priv->irq_received);
40115+ atomic_inc_unchecked(&dev_priv->irq_received);
40116
40117 /* We get interrupts on unclaimed registers, so check for this before we
40118 * do any I915_{READ,WRITE}. */
40119@@ -1799,7 +1799,7 @@ static irqreturn_t gen8_irq_handler(int irq, void *arg)
40120 uint32_t tmp = 0;
40121 enum pipe pipe;
40122
40123- atomic_inc(&dev_priv->irq_received);
40124+ atomic_inc_unchecked(&dev_priv->irq_received);
40125
40126 master_ctl = I915_READ(GEN8_MASTER_IRQ);
40127 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
40128@@ -2623,7 +2623,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
40129 {
40130 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40131
40132- atomic_set(&dev_priv->irq_received, 0);
40133+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40134
40135 I915_WRITE(HWSTAM, 0xeffe);
40136
40137@@ -2641,7 +2641,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
40138 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40139 int pipe;
40140
40141- atomic_set(&dev_priv->irq_received, 0);
40142+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40143
40144 /* VLV magic */
40145 I915_WRITE(VLV_IMR, 0);
40146@@ -2672,7 +2672,7 @@ static void gen8_irq_preinstall(struct drm_device *dev)
40147 struct drm_i915_private *dev_priv = dev->dev_private;
40148 int pipe;
40149
40150- atomic_set(&dev_priv->irq_received, 0);
40151+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40152
40153 I915_WRITE(GEN8_MASTER_IRQ, 0);
40154 POSTING_READ(GEN8_MASTER_IRQ);
40155@@ -2996,7 +2996,7 @@ static void gen8_irq_uninstall(struct drm_device *dev)
40156 if (!dev_priv)
40157 return;
40158
40159- atomic_set(&dev_priv->irq_received, 0);
40160+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40161
40162 I915_WRITE(GEN8_MASTER_IRQ, 0);
40163
40164@@ -3090,7 +3090,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
40165 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40166 int pipe;
40167
40168- atomic_set(&dev_priv->irq_received, 0);
40169+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40170
40171 for_each_pipe(pipe)
40172 I915_WRITE(PIPESTAT(pipe), 0);
40173@@ -3176,7 +3176,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
40174 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40175 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40176
40177- atomic_inc(&dev_priv->irq_received);
40178+ atomic_inc_unchecked(&dev_priv->irq_received);
40179
40180 iir = I915_READ16(IIR);
40181 if (iir == 0)
40182@@ -3251,7 +3251,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
40183 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40184 int pipe;
40185
40186- atomic_set(&dev_priv->irq_received, 0);
40187+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40188
40189 if (I915_HAS_HOTPLUG(dev)) {
40190 I915_WRITE(PORT_HOTPLUG_EN, 0);
40191@@ -3358,7 +3358,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
40192 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40193 int pipe, ret = IRQ_NONE;
40194
40195- atomic_inc(&dev_priv->irq_received);
40196+ atomic_inc_unchecked(&dev_priv->irq_received);
40197
40198 iir = I915_READ(IIR);
40199 do {
40200@@ -3485,7 +3485,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
40201 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40202 int pipe;
40203
40204- atomic_set(&dev_priv->irq_received, 0);
40205+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40206
40207 I915_WRITE(PORT_HOTPLUG_EN, 0);
40208 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
40209@@ -3601,7 +3601,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
40210 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40211 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40212
40213- atomic_inc(&dev_priv->irq_received);
40214+ atomic_inc_unchecked(&dev_priv->irq_received);
40215
40216 iir = I915_READ(IIR);
40217
40218diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40219index 3c5ff7a..ae759ca 100644
40220--- a/drivers/gpu/drm/i915/intel_display.c
40221+++ b/drivers/gpu/drm/i915/intel_display.c
40222@@ -10506,13 +10506,13 @@ struct intel_quirk {
40223 int subsystem_vendor;
40224 int subsystem_device;
40225 void (*hook)(struct drm_device *dev);
40226-};
40227+} __do_const;
40228
40229 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40230 struct intel_dmi_quirk {
40231 void (*hook)(struct drm_device *dev);
40232 const struct dmi_system_id (*dmi_id_list)[];
40233-};
40234+} __do_const;
40235
40236 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40237 {
40238@@ -10520,18 +10520,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40239 return 1;
40240 }
40241
40242-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40243+static const struct dmi_system_id intel_dmi_quirks_table[] = {
40244 {
40245- .dmi_id_list = &(const struct dmi_system_id[]) {
40246- {
40247- .callback = intel_dmi_reverse_brightness,
40248- .ident = "NCR Corporation",
40249- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40250- DMI_MATCH(DMI_PRODUCT_NAME, ""),
40251- },
40252- },
40253- { } /* terminating entry */
40254+ .callback = intel_dmi_reverse_brightness,
40255+ .ident = "NCR Corporation",
40256+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40257+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
40258 },
40259+ },
40260+ { } /* terminating entry */
40261+};
40262+
40263+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40264+ {
40265+ .dmi_id_list = &intel_dmi_quirks_table,
40266 .hook = quirk_invert_brightness,
40267 },
40268 };
40269diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40270index ca4bc54..ee598a2 100644
40271--- a/drivers/gpu/drm/mga/mga_drv.h
40272+++ b/drivers/gpu/drm/mga/mga_drv.h
40273@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40274 u32 clear_cmd;
40275 u32 maccess;
40276
40277- atomic_t vbl_received; /**< Number of vblanks received. */
40278+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40279 wait_queue_head_t fence_queue;
40280- atomic_t last_fence_retired;
40281+ atomic_unchecked_t last_fence_retired;
40282 u32 next_fence_to_post;
40283
40284 unsigned int fb_cpp;
40285diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40286index 709e90d..89a1c0d 100644
40287--- a/drivers/gpu/drm/mga/mga_ioc32.c
40288+++ b/drivers/gpu/drm/mga/mga_ioc32.c
40289@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40290 return 0;
40291 }
40292
40293-drm_ioctl_compat_t *mga_compat_ioctls[] = {
40294+drm_ioctl_compat_t mga_compat_ioctls[] = {
40295 [DRM_MGA_INIT] = compat_mga_init,
40296 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40297 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40298@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40299 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40300 {
40301 unsigned int nr = DRM_IOCTL_NR(cmd);
40302- drm_ioctl_compat_t *fn = NULL;
40303 int ret;
40304
40305 if (nr < DRM_COMMAND_BASE)
40306 return drm_compat_ioctl(filp, cmd, arg);
40307
40308- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40309- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40310-
40311- if (fn != NULL)
40312+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40313+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40314 ret = (*fn) (filp, cmd, arg);
40315- else
40316+ } else
40317 ret = drm_ioctl(filp, cmd, arg);
40318
40319 return ret;
40320diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40321index 2b0ceb8..517e99e 100644
40322--- a/drivers/gpu/drm/mga/mga_irq.c
40323+++ b/drivers/gpu/drm/mga/mga_irq.c
40324@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40325 if (crtc != 0)
40326 return 0;
40327
40328- return atomic_read(&dev_priv->vbl_received);
40329+ return atomic_read_unchecked(&dev_priv->vbl_received);
40330 }
40331
40332
40333@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
40334 /* VBLANK interrupt */
40335 if (status & MGA_VLINEPEN) {
40336 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40337- atomic_inc(&dev_priv->vbl_received);
40338+ atomic_inc_unchecked(&dev_priv->vbl_received);
40339 drm_handle_vblank(dev, 0);
40340 handled = 1;
40341 }
40342@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
40343 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40344 MGA_WRITE(MGA_PRIMEND, prim_end);
40345
40346- atomic_inc(&dev_priv->last_fence_retired);
40347+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
40348 DRM_WAKEUP(&dev_priv->fence_queue);
40349 handled = 1;
40350 }
40351@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40352 * using fences.
40353 */
40354 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
40355- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40356+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40357 - *sequence) <= (1 << 23)));
40358
40359 *sequence = cur_fence;
40360diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40361index 4c3feaa..26391ce 100644
40362--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40363+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40364@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40365 struct bit_table {
40366 const char id;
40367 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40368-};
40369+} __no_const;
40370
40371 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40372
40373diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40374index 4b0fb6c..67667a9 100644
40375--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40376+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40377@@ -96,7 +96,6 @@ struct nouveau_drm {
40378 struct drm_global_reference mem_global_ref;
40379 struct ttm_bo_global_ref bo_global_ref;
40380 struct ttm_bo_device bdev;
40381- atomic_t validate_sequence;
40382 int (*move)(struct nouveau_channel *,
40383 struct ttm_buffer_object *,
40384 struct ttm_mem_reg *, struct ttm_mem_reg *);
40385diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40386index c1a7e5a..38b8539 100644
40387--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40388+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40389@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40390 unsigned long arg)
40391 {
40392 unsigned int nr = DRM_IOCTL_NR(cmd);
40393- drm_ioctl_compat_t *fn = NULL;
40394+ drm_ioctl_compat_t fn = NULL;
40395 int ret;
40396
40397 if (nr < DRM_COMMAND_BASE)
40398diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40399index 19e3757..ad16478 100644
40400--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40401+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40402@@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40403 }
40404
40405 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40406- nouveau_vram_manager_init,
40407- nouveau_vram_manager_fini,
40408- nouveau_vram_manager_new,
40409- nouveau_vram_manager_del,
40410- nouveau_vram_manager_debug
40411+ .init = nouveau_vram_manager_init,
40412+ .takedown = nouveau_vram_manager_fini,
40413+ .get_node = nouveau_vram_manager_new,
40414+ .put_node = nouveau_vram_manager_del,
40415+ .debug = nouveau_vram_manager_debug
40416 };
40417
40418 static int
40419@@ -198,11 +198,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40420 }
40421
40422 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40423- nouveau_gart_manager_init,
40424- nouveau_gart_manager_fini,
40425- nouveau_gart_manager_new,
40426- nouveau_gart_manager_del,
40427- nouveau_gart_manager_debug
40428+ .init = nouveau_gart_manager_init,
40429+ .takedown = nouveau_gart_manager_fini,
40430+ .get_node = nouveau_gart_manager_new,
40431+ .put_node = nouveau_gart_manager_del,
40432+ .debug = nouveau_gart_manager_debug
40433 };
40434
40435 #include <core/subdev/vm/nv04.h>
40436@@ -270,11 +270,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40437 }
40438
40439 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40440- nv04_gart_manager_init,
40441- nv04_gart_manager_fini,
40442- nv04_gart_manager_new,
40443- nv04_gart_manager_del,
40444- nv04_gart_manager_debug
40445+ .init = nv04_gart_manager_init,
40446+ .takedown = nv04_gart_manager_fini,
40447+ .get_node = nv04_gart_manager_new,
40448+ .put_node = nv04_gart_manager_del,
40449+ .debug = nv04_gart_manager_debug
40450 };
40451
40452 int
40453diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40454index 81638d7..2e45854 100644
40455--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40456+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40457@@ -65,7 +65,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40458 bool can_switch;
40459
40460 spin_lock(&dev->count_lock);
40461- can_switch = (dev->open_count == 0);
40462+ can_switch = (local_read(&dev->open_count) == 0);
40463 spin_unlock(&dev->count_lock);
40464 return can_switch;
40465 }
40466diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40467index eb89653..613cf71 100644
40468--- a/drivers/gpu/drm/qxl/qxl_cmd.c
40469+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40470@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40471 int ret;
40472
40473 mutex_lock(&qdev->async_io_mutex);
40474- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40475+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40476 if (qdev->last_sent_io_cmd > irq_num) {
40477 if (intr)
40478 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40479- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40480+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40481 else
40482 ret = wait_event_timeout(qdev->io_cmd_event,
40483- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40484+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40485 /* 0 is timeout, just bail the "hw" has gone away */
40486 if (ret <= 0)
40487 goto out;
40488- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40489+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40490 }
40491 outb(val, addr);
40492 qdev->last_sent_io_cmd = irq_num + 1;
40493 if (intr)
40494 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40495- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40496+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40497 else
40498 ret = wait_event_timeout(qdev->io_cmd_event,
40499- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40500+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40501 out:
40502 if (ret > 0)
40503 ret = 0;
40504diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40505index c3c2bbd..bc3c0fb 100644
40506--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40507+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40508@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40509 struct drm_info_node *node = (struct drm_info_node *) m->private;
40510 struct qxl_device *qdev = node->minor->dev->dev_private;
40511
40512- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40513- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40514- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40515- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40516+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40517+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40518+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40519+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40520 seq_printf(m, "%d\n", qdev->irq_received_error);
40521 return 0;
40522 }
40523diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40524index 7bda32f..dd98fc5 100644
40525--- a/drivers/gpu/drm/qxl/qxl_drv.h
40526+++ b/drivers/gpu/drm/qxl/qxl_drv.h
40527@@ -290,10 +290,10 @@ struct qxl_device {
40528 unsigned int last_sent_io_cmd;
40529
40530 /* interrupt handling */
40531- atomic_t irq_received;
40532- atomic_t irq_received_display;
40533- atomic_t irq_received_cursor;
40534- atomic_t irq_received_io_cmd;
40535+ atomic_unchecked_t irq_received;
40536+ atomic_unchecked_t irq_received_display;
40537+ atomic_unchecked_t irq_received_cursor;
40538+ atomic_unchecked_t irq_received_io_cmd;
40539 unsigned irq_received_error;
40540 wait_queue_head_t display_event;
40541 wait_queue_head_t cursor_event;
40542diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40543index 7b95c75..9cffb4f 100644
40544--- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40545+++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40546@@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40547
40548 /* TODO copy slow path code from i915 */
40549 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40550- 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);
40551+ 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);
40552
40553 {
40554 struct qxl_drawable *draw = fb_cmd;
40555@@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40556 struct drm_qxl_reloc reloc;
40557
40558 if (DRM_COPY_FROM_USER(&reloc,
40559- &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40560+ &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40561 sizeof(reloc))) {
40562 ret = -EFAULT;
40563 goto out_free_bos;
40564@@ -297,7 +297,7 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40565 struct drm_qxl_command *commands =
40566 (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40567
40568- if (DRM_COPY_FROM_USER(&user_cmd, &commands[cmd_num],
40569+ if (DRM_COPY_FROM_USER(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40570 sizeof(user_cmd)))
40571 return -EFAULT;
40572
40573diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40574index 21393dc..329f3a9 100644
40575--- a/drivers/gpu/drm/qxl/qxl_irq.c
40576+++ b/drivers/gpu/drm/qxl/qxl_irq.c
40577@@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(DRM_IRQ_ARGS)
40578
40579 pending = xchg(&qdev->ram_header->int_pending, 0);
40580
40581- atomic_inc(&qdev->irq_received);
40582+ atomic_inc_unchecked(&qdev->irq_received);
40583
40584 if (pending & QXL_INTERRUPT_DISPLAY) {
40585- atomic_inc(&qdev->irq_received_display);
40586+ atomic_inc_unchecked(&qdev->irq_received_display);
40587 wake_up_all(&qdev->display_event);
40588 qxl_queue_garbage_collect(qdev, false);
40589 }
40590 if (pending & QXL_INTERRUPT_CURSOR) {
40591- atomic_inc(&qdev->irq_received_cursor);
40592+ atomic_inc_unchecked(&qdev->irq_received_cursor);
40593 wake_up_all(&qdev->cursor_event);
40594 }
40595 if (pending & QXL_INTERRUPT_IO_CMD) {
40596- atomic_inc(&qdev->irq_received_io_cmd);
40597+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40598 wake_up_all(&qdev->io_cmd_event);
40599 }
40600 if (pending & QXL_INTERRUPT_ERROR) {
40601@@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40602 init_waitqueue_head(&qdev->io_cmd_event);
40603 INIT_WORK(&qdev->client_monitors_config_work,
40604 qxl_client_monitors_config_work_func);
40605- atomic_set(&qdev->irq_received, 0);
40606- atomic_set(&qdev->irq_received_display, 0);
40607- atomic_set(&qdev->irq_received_cursor, 0);
40608- atomic_set(&qdev->irq_received_io_cmd, 0);
40609+ atomic_set_unchecked(&qdev->irq_received, 0);
40610+ atomic_set_unchecked(&qdev->irq_received_display, 0);
40611+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40612+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40613 qdev->irq_received_error = 0;
40614 ret = drm_irq_install(qdev->ddev);
40615 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40616diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40617index c7e7e65..7dddd4d 100644
40618--- a/drivers/gpu/drm/qxl/qxl_ttm.c
40619+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40620@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40621 }
40622 }
40623
40624-static struct vm_operations_struct qxl_ttm_vm_ops;
40625+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40626 static const struct vm_operations_struct *ttm_vm_ops;
40627
40628 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40629@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40630 return r;
40631 if (unlikely(ttm_vm_ops == NULL)) {
40632 ttm_vm_ops = vma->vm_ops;
40633+ pax_open_kernel();
40634 qxl_ttm_vm_ops = *ttm_vm_ops;
40635 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40636+ pax_close_kernel();
40637 }
40638 vma->vm_ops = &qxl_ttm_vm_ops;
40639 return 0;
40640@@ -560,25 +562,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40641 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40642 {
40643 #if defined(CONFIG_DEBUG_FS)
40644- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40645- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40646- unsigned i;
40647+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40648+ {
40649+ .name = "qxl_mem_mm",
40650+ .show = &qxl_mm_dump_table,
40651+ },
40652+ {
40653+ .name = "qxl_surf_mm",
40654+ .show = &qxl_mm_dump_table,
40655+ }
40656+ };
40657
40658- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40659- if (i == 0)
40660- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40661- else
40662- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40663- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40664- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40665- qxl_mem_types_list[i].driver_features = 0;
40666- if (i == 0)
40667- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40668- else
40669- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40670+ pax_open_kernel();
40671+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40672+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40673+ pax_close_kernel();
40674
40675- }
40676- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40677+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40678 #else
40679 return 0;
40680 #endif
40681diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40682index c451257..0ad2134 100644
40683--- a/drivers/gpu/drm/r128/r128_cce.c
40684+++ b/drivers/gpu/drm/r128/r128_cce.c
40685@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40686
40687 /* GH: Simple idle check.
40688 */
40689- atomic_set(&dev_priv->idle_count, 0);
40690+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40691
40692 /* We don't support anything other than bus-mastering ring mode,
40693 * but the ring can be in either AGP or PCI space for the ring
40694diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40695index 56eb5e3..c4ec43d 100644
40696--- a/drivers/gpu/drm/r128/r128_drv.h
40697+++ b/drivers/gpu/drm/r128/r128_drv.h
40698@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40699 int is_pci;
40700 unsigned long cce_buffers_offset;
40701
40702- atomic_t idle_count;
40703+ atomic_unchecked_t idle_count;
40704
40705 int page_flipping;
40706 int current_page;
40707 u32 crtc_offset;
40708 u32 crtc_offset_cntl;
40709
40710- atomic_t vbl_received;
40711+ atomic_unchecked_t vbl_received;
40712
40713 u32 color_fmt;
40714 unsigned int front_offset;
40715diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40716index a954c54..9cc595c 100644
40717--- a/drivers/gpu/drm/r128/r128_ioc32.c
40718+++ b/drivers/gpu/drm/r128/r128_ioc32.c
40719@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40720 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40721 }
40722
40723-drm_ioctl_compat_t *r128_compat_ioctls[] = {
40724+drm_ioctl_compat_t r128_compat_ioctls[] = {
40725 [DRM_R128_INIT] = compat_r128_init,
40726 [DRM_R128_DEPTH] = compat_r128_depth,
40727 [DRM_R128_STIPPLE] = compat_r128_stipple,
40728@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40729 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40730 {
40731 unsigned int nr = DRM_IOCTL_NR(cmd);
40732- drm_ioctl_compat_t *fn = NULL;
40733 int ret;
40734
40735 if (nr < DRM_COMMAND_BASE)
40736 return drm_compat_ioctl(filp, cmd, arg);
40737
40738- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40739- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40740-
40741- if (fn != NULL)
40742+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40743+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40744 ret = (*fn) (filp, cmd, arg);
40745- else
40746+ } else
40747 ret = drm_ioctl(filp, cmd, arg);
40748
40749 return ret;
40750diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40751index 2ea4f09..d391371 100644
40752--- a/drivers/gpu/drm/r128/r128_irq.c
40753+++ b/drivers/gpu/drm/r128/r128_irq.c
40754@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40755 if (crtc != 0)
40756 return 0;
40757
40758- return atomic_read(&dev_priv->vbl_received);
40759+ return atomic_read_unchecked(&dev_priv->vbl_received);
40760 }
40761
40762 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
40763@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
40764 /* VBLANK interrupt */
40765 if (status & R128_CRTC_VBLANK_INT) {
40766 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40767- atomic_inc(&dev_priv->vbl_received);
40768+ atomic_inc_unchecked(&dev_priv->vbl_received);
40769 drm_handle_vblank(dev, 0);
40770 return IRQ_HANDLED;
40771 }
40772diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40773index 01dd9ae..6352f04 100644
40774--- a/drivers/gpu/drm/r128/r128_state.c
40775+++ b/drivers/gpu/drm/r128/r128_state.c
40776@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40777
40778 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40779 {
40780- if (atomic_read(&dev_priv->idle_count) == 0)
40781+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40782 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40783 else
40784- atomic_set(&dev_priv->idle_count, 0);
40785+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40786 }
40787
40788 #endif
40789diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40790index af85299..ed9ac8d 100644
40791--- a/drivers/gpu/drm/radeon/mkregtable.c
40792+++ b/drivers/gpu/drm/radeon/mkregtable.c
40793@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40794 regex_t mask_rex;
40795 regmatch_t match[4];
40796 char buf[1024];
40797- size_t end;
40798+ long end;
40799 int len;
40800 int done = 0;
40801 int r;
40802 unsigned o;
40803 struct offset *offset;
40804 char last_reg_s[10];
40805- int last_reg;
40806+ unsigned long last_reg;
40807
40808 if (regcomp
40809 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
40810diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
40811index 39b033b..6efc056 100644
40812--- a/drivers/gpu/drm/radeon/radeon_device.c
40813+++ b/drivers/gpu/drm/radeon/radeon_device.c
40814@@ -1120,7 +1120,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
40815 bool can_switch;
40816
40817 spin_lock(&dev->count_lock);
40818- can_switch = (dev->open_count == 0);
40819+ can_switch = (local_read(&dev->open_count) == 0);
40820 spin_unlock(&dev->count_lock);
40821 return can_switch;
40822 }
40823diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
40824index 00e0d44..08381a4 100644
40825--- a/drivers/gpu/drm/radeon/radeon_drv.h
40826+++ b/drivers/gpu/drm/radeon/radeon_drv.h
40827@@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
40828
40829 /* SW interrupt */
40830 wait_queue_head_t swi_queue;
40831- atomic_t swi_emitted;
40832+ atomic_unchecked_t swi_emitted;
40833 int vblank_crtc;
40834 uint32_t irq_enable_reg;
40835 uint32_t r500_disp_irq_reg;
40836diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
40837index bdb0f93..5ff558f 100644
40838--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
40839+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
40840@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40841 request = compat_alloc_user_space(sizeof(*request));
40842 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
40843 || __put_user(req32.param, &request->param)
40844- || __put_user((void __user *)(unsigned long)req32.value,
40845+ || __put_user((unsigned long)req32.value,
40846 &request->value))
40847 return -EFAULT;
40848
40849@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40850 #define compat_radeon_cp_setparam NULL
40851 #endif /* X86_64 || IA64 */
40852
40853-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40854+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
40855 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
40856 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
40857 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
40858@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40859 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40860 {
40861 unsigned int nr = DRM_IOCTL_NR(cmd);
40862- drm_ioctl_compat_t *fn = NULL;
40863 int ret;
40864
40865 if (nr < DRM_COMMAND_BASE)
40866 return drm_compat_ioctl(filp, cmd, arg);
40867
40868- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
40869- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40870-
40871- if (fn != NULL)
40872+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
40873+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40874 ret = (*fn) (filp, cmd, arg);
40875- else
40876+ } else
40877 ret = drm_ioctl(filp, cmd, arg);
40878
40879 return ret;
40880diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
40881index 8d68e97..9dcfed8 100644
40882--- a/drivers/gpu/drm/radeon/radeon_irq.c
40883+++ b/drivers/gpu/drm/radeon/radeon_irq.c
40884@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
40885 unsigned int ret;
40886 RING_LOCALS;
40887
40888- atomic_inc(&dev_priv->swi_emitted);
40889- ret = atomic_read(&dev_priv->swi_emitted);
40890+ atomic_inc_unchecked(&dev_priv->swi_emitted);
40891+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
40892
40893 BEGIN_RING(4);
40894 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
40895@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
40896 drm_radeon_private_t *dev_priv =
40897 (drm_radeon_private_t *) dev->dev_private;
40898
40899- atomic_set(&dev_priv->swi_emitted, 0);
40900+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
40901 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
40902
40903 dev->max_vblank_count = 0x001fffff;
40904diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
40905index 4d20910..6726b6d 100644
40906--- a/drivers/gpu/drm/radeon/radeon_state.c
40907+++ b/drivers/gpu/drm/radeon/radeon_state.c
40908@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
40909 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
40910 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
40911
40912- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
40913+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
40914 sarea_priv->nbox * sizeof(depth_boxes[0])))
40915 return -EFAULT;
40916
40917@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
40918 {
40919 drm_radeon_private_t *dev_priv = dev->dev_private;
40920 drm_radeon_getparam_t *param = data;
40921- int value;
40922+ int value = 0;
40923
40924 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
40925
40926diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
40927index 84323c9..cf07baf 100644
40928--- a/drivers/gpu/drm/radeon/radeon_ttm.c
40929+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
40930@@ -787,7 +787,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
40931 man->size = size >> PAGE_SHIFT;
40932 }
40933
40934-static struct vm_operations_struct radeon_ttm_vm_ops;
40935+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
40936 static const struct vm_operations_struct *ttm_vm_ops = NULL;
40937
40938 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40939@@ -828,8 +828,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
40940 }
40941 if (unlikely(ttm_vm_ops == NULL)) {
40942 ttm_vm_ops = vma->vm_ops;
40943+ pax_open_kernel();
40944 radeon_ttm_vm_ops = *ttm_vm_ops;
40945 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
40946+ pax_close_kernel();
40947 }
40948 vma->vm_ops = &radeon_ttm_vm_ops;
40949 return 0;
40950@@ -858,38 +860,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
40951 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
40952 {
40953 #if defined(CONFIG_DEBUG_FS)
40954- static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
40955- static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
40956- unsigned i;
40957+ static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
40958+ {
40959+ .name = "radeon_vram_mm",
40960+ .show = &radeon_mm_dump_table,
40961+ },
40962+ {
40963+ .name = "radeon_gtt_mm",
40964+ .show = &radeon_mm_dump_table,
40965+ },
40966+ {
40967+ .name = "ttm_page_pool",
40968+ .show = &ttm_page_alloc_debugfs,
40969+ },
40970+ {
40971+ .name = "ttm_dma_page_pool",
40972+ .show = &ttm_dma_page_alloc_debugfs,
40973+ },
40974+ };
40975+ unsigned i = RADEON_DEBUGFS_MEM_TYPES + 1;
40976
40977- for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
40978- if (i == 0)
40979- sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
40980- else
40981- sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
40982- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40983- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
40984- radeon_mem_types_list[i].driver_features = 0;
40985- if (i == 0)
40986- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
40987- else
40988- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
40989-
40990- }
40991- /* Add ttm page pool to debugfs */
40992- sprintf(radeon_mem_types_names[i], "ttm_page_pool");
40993- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40994- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
40995- radeon_mem_types_list[i].driver_features = 0;
40996- radeon_mem_types_list[i++].data = NULL;
40997+ pax_open_kernel();
40998+ *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
40999+ *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
41000+ pax_close_kernel();
41001 #ifdef CONFIG_SWIOTLB
41002- if (swiotlb_nr_tbl()) {
41003- sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
41004- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
41005- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
41006- radeon_mem_types_list[i].driver_features = 0;
41007- radeon_mem_types_list[i++].data = NULL;
41008- }
41009+ if (swiotlb_nr_tbl())
41010+ i++;
41011 #endif
41012 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
41013
41014diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41015index ae1cb31..5b5b6b7c 100644
41016--- a/drivers/gpu/drm/tegra/dc.c
41017+++ b/drivers/gpu/drm/tegra/dc.c
41018@@ -1064,7 +1064,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41019 }
41020
41021 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41022- dc->debugfs_files[i].data = dc;
41023+ *(void **)&dc->debugfs_files[i].data = dc;
41024
41025 err = drm_debugfs_create_files(dc->debugfs_files,
41026 ARRAY_SIZE(debugfs_files),
41027diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41028index 0cd9bc2..9759be4 100644
41029--- a/drivers/gpu/drm/tegra/hdmi.c
41030+++ b/drivers/gpu/drm/tegra/hdmi.c
41031@@ -57,7 +57,7 @@ struct tegra_hdmi {
41032 bool stereo;
41033 bool dvi;
41034
41035- struct drm_info_list *debugfs_files;
41036+ drm_info_list_no_const *debugfs_files;
41037 struct drm_minor *minor;
41038 struct dentry *debugfs;
41039 };
41040diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41041index c58eba33..83c2728 100644
41042--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41043+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41044@@ -141,10 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41045 }
41046
41047 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41048- ttm_bo_man_init,
41049- ttm_bo_man_takedown,
41050- ttm_bo_man_get_node,
41051- ttm_bo_man_put_node,
41052- ttm_bo_man_debug
41053+ .init = ttm_bo_man_init,
41054+ .takedown = ttm_bo_man_takedown,
41055+ .get_node = ttm_bo_man_get_node,
41056+ .put_node = ttm_bo_man_put_node,
41057+ .debug = ttm_bo_man_debug
41058 };
41059 EXPORT_SYMBOL(ttm_bo_manager_func);
41060diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41061index dbc2def..0a9f710 100644
41062--- a/drivers/gpu/drm/ttm/ttm_memory.c
41063+++ b/drivers/gpu/drm/ttm/ttm_memory.c
41064@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41065 zone->glob = glob;
41066 glob->zone_kernel = zone;
41067 ret = kobject_init_and_add(
41068- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41069+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41070 if (unlikely(ret != 0)) {
41071 kobject_put(&zone->kobj);
41072 return ret;
41073@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41074 zone->glob = glob;
41075 glob->zone_dma32 = zone;
41076 ret = kobject_init_and_add(
41077- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41078+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41079 if (unlikely(ret != 0)) {
41080 kobject_put(&zone->kobj);
41081 return ret;
41082diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41083index 863bef9..cba15cf 100644
41084--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41085+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41086@@ -391,9 +391,9 @@ out:
41087 static unsigned long
41088 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41089 {
41090- static atomic_t start_pool = ATOMIC_INIT(0);
41091+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41092 unsigned i;
41093- unsigned pool_offset = atomic_add_return(1, &start_pool);
41094+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41095 struct ttm_page_pool *pool;
41096 int shrink_pages = sc->nr_to_scan;
41097 unsigned long freed = 0;
41098diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41099index 97e9d61..bf23c461 100644
41100--- a/drivers/gpu/drm/udl/udl_fb.c
41101+++ b/drivers/gpu/drm/udl/udl_fb.c
41102@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41103 fb_deferred_io_cleanup(info);
41104 kfree(info->fbdefio);
41105 info->fbdefio = NULL;
41106- info->fbops->fb_mmap = udl_fb_mmap;
41107 }
41108
41109 pr_warn("released /dev/fb%d user=%d count=%d\n",
41110diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41111index a811ef2..ff99b05 100644
41112--- a/drivers/gpu/drm/via/via_drv.h
41113+++ b/drivers/gpu/drm/via/via_drv.h
41114@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41115 typedef uint32_t maskarray_t[5];
41116
41117 typedef struct drm_via_irq {
41118- atomic_t irq_received;
41119+ atomic_unchecked_t irq_received;
41120 uint32_t pending_mask;
41121 uint32_t enable_mask;
41122 wait_queue_head_t irq_queue;
41123@@ -75,7 +75,7 @@ typedef struct drm_via_private {
41124 struct timeval last_vblank;
41125 int last_vblank_valid;
41126 unsigned usec_per_vblank;
41127- atomic_t vbl_received;
41128+ atomic_unchecked_t vbl_received;
41129 drm_via_state_t hc_state;
41130 char pci_buf[VIA_PCI_BUF_SIZE];
41131 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41132diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41133index ac98964..5dbf512 100644
41134--- a/drivers/gpu/drm/via/via_irq.c
41135+++ b/drivers/gpu/drm/via/via_irq.c
41136@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41137 if (crtc != 0)
41138 return 0;
41139
41140- return atomic_read(&dev_priv->vbl_received);
41141+ return atomic_read_unchecked(&dev_priv->vbl_received);
41142 }
41143
41144 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
41145@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
41146
41147 status = VIA_READ(VIA_REG_INTERRUPT);
41148 if (status & VIA_IRQ_VBLANK_PENDING) {
41149- atomic_inc(&dev_priv->vbl_received);
41150- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41151+ atomic_inc_unchecked(&dev_priv->vbl_received);
41152+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41153 do_gettimeofday(&cur_vblank);
41154 if (dev_priv->last_vblank_valid) {
41155 dev_priv->usec_per_vblank =
41156@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
41157 dev_priv->last_vblank = cur_vblank;
41158 dev_priv->last_vblank_valid = 1;
41159 }
41160- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41161+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41162 DRM_DEBUG("US per vblank is: %u\n",
41163 dev_priv->usec_per_vblank);
41164 }
41165@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
41166
41167 for (i = 0; i < dev_priv->num_irqs; ++i) {
41168 if (status & cur_irq->pending_mask) {
41169- atomic_inc(&cur_irq->irq_received);
41170+ atomic_inc_unchecked(&cur_irq->irq_received);
41171 DRM_WAKEUP(&cur_irq->irq_queue);
41172 handled = 1;
41173 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41174@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41175 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
41176 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41177 masks[irq][4]));
41178- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41179+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41180 } else {
41181 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
41182 (((cur_irq_sequence =
41183- atomic_read(&cur_irq->irq_received)) -
41184+ atomic_read_unchecked(&cur_irq->irq_received)) -
41185 *sequence) <= (1 << 23)));
41186 }
41187 *sequence = cur_irq_sequence;
41188@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41189 }
41190
41191 for (i = 0; i < dev_priv->num_irqs; ++i) {
41192- atomic_set(&cur_irq->irq_received, 0);
41193+ atomic_set_unchecked(&cur_irq->irq_received, 0);
41194 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41195 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41196 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
41197@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41198 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41199 case VIA_IRQ_RELATIVE:
41200 irqwait->request.sequence +=
41201- atomic_read(&cur_irq->irq_received);
41202+ atomic_read_unchecked(&cur_irq->irq_received);
41203 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41204 case VIA_IRQ_ABSOLUTE:
41205 break;
41206diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41207index c0b73b9..f6f7f34 100644
41208--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41209+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41210@@ -341,7 +341,7 @@ struct vmw_private {
41211 * Fencing and IRQs.
41212 */
41213
41214- atomic_t marker_seq;
41215+ atomic_unchecked_t marker_seq;
41216 wait_queue_head_t fence_queue;
41217 wait_queue_head_t fifo_queue;
41218 int fence_queue_waiters; /* Protected by hw_mutex */
41219diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41220index 3eb1486..0a47ee9 100644
41221--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41222+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41223@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41224 (unsigned int) min,
41225 (unsigned int) fifo->capabilities);
41226
41227- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41228+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41229 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41230 vmw_marker_queue_init(&fifo->marker_queue);
41231 return vmw_fifo_send_fence(dev_priv, &dummy);
41232@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41233 if (reserveable)
41234 iowrite32(bytes, fifo_mem +
41235 SVGA_FIFO_RESERVED);
41236- return fifo_mem + (next_cmd >> 2);
41237+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41238 } else {
41239 need_bounce = true;
41240 }
41241@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41242
41243 fm = vmw_fifo_reserve(dev_priv, bytes);
41244 if (unlikely(fm == NULL)) {
41245- *seqno = atomic_read(&dev_priv->marker_seq);
41246+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41247 ret = -ENOMEM;
41248 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41249 false, 3*HZ);
41250@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41251 }
41252
41253 do {
41254- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41255+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41256 } while (*seqno == 0);
41257
41258 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41259diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41260index c5c054a..46f0548 100644
41261--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41262+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41263@@ -153,9 +153,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41264 }
41265
41266 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41267- vmw_gmrid_man_init,
41268- vmw_gmrid_man_takedown,
41269- vmw_gmrid_man_get_node,
41270- vmw_gmrid_man_put_node,
41271- vmw_gmrid_man_debug
41272+ .init = vmw_gmrid_man_init,
41273+ .takedown = vmw_gmrid_man_takedown,
41274+ .get_node = vmw_gmrid_man_get_node,
41275+ .put_node = vmw_gmrid_man_put_node,
41276+ .debug = vmw_gmrid_man_debug
41277 };
41278diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41279index 45d5b5a..f3f5e4e 100644
41280--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41281+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41282@@ -141,7 +141,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41283 int ret;
41284
41285 num_clips = arg->num_clips;
41286- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41287+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41288
41289 if (unlikely(num_clips == 0))
41290 return 0;
41291@@ -225,7 +225,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41292 int ret;
41293
41294 num_clips = arg->num_clips;
41295- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41296+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41297
41298 if (unlikely(num_clips == 0))
41299 return 0;
41300diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41301index 4640adb..e1384ed 100644
41302--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41303+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41304@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41305 * emitted. Then the fence is stale and signaled.
41306 */
41307
41308- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41309+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41310 > VMW_FENCE_WRAP);
41311
41312 return ret;
41313@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41314
41315 if (fifo_idle)
41316 down_read(&fifo_state->rwsem);
41317- signal_seq = atomic_read(&dev_priv->marker_seq);
41318+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41319 ret = 0;
41320
41321 for (;;) {
41322diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41323index 8a8725c2..afed796 100644
41324--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41325+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41326@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41327 while (!vmw_lag_lt(queue, us)) {
41328 spin_lock(&queue->lock);
41329 if (list_empty(&queue->head))
41330- seqno = atomic_read(&dev_priv->marker_seq);
41331+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41332 else {
41333 marker = list_first_entry(&queue->head,
41334 struct vmw_marker, head);
41335diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41336index ec0ae2d..dc0780b 100644
41337--- a/drivers/gpu/vga/vga_switcheroo.c
41338+++ b/drivers/gpu/vga/vga_switcheroo.c
41339@@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41340
41341 /* this version is for the case where the power switch is separate
41342 to the device being powered down. */
41343-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41344+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41345 {
41346 /* copy over all the bus versions */
41347 if (dev->bus && dev->bus->pm) {
41348@@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41349 return ret;
41350 }
41351
41352-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41353+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41354 {
41355 /* copy over all the bus versions */
41356 if (dev->bus && dev->bus->pm) {
41357diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41358index 253fe23..0dfec5f 100644
41359--- a/drivers/hid/hid-core.c
41360+++ b/drivers/hid/hid-core.c
41361@@ -2416,7 +2416,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41362
41363 int hid_add_device(struct hid_device *hdev)
41364 {
41365- static atomic_t id = ATOMIC_INIT(0);
41366+ static atomic_unchecked_t id = ATOMIC_INIT(0);
41367 int ret;
41368
41369 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41370@@ -2450,7 +2450,7 @@ int hid_add_device(struct hid_device *hdev)
41371 /* XXX hack, any other cleaner solution after the driver core
41372 * is converted to allow more than 20 bytes as the device name? */
41373 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41374- hdev->vendor, hdev->product, atomic_inc_return(&id));
41375+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41376
41377 hid_debug_register(hdev, dev_name(&hdev->dev));
41378 ret = device_add(&hdev->dev);
41379diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41380index c13fb5b..55a3802 100644
41381--- a/drivers/hid/hid-wiimote-debug.c
41382+++ b/drivers/hid/hid-wiimote-debug.c
41383@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41384 else if (size == 0)
41385 return -EIO;
41386
41387- if (copy_to_user(u, buf, size))
41388+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
41389 return -EFAULT;
41390
41391 *off += size;
41392diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41393index cedc6da..2c3da2a 100644
41394--- a/drivers/hid/uhid.c
41395+++ b/drivers/hid/uhid.c
41396@@ -47,7 +47,7 @@ struct uhid_device {
41397 struct mutex report_lock;
41398 wait_queue_head_t report_wait;
41399 atomic_t report_done;
41400- atomic_t report_id;
41401+ atomic_unchecked_t report_id;
41402 struct uhid_event report_buf;
41403 };
41404
41405@@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41406
41407 spin_lock_irqsave(&uhid->qlock, flags);
41408 ev->type = UHID_FEATURE;
41409- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41410+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41411 ev->u.feature.rnum = rnum;
41412 ev->u.feature.rtype = report_type;
41413
41414@@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41415 spin_lock_irqsave(&uhid->qlock, flags);
41416
41417 /* id for old report; drop it silently */
41418- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41419+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41420 goto unlock;
41421 if (atomic_read(&uhid->report_done))
41422 goto unlock;
41423diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41424index cea623c..73011b0 100644
41425--- a/drivers/hv/channel.c
41426+++ b/drivers/hv/channel.c
41427@@ -362,8 +362,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41428 int ret = 0;
41429 int t;
41430
41431- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41432- atomic_inc(&vmbus_connection.next_gpadl_handle);
41433+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41434+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41435
41436 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41437 if (ret)
41438diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41439index f0c5e07..49a4d4a 100644
41440--- a/drivers/hv/hv.c
41441+++ b/drivers/hv/hv.c
41442@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41443 u64 output_address = (output) ? virt_to_phys(output) : 0;
41444 u32 output_address_hi = output_address >> 32;
41445 u32 output_address_lo = output_address & 0xFFFFFFFF;
41446- void *hypercall_page = hv_context.hypercall_page;
41447+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41448
41449 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41450 "=a"(hv_status_lo) : "d" (control_hi),
41451@@ -154,7 +154,7 @@ int hv_init(void)
41452 /* See if the hypercall page is already set */
41453 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
41454
41455- virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
41456+ virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
41457
41458 if (!virtaddr)
41459 goto cleanup;
41460diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41461index 7e17a54..a50a33d 100644
41462--- a/drivers/hv/hv_balloon.c
41463+++ b/drivers/hv/hv_balloon.c
41464@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41465
41466 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41467 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41468-static atomic_t trans_id = ATOMIC_INIT(0);
41469+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41470
41471 static int dm_ring_size = (5 * PAGE_SIZE);
41472
41473@@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
41474 pr_info("Memory hot add failed\n");
41475
41476 dm->state = DM_INITIALIZED;
41477- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41478+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41479 vmbus_sendpacket(dm->dev->channel, &resp,
41480 sizeof(struct dm_hot_add_response),
41481 (unsigned long)NULL,
41482@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
41483 memset(&status, 0, sizeof(struct dm_status));
41484 status.hdr.type = DM_STATUS_REPORT;
41485 status.hdr.size = sizeof(struct dm_status);
41486- status.hdr.trans_id = atomic_inc_return(&trans_id);
41487+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41488
41489 /*
41490 * The host expects the guest to report free memory.
41491@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
41492 * send the status. This can happen if we were interrupted
41493 * after we picked our transaction ID.
41494 */
41495- if (status.hdr.trans_id != atomic_read(&trans_id))
41496+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
41497 return;
41498
41499 vmbus_sendpacket(dm->dev->channel, &status,
41500@@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
41501 */
41502
41503 do {
41504- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
41505+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41506 ret = vmbus_sendpacket(dm_device.dev->channel,
41507 bl_resp,
41508 bl_resp->hdr.size,
41509@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
41510
41511 memset(&resp, 0, sizeof(struct dm_unballoon_response));
41512 resp.hdr.type = DM_UNBALLOON_RESPONSE;
41513- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41514+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41515 resp.hdr.size = sizeof(struct dm_unballoon_response);
41516
41517 vmbus_sendpacket(dm_device.dev->channel, &resp,
41518@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
41519 memset(&version_req, 0, sizeof(struct dm_version_request));
41520 version_req.hdr.type = DM_VERSION_REQUEST;
41521 version_req.hdr.size = sizeof(struct dm_version_request);
41522- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41523+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41524 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
41525 version_req.is_last_attempt = 1;
41526
41527@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
41528 memset(&version_req, 0, sizeof(struct dm_version_request));
41529 version_req.hdr.type = DM_VERSION_REQUEST;
41530 version_req.hdr.size = sizeof(struct dm_version_request);
41531- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41532+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41533 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
41534 version_req.is_last_attempt = 0;
41535
41536@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
41537 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
41538 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
41539 cap_msg.hdr.size = sizeof(struct dm_capabilities);
41540- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
41541+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41542
41543 cap_msg.caps.cap_bits.balloon = 1;
41544 cap_msg.caps.cap_bits.hot_add = 1;
41545diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
41546index e055176..c22ff1f 100644
41547--- a/drivers/hv/hyperv_vmbus.h
41548+++ b/drivers/hv/hyperv_vmbus.h
41549@@ -602,7 +602,7 @@ enum vmbus_connect_state {
41550 struct vmbus_connection {
41551 enum vmbus_connect_state conn_state;
41552
41553- atomic_t next_gpadl_handle;
41554+ atomic_unchecked_t next_gpadl_handle;
41555
41556 /*
41557 * Represents channel interrupts. Each bit position represents a
41558diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
41559index 48aad4f..c768fb2 100644
41560--- a/drivers/hv/vmbus_drv.c
41561+++ b/drivers/hv/vmbus_drv.c
41562@@ -846,10 +846,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
41563 {
41564 int ret = 0;
41565
41566- static atomic_t device_num = ATOMIC_INIT(0);
41567+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41568
41569 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
41570- atomic_inc_return(&device_num));
41571+ atomic_inc_return_unchecked(&device_num));
41572
41573 child_device_obj->device.bus = &hv_bus;
41574 child_device_obj->device.parent = &hv_acpi_dev->dev;
41575diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
41576index 6a34f7f..aa4c3a6 100644
41577--- a/drivers/hwmon/acpi_power_meter.c
41578+++ b/drivers/hwmon/acpi_power_meter.c
41579@@ -117,7 +117,7 @@ struct sensor_template {
41580 struct device_attribute *devattr,
41581 const char *buf, size_t count);
41582 int index;
41583-};
41584+} __do_const;
41585
41586 /* Averaging interval */
41587 static int update_avg_interval(struct acpi_power_meter_resource *resource)
41588@@ -632,7 +632,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
41589 struct sensor_template *attrs)
41590 {
41591 struct device *dev = &resource->acpi_dev->dev;
41592- struct sensor_device_attribute *sensors =
41593+ sensor_device_attribute_no_const *sensors =
41594 &resource->sensors[resource->num_sensors];
41595 int res = 0;
41596
41597diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
41598index 3288f13..71cfb4e 100644
41599--- a/drivers/hwmon/applesmc.c
41600+++ b/drivers/hwmon/applesmc.c
41601@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
41602 {
41603 struct applesmc_node_group *grp;
41604 struct applesmc_dev_attr *node;
41605- struct attribute *attr;
41606+ attribute_no_const *attr;
41607 int ret, i;
41608
41609 for (grp = groups; grp->format; grp++) {
41610diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
41611index dafc63c..4abb96c 100644
41612--- a/drivers/hwmon/asus_atk0110.c
41613+++ b/drivers/hwmon/asus_atk0110.c
41614@@ -151,10 +151,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
41615 struct atk_sensor_data {
41616 struct list_head list;
41617 struct atk_data *data;
41618- struct device_attribute label_attr;
41619- struct device_attribute input_attr;
41620- struct device_attribute limit1_attr;
41621- struct device_attribute limit2_attr;
41622+ device_attribute_no_const label_attr;
41623+ device_attribute_no_const input_attr;
41624+ device_attribute_no_const limit1_attr;
41625+ device_attribute_no_const limit2_attr;
41626 char label_attr_name[ATTR_NAME_SIZE];
41627 char input_attr_name[ATTR_NAME_SIZE];
41628 char limit1_attr_name[ATTR_NAME_SIZE];
41629@@ -274,7 +274,7 @@ static ssize_t atk_name_show(struct device *dev,
41630 static struct device_attribute atk_name_attr =
41631 __ATTR(name, 0444, atk_name_show, NULL);
41632
41633-static void atk_init_attribute(struct device_attribute *attr, char *name,
41634+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
41635 sysfs_show_func show)
41636 {
41637 sysfs_attr_init(&attr->attr);
41638diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
41639index 9425098..7646cc5 100644
41640--- a/drivers/hwmon/coretemp.c
41641+++ b/drivers/hwmon/coretemp.c
41642@@ -797,7 +797,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
41643 return NOTIFY_OK;
41644 }
41645
41646-static struct notifier_block coretemp_cpu_notifier __refdata = {
41647+static struct notifier_block coretemp_cpu_notifier = {
41648 .notifier_call = coretemp_cpu_callback,
41649 };
41650
41651diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
41652index 632f1dc..57e6a58 100644
41653--- a/drivers/hwmon/ibmaem.c
41654+++ b/drivers/hwmon/ibmaem.c
41655@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
41656 struct aem_rw_sensor_template *rw)
41657 {
41658 struct device *dev = &data->pdev->dev;
41659- struct sensor_device_attribute *sensors = data->sensors;
41660+ sensor_device_attribute_no_const *sensors = data->sensors;
41661 int err;
41662
41663 /* Set up read-only sensors */
41664diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
41665index 708081b..fe2d4ab 100644
41666--- a/drivers/hwmon/iio_hwmon.c
41667+++ b/drivers/hwmon/iio_hwmon.c
41668@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
41669 {
41670 struct device *dev = &pdev->dev;
41671 struct iio_hwmon_state *st;
41672- struct sensor_device_attribute *a;
41673+ sensor_device_attribute_no_const *a;
41674 int ret, i;
41675 int in_i = 1, temp_i = 1, curr_i = 1;
41676 enum iio_chan_type type;
41677diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
41678index cf811c1..4c17110 100644
41679--- a/drivers/hwmon/nct6775.c
41680+++ b/drivers/hwmon/nct6775.c
41681@@ -944,10 +944,10 @@ static struct attribute_group *
41682 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
41683 int repeat)
41684 {
41685- struct attribute_group *group;
41686+ attribute_group_no_const *group;
41687 struct sensor_device_attr_u *su;
41688- struct sensor_device_attribute *a;
41689- struct sensor_device_attribute_2 *a2;
41690+ sensor_device_attribute_no_const *a;
41691+ sensor_device_attribute_2_no_const *a2;
41692 struct attribute **attrs;
41693 struct sensor_device_template **t;
41694 int i, count;
41695diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
41696index 3cbf66e..8c5cc2a 100644
41697--- a/drivers/hwmon/pmbus/pmbus_core.c
41698+++ b/drivers/hwmon/pmbus/pmbus_core.c
41699@@ -782,7 +782,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41700 return 0;
41701 }
41702
41703-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41704+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41705 const char *name,
41706 umode_t mode,
41707 ssize_t (*show)(struct device *dev,
41708@@ -799,7 +799,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41709 dev_attr->store = store;
41710 }
41711
41712-static void pmbus_attr_init(struct sensor_device_attribute *a,
41713+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41714 const char *name,
41715 umode_t mode,
41716 ssize_t (*show)(struct device *dev,
41717@@ -821,7 +821,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41718 u16 reg, u8 mask)
41719 {
41720 struct pmbus_boolean *boolean;
41721- struct sensor_device_attribute *a;
41722+ sensor_device_attribute_no_const *a;
41723
41724 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41725 if (!boolean)
41726@@ -846,7 +846,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41727 bool update, bool readonly)
41728 {
41729 struct pmbus_sensor *sensor;
41730- struct device_attribute *a;
41731+ device_attribute_no_const *a;
41732
41733 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41734 if (!sensor)
41735@@ -877,7 +877,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41736 const char *lstring, int index)
41737 {
41738 struct pmbus_label *label;
41739- struct device_attribute *a;
41740+ device_attribute_no_const *a;
41741
41742 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41743 if (!label)
41744diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41745index 97cd45a..ac54d8b 100644
41746--- a/drivers/hwmon/sht15.c
41747+++ b/drivers/hwmon/sht15.c
41748@@ -169,7 +169,7 @@ struct sht15_data {
41749 int supply_uv;
41750 bool supply_uv_valid;
41751 struct work_struct update_supply_work;
41752- atomic_t interrupt_handled;
41753+ atomic_unchecked_t interrupt_handled;
41754 };
41755
41756 /**
41757@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41758 ret = gpio_direction_input(data->pdata->gpio_data);
41759 if (ret)
41760 return ret;
41761- atomic_set(&data->interrupt_handled, 0);
41762+ atomic_set_unchecked(&data->interrupt_handled, 0);
41763
41764 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41765 if (gpio_get_value(data->pdata->gpio_data) == 0) {
41766 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
41767 /* Only relevant if the interrupt hasn't occurred. */
41768- if (!atomic_read(&data->interrupt_handled))
41769+ if (!atomic_read_unchecked(&data->interrupt_handled))
41770 schedule_work(&data->read_work);
41771 }
41772 ret = wait_event_timeout(data->wait_queue,
41773@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
41774
41775 /* First disable the interrupt */
41776 disable_irq_nosync(irq);
41777- atomic_inc(&data->interrupt_handled);
41778+ atomic_inc_unchecked(&data->interrupt_handled);
41779 /* Then schedule a reading work struct */
41780 if (data->state != SHT15_READING_NOTHING)
41781 schedule_work(&data->read_work);
41782@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
41783 * If not, then start the interrupt again - care here as could
41784 * have gone low in meantime so verify it hasn't!
41785 */
41786- atomic_set(&data->interrupt_handled, 0);
41787+ atomic_set_unchecked(&data->interrupt_handled, 0);
41788 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41789 /* If still not occurred or another handler was scheduled */
41790 if (gpio_get_value(data->pdata->gpio_data)
41791- || atomic_read(&data->interrupt_handled))
41792+ || atomic_read_unchecked(&data->interrupt_handled))
41793 return;
41794 }
41795
41796diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
41797index 38944e9..ae9e5ed 100644
41798--- a/drivers/hwmon/via-cputemp.c
41799+++ b/drivers/hwmon/via-cputemp.c
41800@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
41801 return NOTIFY_OK;
41802 }
41803
41804-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
41805+static struct notifier_block via_cputemp_cpu_notifier = {
41806 .notifier_call = via_cputemp_cpu_callback,
41807 };
41808
41809diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
41810index 07f01ac..d79ad3d 100644
41811--- a/drivers/i2c/busses/i2c-amd756-s4882.c
41812+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
41813@@ -43,7 +43,7 @@
41814 extern struct i2c_adapter amd756_smbus;
41815
41816 static struct i2c_adapter *s4882_adapter;
41817-static struct i2c_algorithm *s4882_algo;
41818+static i2c_algorithm_no_const *s4882_algo;
41819
41820 /* Wrapper access functions for multiplexed SMBus */
41821 static DEFINE_MUTEX(amd756_lock);
41822diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
41823index 721f7eb..0fd2a09 100644
41824--- a/drivers/i2c/busses/i2c-diolan-u2c.c
41825+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
41826@@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
41827 /* usb layer */
41828
41829 /* Send command to device, and get response. */
41830-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41831+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41832 {
41833 int ret = 0;
41834 int actual;
41835diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
41836index 2ca268d..c6acbdf 100644
41837--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
41838+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
41839@@ -41,7 +41,7 @@
41840 extern struct i2c_adapter *nforce2_smbus;
41841
41842 static struct i2c_adapter *s4985_adapter;
41843-static struct i2c_algorithm *s4985_algo;
41844+static i2c_algorithm_no_const *s4985_algo;
41845
41846 /* Wrapper access functions for multiplexed SMBus */
41847 static DEFINE_MUTEX(nforce2_lock);
41848diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
41849index 80b47e8..1a6040d9 100644
41850--- a/drivers/i2c/i2c-dev.c
41851+++ b/drivers/i2c/i2c-dev.c
41852@@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
41853 break;
41854 }
41855
41856- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
41857+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
41858 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
41859 if (IS_ERR(rdwr_pa[i].buf)) {
41860 res = PTR_ERR(rdwr_pa[i].buf);
41861diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
41862index 0b510ba..4fbb5085 100644
41863--- a/drivers/ide/ide-cd.c
41864+++ b/drivers/ide/ide-cd.c
41865@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
41866 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
41867 if ((unsigned long)buf & alignment
41868 || blk_rq_bytes(rq) & q->dma_pad_mask
41869- || object_is_on_stack(buf))
41870+ || object_starts_on_stack(buf))
41871 drive->dma = 0;
41872 }
41873 }
41874diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
41875index 18f72e3..3722327 100644
41876--- a/drivers/iio/industrialio-core.c
41877+++ b/drivers/iio/industrialio-core.c
41878@@ -521,7 +521,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
41879 }
41880
41881 static
41882-int __iio_device_attr_init(struct device_attribute *dev_attr,
41883+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
41884 const char *postfix,
41885 struct iio_chan_spec const *chan,
41886 ssize_t (*readfunc)(struct device *dev,
41887diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
41888index f2ef7ef..743d02f 100644
41889--- a/drivers/infiniband/core/cm.c
41890+++ b/drivers/infiniband/core/cm.c
41891@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
41892
41893 struct cm_counter_group {
41894 struct kobject obj;
41895- atomic_long_t counter[CM_ATTR_COUNT];
41896+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
41897 };
41898
41899 struct cm_counter_attribute {
41900@@ -1392,7 +1392,7 @@ static void cm_dup_req_handler(struct cm_work *work,
41901 struct ib_mad_send_buf *msg = NULL;
41902 int ret;
41903
41904- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41905+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41906 counter[CM_REQ_COUNTER]);
41907
41908 /* Quick state check to discard duplicate REQs. */
41909@@ -1776,7 +1776,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
41910 if (!cm_id_priv)
41911 return;
41912
41913- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41914+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41915 counter[CM_REP_COUNTER]);
41916 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
41917 if (ret)
41918@@ -1943,7 +1943,7 @@ static int cm_rtu_handler(struct cm_work *work)
41919 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
41920 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
41921 spin_unlock_irq(&cm_id_priv->lock);
41922- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41923+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41924 counter[CM_RTU_COUNTER]);
41925 goto out;
41926 }
41927@@ -2126,7 +2126,7 @@ static int cm_dreq_handler(struct cm_work *work)
41928 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
41929 dreq_msg->local_comm_id);
41930 if (!cm_id_priv) {
41931- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41932+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41933 counter[CM_DREQ_COUNTER]);
41934 cm_issue_drep(work->port, work->mad_recv_wc);
41935 return -EINVAL;
41936@@ -2151,7 +2151,7 @@ static int cm_dreq_handler(struct cm_work *work)
41937 case IB_CM_MRA_REP_RCVD:
41938 break;
41939 case IB_CM_TIMEWAIT:
41940- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41941+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41942 counter[CM_DREQ_COUNTER]);
41943 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41944 goto unlock;
41945@@ -2165,7 +2165,7 @@ static int cm_dreq_handler(struct cm_work *work)
41946 cm_free_msg(msg);
41947 goto deref;
41948 case IB_CM_DREQ_RCVD:
41949- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41950+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41951 counter[CM_DREQ_COUNTER]);
41952 goto unlock;
41953 default:
41954@@ -2532,7 +2532,7 @@ static int cm_mra_handler(struct cm_work *work)
41955 ib_modify_mad(cm_id_priv->av.port->mad_agent,
41956 cm_id_priv->msg, timeout)) {
41957 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
41958- atomic_long_inc(&work->port->
41959+ atomic_long_inc_unchecked(&work->port->
41960 counter_group[CM_RECV_DUPLICATES].
41961 counter[CM_MRA_COUNTER]);
41962 goto out;
41963@@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
41964 break;
41965 case IB_CM_MRA_REQ_RCVD:
41966 case IB_CM_MRA_REP_RCVD:
41967- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41968+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41969 counter[CM_MRA_COUNTER]);
41970 /* fall through */
41971 default:
41972@@ -2703,7 +2703,7 @@ static int cm_lap_handler(struct cm_work *work)
41973 case IB_CM_LAP_IDLE:
41974 break;
41975 case IB_CM_MRA_LAP_SENT:
41976- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41977+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41978 counter[CM_LAP_COUNTER]);
41979 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41980 goto unlock;
41981@@ -2719,7 +2719,7 @@ static int cm_lap_handler(struct cm_work *work)
41982 cm_free_msg(msg);
41983 goto deref;
41984 case IB_CM_LAP_RCVD:
41985- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41986+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41987 counter[CM_LAP_COUNTER]);
41988 goto unlock;
41989 default:
41990@@ -3003,7 +3003,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
41991 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
41992 if (cur_cm_id_priv) {
41993 spin_unlock_irq(&cm.lock);
41994- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41995+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41996 counter[CM_SIDR_REQ_COUNTER]);
41997 goto out; /* Duplicate message. */
41998 }
41999@@ -3215,10 +3215,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42000 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42001 msg->retries = 1;
42002
42003- atomic_long_add(1 + msg->retries,
42004+ atomic_long_add_unchecked(1 + msg->retries,
42005 &port->counter_group[CM_XMIT].counter[attr_index]);
42006 if (msg->retries)
42007- atomic_long_add(msg->retries,
42008+ atomic_long_add_unchecked(msg->retries,
42009 &port->counter_group[CM_XMIT_RETRIES].
42010 counter[attr_index]);
42011
42012@@ -3428,7 +3428,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42013 }
42014
42015 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42016- atomic_long_inc(&port->counter_group[CM_RECV].
42017+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42018 counter[attr_id - CM_ATTR_ID_OFFSET]);
42019
42020 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42021@@ -3633,7 +3633,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42022 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42023
42024 return sprintf(buf, "%ld\n",
42025- atomic_long_read(&group->counter[cm_attr->index]));
42026+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42027 }
42028
42029 static const struct sysfs_ops cm_counter_ops = {
42030diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42031index 9f5ad7c..588cd84 100644
42032--- a/drivers/infiniband/core/fmr_pool.c
42033+++ b/drivers/infiniband/core/fmr_pool.c
42034@@ -98,8 +98,8 @@ struct ib_fmr_pool {
42035
42036 struct task_struct *thread;
42037
42038- atomic_t req_ser;
42039- atomic_t flush_ser;
42040+ atomic_unchecked_t req_ser;
42041+ atomic_unchecked_t flush_ser;
42042
42043 wait_queue_head_t force_wait;
42044 };
42045@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42046 struct ib_fmr_pool *pool = pool_ptr;
42047
42048 do {
42049- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42050+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42051 ib_fmr_batch_release(pool);
42052
42053- atomic_inc(&pool->flush_ser);
42054+ atomic_inc_unchecked(&pool->flush_ser);
42055 wake_up_interruptible(&pool->force_wait);
42056
42057 if (pool->flush_function)
42058@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42059 }
42060
42061 set_current_state(TASK_INTERRUPTIBLE);
42062- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42063+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42064 !kthread_should_stop())
42065 schedule();
42066 __set_current_state(TASK_RUNNING);
42067@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42068 pool->dirty_watermark = params->dirty_watermark;
42069 pool->dirty_len = 0;
42070 spin_lock_init(&pool->pool_lock);
42071- atomic_set(&pool->req_ser, 0);
42072- atomic_set(&pool->flush_ser, 0);
42073+ atomic_set_unchecked(&pool->req_ser, 0);
42074+ atomic_set_unchecked(&pool->flush_ser, 0);
42075 init_waitqueue_head(&pool->force_wait);
42076
42077 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42078@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42079 }
42080 spin_unlock_irq(&pool->pool_lock);
42081
42082- serial = atomic_inc_return(&pool->req_ser);
42083+ serial = atomic_inc_return_unchecked(&pool->req_ser);
42084 wake_up_process(pool->thread);
42085
42086 if (wait_event_interruptible(pool->force_wait,
42087- atomic_read(&pool->flush_ser) - serial >= 0))
42088+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42089 return -EINTR;
42090
42091 return 0;
42092@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42093 } else {
42094 list_add_tail(&fmr->list, &pool->dirty_list);
42095 if (++pool->dirty_len >= pool->dirty_watermark) {
42096- atomic_inc(&pool->req_ser);
42097+ atomic_inc_unchecked(&pool->req_ser);
42098 wake_up_process(pool->thread);
42099 }
42100 }
42101diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42102index 84e4500..2c9beeb 100644
42103--- a/drivers/infiniband/hw/cxgb4/mem.c
42104+++ b/drivers/infiniband/hw/cxgb4/mem.c
42105@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42106 int err;
42107 struct fw_ri_tpte tpt;
42108 u32 stag_idx;
42109- static atomic_t key;
42110+ static atomic_unchecked_t key;
42111
42112 if (c4iw_fatal_error(rdev))
42113 return -EIO;
42114@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42115 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42116 rdev->stats.stag.max = rdev->stats.stag.cur;
42117 mutex_unlock(&rdev->stats.lock);
42118- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42119+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42120 }
42121 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42122 __func__, stag_state, type, pdid, stag_idx);
42123diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
42124index 644c2c7..ecf0879 100644
42125--- a/drivers/infiniband/hw/ipath/ipath_dma.c
42126+++ b/drivers/infiniband/hw/ipath/ipath_dma.c
42127@@ -176,17 +176,17 @@ static void ipath_dma_free_coherent(struct ib_device *dev, size_t size,
42128 }
42129
42130 struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
42131- ipath_mapping_error,
42132- ipath_dma_map_single,
42133- ipath_dma_unmap_single,
42134- ipath_dma_map_page,
42135- ipath_dma_unmap_page,
42136- ipath_map_sg,
42137- ipath_unmap_sg,
42138- ipath_sg_dma_address,
42139- ipath_sg_dma_len,
42140- ipath_sync_single_for_cpu,
42141- ipath_sync_single_for_device,
42142- ipath_dma_alloc_coherent,
42143- ipath_dma_free_coherent
42144+ .mapping_error = ipath_mapping_error,
42145+ .map_single = ipath_dma_map_single,
42146+ .unmap_single = ipath_dma_unmap_single,
42147+ .map_page = ipath_dma_map_page,
42148+ .unmap_page = ipath_dma_unmap_page,
42149+ .map_sg = ipath_map_sg,
42150+ .unmap_sg = ipath_unmap_sg,
42151+ .dma_address = ipath_sg_dma_address,
42152+ .dma_len = ipath_sg_dma_len,
42153+ .sync_single_for_cpu = ipath_sync_single_for_cpu,
42154+ .sync_single_for_device = ipath_sync_single_for_device,
42155+ .alloc_coherent = ipath_dma_alloc_coherent,
42156+ .free_coherent = ipath_dma_free_coherent
42157 };
42158diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42159index 79b3dbc..96e5fcc 100644
42160--- a/drivers/infiniband/hw/ipath/ipath_rc.c
42161+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42162@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42163 struct ib_atomic_eth *ateth;
42164 struct ipath_ack_entry *e;
42165 u64 vaddr;
42166- atomic64_t *maddr;
42167+ atomic64_unchecked_t *maddr;
42168 u64 sdata;
42169 u32 rkey;
42170 u8 next;
42171@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42172 IB_ACCESS_REMOTE_ATOMIC)))
42173 goto nack_acc_unlck;
42174 /* Perform atomic OP and save result. */
42175- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42176+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42177 sdata = be64_to_cpu(ateth->swap_data);
42178 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42179 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42180- (u64) atomic64_add_return(sdata, maddr) - sdata :
42181+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42182 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42183 be64_to_cpu(ateth->compare_data),
42184 sdata);
42185diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42186index 1f95bba..9530f87 100644
42187--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42188+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42189@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42190 unsigned long flags;
42191 struct ib_wc wc;
42192 u64 sdata;
42193- atomic64_t *maddr;
42194+ atomic64_unchecked_t *maddr;
42195 enum ib_wc_status send_status;
42196
42197 /*
42198@@ -382,11 +382,11 @@ again:
42199 IB_ACCESS_REMOTE_ATOMIC)))
42200 goto acc_err;
42201 /* Perform atomic OP and save result. */
42202- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42203+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42204 sdata = wqe->wr.wr.atomic.compare_add;
42205 *(u64 *) sqp->s_sge.sge.vaddr =
42206 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42207- (u64) atomic64_add_return(sdata, maddr) - sdata :
42208+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42209 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42210 sdata, wqe->wr.wr.atomic.swap);
42211 goto send_comp;
42212diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42213index f2a3f48..673ec79 100644
42214--- a/drivers/infiniband/hw/mlx4/mad.c
42215+++ b/drivers/infiniband/hw/mlx4/mad.c
42216@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42217
42218 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42219 {
42220- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42221+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42222 cpu_to_be64(0xff00000000000000LL);
42223 }
42224
42225diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42226index 25b2cdf..099ff97 100644
42227--- a/drivers/infiniband/hw/mlx4/mcg.c
42228+++ b/drivers/infiniband/hw/mlx4/mcg.c
42229@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42230 {
42231 char name[20];
42232
42233- atomic_set(&ctx->tid, 0);
42234+ atomic_set_unchecked(&ctx->tid, 0);
42235 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42236 ctx->mcg_wq = create_singlethread_workqueue(name);
42237 if (!ctx->mcg_wq)
42238diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42239index 036b663..c9a8c73 100644
42240--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42241+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42242@@ -404,7 +404,7 @@ struct mlx4_ib_demux_ctx {
42243 struct list_head mcg_mgid0_list;
42244 struct workqueue_struct *mcg_wq;
42245 struct mlx4_ib_demux_pv_ctx **tun;
42246- atomic_t tid;
42247+ atomic_unchecked_t tid;
42248 int flushing; /* flushing the work queue */
42249 };
42250
42251diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42252index 9d3e5c1..6f166df 100644
42253--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42254+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42255@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42256 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42257 }
42258
42259-int mthca_QUERY_FW(struct mthca_dev *dev)
42260+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42261 {
42262 struct mthca_mailbox *mailbox;
42263 u32 *outbox;
42264@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42265 CMD_TIME_CLASS_B);
42266 }
42267
42268-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42269+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42270 int num_mtt)
42271 {
42272 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42273@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42274 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42275 }
42276
42277-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42278+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42279 int eq_num)
42280 {
42281 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42282@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42283 CMD_TIME_CLASS_B);
42284 }
42285
42286-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42287+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42288 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42289 void *in_mad, void *response_mad)
42290 {
42291diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42292index 87897b9..7e79542 100644
42293--- a/drivers/infiniband/hw/mthca/mthca_main.c
42294+++ b/drivers/infiniband/hw/mthca/mthca_main.c
42295@@ -692,7 +692,7 @@ err_close:
42296 return err;
42297 }
42298
42299-static int mthca_setup_hca(struct mthca_dev *dev)
42300+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42301 {
42302 int err;
42303
42304diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42305index ed9a989..6aa5dc2 100644
42306--- a/drivers/infiniband/hw/mthca/mthca_mr.c
42307+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42308@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42309 * through the bitmaps)
42310 */
42311
42312-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42313+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42314 {
42315 int o;
42316 int m;
42317@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42318 return key;
42319 }
42320
42321-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42322+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42323 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42324 {
42325 struct mthca_mailbox *mailbox;
42326@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42327 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42328 }
42329
42330-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42331+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42332 u64 *buffer_list, int buffer_size_shift,
42333 int list_len, u64 iova, u64 total_size,
42334 u32 access, struct mthca_mr *mr)
42335diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42336index 5b71d43..35a9e14 100644
42337--- a/drivers/infiniband/hw/mthca/mthca_provider.c
42338+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42339@@ -763,7 +763,7 @@ unlock:
42340 return 0;
42341 }
42342
42343-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42344+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42345 {
42346 struct mthca_dev *dev = to_mdev(ibcq->device);
42347 struct mthca_cq *cq = to_mcq(ibcq);
42348diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42349index 4291410..d2ab1fb 100644
42350--- a/drivers/infiniband/hw/nes/nes.c
42351+++ b/drivers/infiniband/hw/nes/nes.c
42352@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42353 LIST_HEAD(nes_adapter_list);
42354 static LIST_HEAD(nes_dev_list);
42355
42356-atomic_t qps_destroyed;
42357+atomic_unchecked_t qps_destroyed;
42358
42359 static unsigned int ee_flsh_adapter;
42360 static unsigned int sysfs_nonidx_addr;
42361@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42362 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42363 struct nes_adapter *nesadapter = nesdev->nesadapter;
42364
42365- atomic_inc(&qps_destroyed);
42366+ atomic_inc_unchecked(&qps_destroyed);
42367
42368 /* Free the control structures */
42369
42370diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42371index 33cc589..3bd6538 100644
42372--- a/drivers/infiniband/hw/nes/nes.h
42373+++ b/drivers/infiniband/hw/nes/nes.h
42374@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42375 extern unsigned int wqm_quanta;
42376 extern struct list_head nes_adapter_list;
42377
42378-extern atomic_t cm_connects;
42379-extern atomic_t cm_accepts;
42380-extern atomic_t cm_disconnects;
42381-extern atomic_t cm_closes;
42382-extern atomic_t cm_connecteds;
42383-extern atomic_t cm_connect_reqs;
42384-extern atomic_t cm_rejects;
42385-extern atomic_t mod_qp_timouts;
42386-extern atomic_t qps_created;
42387-extern atomic_t qps_destroyed;
42388-extern atomic_t sw_qps_destroyed;
42389+extern atomic_unchecked_t cm_connects;
42390+extern atomic_unchecked_t cm_accepts;
42391+extern atomic_unchecked_t cm_disconnects;
42392+extern atomic_unchecked_t cm_closes;
42393+extern atomic_unchecked_t cm_connecteds;
42394+extern atomic_unchecked_t cm_connect_reqs;
42395+extern atomic_unchecked_t cm_rejects;
42396+extern atomic_unchecked_t mod_qp_timouts;
42397+extern atomic_unchecked_t qps_created;
42398+extern atomic_unchecked_t qps_destroyed;
42399+extern atomic_unchecked_t sw_qps_destroyed;
42400 extern u32 mh_detected;
42401 extern u32 mh_pauses_sent;
42402 extern u32 cm_packets_sent;
42403@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42404 extern u32 cm_packets_received;
42405 extern u32 cm_packets_dropped;
42406 extern u32 cm_packets_retrans;
42407-extern atomic_t cm_listens_created;
42408-extern atomic_t cm_listens_destroyed;
42409+extern atomic_unchecked_t cm_listens_created;
42410+extern atomic_unchecked_t cm_listens_destroyed;
42411 extern u32 cm_backlog_drops;
42412-extern atomic_t cm_loopbacks;
42413-extern atomic_t cm_nodes_created;
42414-extern atomic_t cm_nodes_destroyed;
42415-extern atomic_t cm_accel_dropped_pkts;
42416-extern atomic_t cm_resets_recvd;
42417-extern atomic_t pau_qps_created;
42418-extern atomic_t pau_qps_destroyed;
42419+extern atomic_unchecked_t cm_loopbacks;
42420+extern atomic_unchecked_t cm_nodes_created;
42421+extern atomic_unchecked_t cm_nodes_destroyed;
42422+extern atomic_unchecked_t cm_accel_dropped_pkts;
42423+extern atomic_unchecked_t cm_resets_recvd;
42424+extern atomic_unchecked_t pau_qps_created;
42425+extern atomic_unchecked_t pau_qps_destroyed;
42426
42427 extern u32 int_mod_timer_init;
42428 extern u32 int_mod_cq_depth_256;
42429diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42430index 6b29249..461d143 100644
42431--- a/drivers/infiniband/hw/nes/nes_cm.c
42432+++ b/drivers/infiniband/hw/nes/nes_cm.c
42433@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42434 u32 cm_packets_retrans;
42435 u32 cm_packets_created;
42436 u32 cm_packets_received;
42437-atomic_t cm_listens_created;
42438-atomic_t cm_listens_destroyed;
42439+atomic_unchecked_t cm_listens_created;
42440+atomic_unchecked_t cm_listens_destroyed;
42441 u32 cm_backlog_drops;
42442-atomic_t cm_loopbacks;
42443-atomic_t cm_nodes_created;
42444-atomic_t cm_nodes_destroyed;
42445-atomic_t cm_accel_dropped_pkts;
42446-atomic_t cm_resets_recvd;
42447+atomic_unchecked_t cm_loopbacks;
42448+atomic_unchecked_t cm_nodes_created;
42449+atomic_unchecked_t cm_nodes_destroyed;
42450+atomic_unchecked_t cm_accel_dropped_pkts;
42451+atomic_unchecked_t cm_resets_recvd;
42452
42453 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42454 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42455@@ -133,28 +133,28 @@ static void print_core(struct nes_cm_core *core);
42456 /* instance of function pointers for client API */
42457 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42458 static struct nes_cm_ops nes_cm_api = {
42459- mini_cm_accelerated,
42460- mini_cm_listen,
42461- mini_cm_del_listen,
42462- mini_cm_connect,
42463- mini_cm_close,
42464- mini_cm_accept,
42465- mini_cm_reject,
42466- mini_cm_recv_pkt,
42467- mini_cm_dealloc_core,
42468- mini_cm_get,
42469- mini_cm_set
42470+ .accelerated = mini_cm_accelerated,
42471+ .listen = mini_cm_listen,
42472+ .stop_listener = mini_cm_del_listen,
42473+ .connect = mini_cm_connect,
42474+ .close = mini_cm_close,
42475+ .accept = mini_cm_accept,
42476+ .reject = mini_cm_reject,
42477+ .recv_pkt = mini_cm_recv_pkt,
42478+ .destroy_cm_core = mini_cm_dealloc_core,
42479+ .get = mini_cm_get,
42480+ .set = mini_cm_set
42481 };
42482
42483 static struct nes_cm_core *g_cm_core;
42484
42485-atomic_t cm_connects;
42486-atomic_t cm_accepts;
42487-atomic_t cm_disconnects;
42488-atomic_t cm_closes;
42489-atomic_t cm_connecteds;
42490-atomic_t cm_connect_reqs;
42491-atomic_t cm_rejects;
42492+atomic_unchecked_t cm_connects;
42493+atomic_unchecked_t cm_accepts;
42494+atomic_unchecked_t cm_disconnects;
42495+atomic_unchecked_t cm_closes;
42496+atomic_unchecked_t cm_connecteds;
42497+atomic_unchecked_t cm_connect_reqs;
42498+atomic_unchecked_t cm_rejects;
42499
42500 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
42501 {
42502@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
42503 kfree(listener);
42504 listener = NULL;
42505 ret = 0;
42506- atomic_inc(&cm_listens_destroyed);
42507+ atomic_inc_unchecked(&cm_listens_destroyed);
42508 } else {
42509 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
42510 }
42511@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
42512 cm_node->rem_mac);
42513
42514 add_hte_node(cm_core, cm_node);
42515- atomic_inc(&cm_nodes_created);
42516+ atomic_inc_unchecked(&cm_nodes_created);
42517
42518 return cm_node;
42519 }
42520@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
42521 }
42522
42523 atomic_dec(&cm_core->node_cnt);
42524- atomic_inc(&cm_nodes_destroyed);
42525+ atomic_inc_unchecked(&cm_nodes_destroyed);
42526 nesqp = cm_node->nesqp;
42527 if (nesqp) {
42528 nesqp->cm_node = NULL;
42529@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
42530
42531 static void drop_packet(struct sk_buff *skb)
42532 {
42533- atomic_inc(&cm_accel_dropped_pkts);
42534+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
42535 dev_kfree_skb_any(skb);
42536 }
42537
42538@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
42539 {
42540
42541 int reset = 0; /* whether to send reset in case of err.. */
42542- atomic_inc(&cm_resets_recvd);
42543+ atomic_inc_unchecked(&cm_resets_recvd);
42544 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
42545 " refcnt=%d\n", cm_node, cm_node->state,
42546 atomic_read(&cm_node->ref_count));
42547@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
42548 rem_ref_cm_node(cm_node->cm_core, cm_node);
42549 return NULL;
42550 }
42551- atomic_inc(&cm_loopbacks);
42552+ atomic_inc_unchecked(&cm_loopbacks);
42553 loopbackremotenode->loopbackpartner = cm_node;
42554 loopbackremotenode->tcp_cntxt.rcv_wscale =
42555 NES_CM_DEFAULT_RCV_WND_SCALE;
42556@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
42557 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
42558 else {
42559 rem_ref_cm_node(cm_core, cm_node);
42560- atomic_inc(&cm_accel_dropped_pkts);
42561+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
42562 dev_kfree_skb_any(skb);
42563 }
42564 break;
42565@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42566
42567 if ((cm_id) && (cm_id->event_handler)) {
42568 if (issue_disconn) {
42569- atomic_inc(&cm_disconnects);
42570+ atomic_inc_unchecked(&cm_disconnects);
42571 cm_event.event = IW_CM_EVENT_DISCONNECT;
42572 cm_event.status = disconn_status;
42573 cm_event.local_addr = cm_id->local_addr;
42574@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42575 }
42576
42577 if (issue_close) {
42578- atomic_inc(&cm_closes);
42579+ atomic_inc_unchecked(&cm_closes);
42580 nes_disconnect(nesqp, 1);
42581
42582 cm_id->provider_data = nesqp;
42583@@ -3035,7 +3035,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42584
42585 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
42586 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
42587- atomic_inc(&cm_accepts);
42588+ atomic_inc_unchecked(&cm_accepts);
42589
42590 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
42591 netdev_refcnt_read(nesvnic->netdev));
42592@@ -3224,7 +3224,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
42593 struct nes_cm_core *cm_core;
42594 u8 *start_buff;
42595
42596- atomic_inc(&cm_rejects);
42597+ atomic_inc_unchecked(&cm_rejects);
42598 cm_node = (struct nes_cm_node *)cm_id->provider_data;
42599 loopback = cm_node->loopbackpartner;
42600 cm_core = cm_node->cm_core;
42601@@ -3286,7 +3286,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42602 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
42603 ntohs(laddr->sin_port));
42604
42605- atomic_inc(&cm_connects);
42606+ atomic_inc_unchecked(&cm_connects);
42607 nesqp->active_conn = 1;
42608
42609 /* cache the cm_id in the qp */
42610@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
42611 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
42612 return err;
42613 }
42614- atomic_inc(&cm_listens_created);
42615+ atomic_inc_unchecked(&cm_listens_created);
42616 }
42617
42618 cm_id->add_ref(cm_id);
42619@@ -3505,7 +3505,7 @@ static void cm_event_connected(struct nes_cm_event *event)
42620
42621 if (nesqp->destroyed)
42622 return;
42623- atomic_inc(&cm_connecteds);
42624+ atomic_inc_unchecked(&cm_connecteds);
42625 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
42626 " local port 0x%04X. jiffies = %lu.\n",
42627 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
42628@@ -3686,7 +3686,7 @@ static void cm_event_reset(struct nes_cm_event *event)
42629
42630 cm_id->add_ref(cm_id);
42631 ret = cm_id->event_handler(cm_id, &cm_event);
42632- atomic_inc(&cm_closes);
42633+ atomic_inc_unchecked(&cm_closes);
42634 cm_event.event = IW_CM_EVENT_CLOSE;
42635 cm_event.status = 0;
42636 cm_event.provider_data = cm_id->provider_data;
42637@@ -3726,7 +3726,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
42638 return;
42639 cm_id = cm_node->cm_id;
42640
42641- atomic_inc(&cm_connect_reqs);
42642+ atomic_inc_unchecked(&cm_connect_reqs);
42643 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42644 cm_node, cm_id, jiffies);
42645
42646@@ -3770,7 +3770,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
42647 return;
42648 cm_id = cm_node->cm_id;
42649
42650- atomic_inc(&cm_connect_reqs);
42651+ atomic_inc_unchecked(&cm_connect_reqs);
42652 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42653 cm_node, cm_id, jiffies);
42654
42655diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
42656index 4166452..fc952c3 100644
42657--- a/drivers/infiniband/hw/nes/nes_mgt.c
42658+++ b/drivers/infiniband/hw/nes/nes_mgt.c
42659@@ -40,8 +40,8 @@
42660 #include "nes.h"
42661 #include "nes_mgt.h"
42662
42663-atomic_t pau_qps_created;
42664-atomic_t pau_qps_destroyed;
42665+atomic_unchecked_t pau_qps_created;
42666+atomic_unchecked_t pau_qps_destroyed;
42667
42668 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
42669 {
42670@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
42671 {
42672 struct sk_buff *skb;
42673 unsigned long flags;
42674- atomic_inc(&pau_qps_destroyed);
42675+ atomic_inc_unchecked(&pau_qps_destroyed);
42676
42677 /* Free packets that have not yet been forwarded */
42678 /* Lock is acquired by skb_dequeue when removing the skb */
42679@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
42680 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
42681 skb_queue_head_init(&nesqp->pau_list);
42682 spin_lock_init(&nesqp->pau_lock);
42683- atomic_inc(&pau_qps_created);
42684+ atomic_inc_unchecked(&pau_qps_created);
42685 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
42686 }
42687
42688diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
42689index 49eb511..a774366 100644
42690--- a/drivers/infiniband/hw/nes/nes_nic.c
42691+++ b/drivers/infiniband/hw/nes/nes_nic.c
42692@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
42693 target_stat_values[++index] = mh_detected;
42694 target_stat_values[++index] = mh_pauses_sent;
42695 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
42696- target_stat_values[++index] = atomic_read(&cm_connects);
42697- target_stat_values[++index] = atomic_read(&cm_accepts);
42698- target_stat_values[++index] = atomic_read(&cm_disconnects);
42699- target_stat_values[++index] = atomic_read(&cm_connecteds);
42700- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42701- target_stat_values[++index] = atomic_read(&cm_rejects);
42702- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42703- target_stat_values[++index] = atomic_read(&qps_created);
42704- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42705- target_stat_values[++index] = atomic_read(&qps_destroyed);
42706- target_stat_values[++index] = atomic_read(&cm_closes);
42707+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42708+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42709+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42710+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42711+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42712+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42713+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42714+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42715+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42716+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42717+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42718 target_stat_values[++index] = cm_packets_sent;
42719 target_stat_values[++index] = cm_packets_bounced;
42720 target_stat_values[++index] = cm_packets_created;
42721 target_stat_values[++index] = cm_packets_received;
42722 target_stat_values[++index] = cm_packets_dropped;
42723 target_stat_values[++index] = cm_packets_retrans;
42724- target_stat_values[++index] = atomic_read(&cm_listens_created);
42725- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42726+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42727+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42728 target_stat_values[++index] = cm_backlog_drops;
42729- target_stat_values[++index] = atomic_read(&cm_loopbacks);
42730- target_stat_values[++index] = atomic_read(&cm_nodes_created);
42731- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42732- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42733- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42734+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42735+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42736+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42737+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42738+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42739 target_stat_values[++index] = nesadapter->free_4kpbl;
42740 target_stat_values[++index] = nesadapter->free_256pbl;
42741 target_stat_values[++index] = int_mod_timer_init;
42742 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42743 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42744 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42745- target_stat_values[++index] = atomic_read(&pau_qps_created);
42746- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42747+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42748+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42749 }
42750
42751 /**
42752diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42753index 8308e36..ae0d3b5 100644
42754--- a/drivers/infiniband/hw/nes/nes_verbs.c
42755+++ b/drivers/infiniband/hw/nes/nes_verbs.c
42756@@ -46,9 +46,9 @@
42757
42758 #include <rdma/ib_umem.h>
42759
42760-atomic_t mod_qp_timouts;
42761-atomic_t qps_created;
42762-atomic_t sw_qps_destroyed;
42763+atomic_unchecked_t mod_qp_timouts;
42764+atomic_unchecked_t qps_created;
42765+atomic_unchecked_t sw_qps_destroyed;
42766
42767 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42768
42769@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42770 if (init_attr->create_flags)
42771 return ERR_PTR(-EINVAL);
42772
42773- atomic_inc(&qps_created);
42774+ atomic_inc_unchecked(&qps_created);
42775 switch (init_attr->qp_type) {
42776 case IB_QPT_RC:
42777 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42778@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42779 struct iw_cm_event cm_event;
42780 int ret = 0;
42781
42782- atomic_inc(&sw_qps_destroyed);
42783+ atomic_inc_unchecked(&sw_qps_destroyed);
42784 nesqp->destroyed = 1;
42785
42786 /* Blow away the connection if it exists. */
42787diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42788index 1946101..09766d2 100644
42789--- a/drivers/infiniband/hw/qib/qib.h
42790+++ b/drivers/infiniband/hw/qib/qib.h
42791@@ -52,6 +52,7 @@
42792 #include <linux/kref.h>
42793 #include <linux/sched.h>
42794 #include <linux/kthread.h>
42795+#include <linux/slab.h>
42796
42797 #include "qib_common.h"
42798 #include "qib_verbs.h"
42799diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
42800index 24c41ba..102d71f 100644
42801--- a/drivers/input/gameport/gameport.c
42802+++ b/drivers/input/gameport/gameport.c
42803@@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
42804 */
42805 static void gameport_init_port(struct gameport *gameport)
42806 {
42807- static atomic_t gameport_no = ATOMIC_INIT(0);
42808+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
42809
42810 __module_get(THIS_MODULE);
42811
42812 mutex_init(&gameport->drv_mutex);
42813 device_initialize(&gameport->dev);
42814 dev_set_name(&gameport->dev, "gameport%lu",
42815- (unsigned long)atomic_inc_return(&gameport_no) - 1);
42816+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
42817 gameport->dev.bus = &gameport_bus;
42818 gameport->dev.release = gameport_release_port;
42819 if (gameport->parent)
42820diff --git a/drivers/input/input.c b/drivers/input/input.c
42821index d2965e4..f52b7d7 100644
42822--- a/drivers/input/input.c
42823+++ b/drivers/input/input.c
42824@@ -1734,7 +1734,7 @@ EXPORT_SYMBOL_GPL(input_class);
42825 */
42826 struct input_dev *input_allocate_device(void)
42827 {
42828- static atomic_t input_no = ATOMIC_INIT(0);
42829+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
42830 struct input_dev *dev;
42831
42832 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
42833@@ -1749,7 +1749,7 @@ struct input_dev *input_allocate_device(void)
42834 INIT_LIST_HEAD(&dev->node);
42835
42836 dev_set_name(&dev->dev, "input%ld",
42837- (unsigned long) atomic_inc_return(&input_no) - 1);
42838+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
42839
42840 __module_get(THIS_MODULE);
42841 }
42842diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
42843index 04c69af..5f92d00 100644
42844--- a/drivers/input/joystick/sidewinder.c
42845+++ b/drivers/input/joystick/sidewinder.c
42846@@ -30,6 +30,7 @@
42847 #include <linux/kernel.h>
42848 #include <linux/module.h>
42849 #include <linux/slab.h>
42850+#include <linux/sched.h>
42851 #include <linux/init.h>
42852 #include <linux/input.h>
42853 #include <linux/gameport.h>
42854diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
42855index 75e3b10..fb390fd 100644
42856--- a/drivers/input/joystick/xpad.c
42857+++ b/drivers/input/joystick/xpad.c
42858@@ -736,7 +736,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
42859
42860 static int xpad_led_probe(struct usb_xpad *xpad)
42861 {
42862- static atomic_t led_seq = ATOMIC_INIT(0);
42863+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
42864 long led_no;
42865 struct xpad_led *led;
42866 struct led_classdev *led_cdev;
42867@@ -749,7 +749,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
42868 if (!led)
42869 return -ENOMEM;
42870
42871- led_no = (long)atomic_inc_return(&led_seq) - 1;
42872+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
42873
42874 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
42875 led->xpad = xpad;
42876diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
42877index e204f26..8459f15 100644
42878--- a/drivers/input/misc/ims-pcu.c
42879+++ b/drivers/input/misc/ims-pcu.c
42880@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
42881
42882 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42883 {
42884- static atomic_t device_no = ATOMIC_INIT(0);
42885+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
42886
42887 const struct ims_pcu_device_info *info;
42888 u8 device_id;
42889@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42890 }
42891
42892 /* Device appears to be operable, complete initialization */
42893- pcu->device_no = atomic_inc_return(&device_no) - 1;
42894+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
42895
42896 error = ims_pcu_setup_backlight(pcu);
42897 if (error)
42898diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
42899index 2f0b39d..7370f13 100644
42900--- a/drivers/input/mouse/psmouse.h
42901+++ b/drivers/input/mouse/psmouse.h
42902@@ -116,7 +116,7 @@ struct psmouse_attribute {
42903 ssize_t (*set)(struct psmouse *psmouse, void *data,
42904 const char *buf, size_t count);
42905 bool protect;
42906-};
42907+} __do_const;
42908 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
42909
42910 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
42911diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
42912index b604564..3f14ae4 100644
42913--- a/drivers/input/mousedev.c
42914+++ b/drivers/input/mousedev.c
42915@@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
42916
42917 spin_unlock_irq(&client->packet_lock);
42918
42919- if (copy_to_user(buffer, data, count))
42920+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
42921 return -EFAULT;
42922
42923 return count;
42924diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
42925index 8f4c4ab..5fc8a45 100644
42926--- a/drivers/input/serio/serio.c
42927+++ b/drivers/input/serio/serio.c
42928@@ -505,7 +505,7 @@ static void serio_release_port(struct device *dev)
42929 */
42930 static void serio_init_port(struct serio *serio)
42931 {
42932- static atomic_t serio_no = ATOMIC_INIT(0);
42933+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
42934
42935 __module_get(THIS_MODULE);
42936
42937@@ -516,7 +516,7 @@ static void serio_init_port(struct serio *serio)
42938 mutex_init(&serio->drv_mutex);
42939 device_initialize(&serio->dev);
42940 dev_set_name(&serio->dev, "serio%ld",
42941- (long)atomic_inc_return(&serio_no) - 1);
42942+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
42943 serio->dev.bus = &serio_bus;
42944 serio->dev.release = serio_release_port;
42945 serio->dev.groups = serio_device_attr_groups;
42946diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
42947index 59df2e7..8f1cafb 100644
42948--- a/drivers/input/serio/serio_raw.c
42949+++ b/drivers/input/serio/serio_raw.c
42950@@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
42951
42952 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42953 {
42954- static atomic_t serio_raw_no = ATOMIC_INIT(0);
42955+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
42956 struct serio_raw *serio_raw;
42957 int err;
42958
42959@@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42960 }
42961
42962 snprintf(serio_raw->name, sizeof(serio_raw->name),
42963- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
42964+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
42965 kref_init(&serio_raw->kref);
42966 INIT_LIST_HEAD(&serio_raw->client_list);
42967 init_waitqueue_head(&serio_raw->wait);
42968diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
42969index e5555fc..937986d 100644
42970--- a/drivers/iommu/iommu.c
42971+++ b/drivers/iommu/iommu.c
42972@@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
42973 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
42974 {
42975 bus_register_notifier(bus, &iommu_bus_nb);
42976- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
42977+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
42978 }
42979
42980 /**
42981diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
42982index 39f81ae..2660096 100644
42983--- a/drivers/iommu/irq_remapping.c
42984+++ b/drivers/iommu/irq_remapping.c
42985@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
42986 void panic_if_irq_remap(const char *msg)
42987 {
42988 if (irq_remapping_enabled)
42989- panic(msg);
42990+ panic("%s", msg);
42991 }
42992
42993 static void ir_ack_apic_edge(struct irq_data *data)
42994@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
42995
42996 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
42997 {
42998- chip->irq_print_chip = ir_print_prefix;
42999- chip->irq_ack = ir_ack_apic_edge;
43000- chip->irq_eoi = ir_ack_apic_level;
43001- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43002+ pax_open_kernel();
43003+ *(void **)&chip->irq_print_chip = ir_print_prefix;
43004+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
43005+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
43006+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43007+ pax_close_kernel();
43008 }
43009
43010 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43011diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43012index 341c601..e5f407e 100644
43013--- a/drivers/irqchip/irq-gic.c
43014+++ b/drivers/irqchip/irq-gic.c
43015@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43016 * Supported arch specific GIC irq extension.
43017 * Default make them NULL.
43018 */
43019-struct irq_chip gic_arch_extn = {
43020+irq_chip_no_const gic_arch_extn = {
43021 .irq_eoi = NULL,
43022 .irq_mask = NULL,
43023 .irq_unmask = NULL,
43024@@ -332,7 +332,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43025 chained_irq_exit(chip, desc);
43026 }
43027
43028-static struct irq_chip gic_chip = {
43029+static irq_chip_no_const gic_chip __read_only = {
43030 .name = "GIC",
43031 .irq_mask = gic_mask_irq,
43032 .irq_unmask = gic_unmask_irq,
43033diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43034index ac6f72b..81150f2 100644
43035--- a/drivers/isdn/capi/capi.c
43036+++ b/drivers/isdn/capi/capi.c
43037@@ -81,8 +81,8 @@ struct capiminor {
43038
43039 struct capi20_appl *ap;
43040 u32 ncci;
43041- atomic_t datahandle;
43042- atomic_t msgid;
43043+ atomic_unchecked_t datahandle;
43044+ atomic_unchecked_t msgid;
43045
43046 struct tty_port port;
43047 int ttyinstop;
43048@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43049 capimsg_setu16(s, 2, mp->ap->applid);
43050 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43051 capimsg_setu8 (s, 5, CAPI_RESP);
43052- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43053+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43054 capimsg_setu32(s, 8, mp->ncci);
43055 capimsg_setu16(s, 12, datahandle);
43056 }
43057@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43058 mp->outbytes -= len;
43059 spin_unlock_bh(&mp->outlock);
43060
43061- datahandle = atomic_inc_return(&mp->datahandle);
43062+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43063 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43064 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43065 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43066 capimsg_setu16(skb->data, 2, mp->ap->applid);
43067 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43068 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43069- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43070+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43071 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43072 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43073 capimsg_setu16(skb->data, 16, len); /* Data length */
43074diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43075index c44950d..10ac276 100644
43076--- a/drivers/isdn/gigaset/bas-gigaset.c
43077+++ b/drivers/isdn/gigaset/bas-gigaset.c
43078@@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43079
43080
43081 static const struct gigaset_ops gigops = {
43082- gigaset_write_cmd,
43083- gigaset_write_room,
43084- gigaset_chars_in_buffer,
43085- gigaset_brkchars,
43086- gigaset_init_bchannel,
43087- gigaset_close_bchannel,
43088- gigaset_initbcshw,
43089- gigaset_freebcshw,
43090- gigaset_reinitbcshw,
43091- gigaset_initcshw,
43092- gigaset_freecshw,
43093- gigaset_set_modem_ctrl,
43094- gigaset_baud_rate,
43095- gigaset_set_line_ctrl,
43096- gigaset_isoc_send_skb,
43097- gigaset_isoc_input,
43098+ .write_cmd = gigaset_write_cmd,
43099+ .write_room = gigaset_write_room,
43100+ .chars_in_buffer = gigaset_chars_in_buffer,
43101+ .brkchars = gigaset_brkchars,
43102+ .init_bchannel = gigaset_init_bchannel,
43103+ .close_bchannel = gigaset_close_bchannel,
43104+ .initbcshw = gigaset_initbcshw,
43105+ .freebcshw = gigaset_freebcshw,
43106+ .reinitbcshw = gigaset_reinitbcshw,
43107+ .initcshw = gigaset_initcshw,
43108+ .freecshw = gigaset_freecshw,
43109+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43110+ .baud_rate = gigaset_baud_rate,
43111+ .set_line_ctrl = gigaset_set_line_ctrl,
43112+ .send_skb = gigaset_isoc_send_skb,
43113+ .handle_input = gigaset_isoc_input,
43114 };
43115
43116 /* bas_gigaset_init
43117diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43118index 600c79b..3752bab 100644
43119--- a/drivers/isdn/gigaset/interface.c
43120+++ b/drivers/isdn/gigaset/interface.c
43121@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43122 }
43123 tty->driver_data = cs;
43124
43125- ++cs->port.count;
43126+ atomic_inc(&cs->port.count);
43127
43128- if (cs->port.count == 1) {
43129+ if (atomic_read(&cs->port.count) == 1) {
43130 tty_port_tty_set(&cs->port, tty);
43131 cs->port.low_latency = 1;
43132 }
43133@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43134
43135 if (!cs->connected)
43136 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43137- else if (!cs->port.count)
43138+ else if (!atomic_read(&cs->port.count))
43139 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43140- else if (!--cs->port.count)
43141+ else if (!atomic_dec_return(&cs->port.count))
43142 tty_port_tty_set(&cs->port, NULL);
43143
43144 mutex_unlock(&cs->mutex);
43145diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43146index 8c91fd5..14f13ce 100644
43147--- a/drivers/isdn/gigaset/ser-gigaset.c
43148+++ b/drivers/isdn/gigaset/ser-gigaset.c
43149@@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43150 }
43151
43152 static const struct gigaset_ops ops = {
43153- gigaset_write_cmd,
43154- gigaset_write_room,
43155- gigaset_chars_in_buffer,
43156- gigaset_brkchars,
43157- gigaset_init_bchannel,
43158- gigaset_close_bchannel,
43159- gigaset_initbcshw,
43160- gigaset_freebcshw,
43161- gigaset_reinitbcshw,
43162- gigaset_initcshw,
43163- gigaset_freecshw,
43164- gigaset_set_modem_ctrl,
43165- gigaset_baud_rate,
43166- gigaset_set_line_ctrl,
43167- gigaset_m10x_send_skb, /* asyncdata.c */
43168- gigaset_m10x_input, /* asyncdata.c */
43169+ .write_cmd = gigaset_write_cmd,
43170+ .write_room = gigaset_write_room,
43171+ .chars_in_buffer = gigaset_chars_in_buffer,
43172+ .brkchars = gigaset_brkchars,
43173+ .init_bchannel = gigaset_init_bchannel,
43174+ .close_bchannel = gigaset_close_bchannel,
43175+ .initbcshw = gigaset_initbcshw,
43176+ .freebcshw = gigaset_freebcshw,
43177+ .reinitbcshw = gigaset_reinitbcshw,
43178+ .initcshw = gigaset_initcshw,
43179+ .freecshw = gigaset_freecshw,
43180+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43181+ .baud_rate = gigaset_baud_rate,
43182+ .set_line_ctrl = gigaset_set_line_ctrl,
43183+ .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43184+ .handle_input = gigaset_m10x_input, /* asyncdata.c */
43185 };
43186
43187
43188diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43189index d0a41cb..b953e50 100644
43190--- a/drivers/isdn/gigaset/usb-gigaset.c
43191+++ b/drivers/isdn/gigaset/usb-gigaset.c
43192@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43193 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43194 memcpy(cs->hw.usb->bchars, buf, 6);
43195 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43196- 0, 0, &buf, 6, 2000);
43197+ 0, 0, buf, 6, 2000);
43198 }
43199
43200 static void gigaset_freebcshw(struct bc_state *bcs)
43201@@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43202 }
43203
43204 static const struct gigaset_ops ops = {
43205- gigaset_write_cmd,
43206- gigaset_write_room,
43207- gigaset_chars_in_buffer,
43208- gigaset_brkchars,
43209- gigaset_init_bchannel,
43210- gigaset_close_bchannel,
43211- gigaset_initbcshw,
43212- gigaset_freebcshw,
43213- gigaset_reinitbcshw,
43214- gigaset_initcshw,
43215- gigaset_freecshw,
43216- gigaset_set_modem_ctrl,
43217- gigaset_baud_rate,
43218- gigaset_set_line_ctrl,
43219- gigaset_m10x_send_skb,
43220- gigaset_m10x_input,
43221+ .write_cmd = gigaset_write_cmd,
43222+ .write_room = gigaset_write_room,
43223+ .chars_in_buffer = gigaset_chars_in_buffer,
43224+ .brkchars = gigaset_brkchars,
43225+ .init_bchannel = gigaset_init_bchannel,
43226+ .close_bchannel = gigaset_close_bchannel,
43227+ .initbcshw = gigaset_initbcshw,
43228+ .freebcshw = gigaset_freebcshw,
43229+ .reinitbcshw = gigaset_reinitbcshw,
43230+ .initcshw = gigaset_initcshw,
43231+ .freecshw = gigaset_freecshw,
43232+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43233+ .baud_rate = gigaset_baud_rate,
43234+ .set_line_ctrl = gigaset_set_line_ctrl,
43235+ .send_skb = gigaset_m10x_send_skb,
43236+ .handle_input = gigaset_m10x_input,
43237 };
43238
43239 /*
43240diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43241index 4d9b195..455075c 100644
43242--- a/drivers/isdn/hardware/avm/b1.c
43243+++ b/drivers/isdn/hardware/avm/b1.c
43244@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43245 }
43246 if (left) {
43247 if (t4file->user) {
43248- if (copy_from_user(buf, dp, left))
43249+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43250 return -EFAULT;
43251 } else {
43252 memcpy(buf, dp, left);
43253@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43254 }
43255 if (left) {
43256 if (config->user) {
43257- if (copy_from_user(buf, dp, left))
43258+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43259 return -EFAULT;
43260 } else {
43261 memcpy(buf, dp, left);
43262diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43263index 9bb12ba..d4262f7 100644
43264--- a/drivers/isdn/i4l/isdn_common.c
43265+++ b/drivers/isdn/i4l/isdn_common.c
43266@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43267 } else
43268 return -EINVAL;
43269 case IIOCDBGVAR:
43270+ if (!capable(CAP_SYS_RAWIO))
43271+ return -EPERM;
43272 if (arg) {
43273 if (copy_to_user(argp, &dev, sizeof(ulong)))
43274 return -EFAULT;
43275diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43276index 91d5730..336523e 100644
43277--- a/drivers/isdn/i4l/isdn_concap.c
43278+++ b/drivers/isdn/i4l/isdn_concap.c
43279@@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43280 }
43281
43282 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43283- &isdn_concap_dl_data_req,
43284- &isdn_concap_dl_connect_req,
43285- &isdn_concap_dl_disconn_req
43286+ .data_req = &isdn_concap_dl_data_req,
43287+ .connect_req = &isdn_concap_dl_connect_req,
43288+ .disconn_req = &isdn_concap_dl_disconn_req
43289 };
43290
43291 /* The following should better go into a dedicated source file such that
43292diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43293index 3c5f249..5fac4d0 100644
43294--- a/drivers/isdn/i4l/isdn_tty.c
43295+++ b/drivers/isdn/i4l/isdn_tty.c
43296@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43297
43298 #ifdef ISDN_DEBUG_MODEM_OPEN
43299 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43300- port->count);
43301+ atomic_read(&port->count));
43302 #endif
43303- port->count++;
43304+ atomic_inc(&port->count);
43305 port->tty = tty;
43306 /*
43307 * Start up serial port
43308@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43309 #endif
43310 return;
43311 }
43312- if ((tty->count == 1) && (port->count != 1)) {
43313+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43314 /*
43315 * Uh, oh. tty->count is 1, which means that the tty
43316 * structure will be freed. Info->count should always
43317@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43318 * serial port won't be shutdown.
43319 */
43320 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43321- "info->count is %d\n", port->count);
43322- port->count = 1;
43323+ "info->count is %d\n", atomic_read(&port->count));
43324+ atomic_set(&port->count, 1);
43325 }
43326- if (--port->count < 0) {
43327+ if (atomic_dec_return(&port->count) < 0) {
43328 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43329- info->line, port->count);
43330- port->count = 0;
43331+ info->line, atomic_read(&port->count));
43332+ atomic_set(&port->count, 0);
43333 }
43334- if (port->count) {
43335+ if (atomic_read(&port->count)) {
43336 #ifdef ISDN_DEBUG_MODEM_OPEN
43337 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43338 #endif
43339@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43340 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43341 return;
43342 isdn_tty_shutdown(info);
43343- port->count = 0;
43344+ atomic_set(&port->count, 0);
43345 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43346 port->tty = NULL;
43347 wake_up_interruptible(&port->open_wait);
43348@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43349 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43350 modem_info *info = &dev->mdm.info[i];
43351
43352- if (info->port.count == 0)
43353+ if (atomic_read(&info->port.count) == 0)
43354 continue;
43355 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43356 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43357diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43358index e2d4e58..40cd045 100644
43359--- a/drivers/isdn/i4l/isdn_x25iface.c
43360+++ b/drivers/isdn/i4l/isdn_x25iface.c
43361@@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43362
43363
43364 static struct concap_proto_ops ix25_pops = {
43365- &isdn_x25iface_proto_new,
43366- &isdn_x25iface_proto_del,
43367- &isdn_x25iface_proto_restart,
43368- &isdn_x25iface_proto_close,
43369- &isdn_x25iface_xmit,
43370- &isdn_x25iface_receive,
43371- &isdn_x25iface_connect_ind,
43372- &isdn_x25iface_disconn_ind
43373+ .proto_new = &isdn_x25iface_proto_new,
43374+ .proto_del = &isdn_x25iface_proto_del,
43375+ .restart = &isdn_x25iface_proto_restart,
43376+ .close = &isdn_x25iface_proto_close,
43377+ .encap_and_xmit = &isdn_x25iface_xmit,
43378+ .data_ind = &isdn_x25iface_receive,
43379+ .connect_ind = &isdn_x25iface_connect_ind,
43380+ .disconn_ind = &isdn_x25iface_disconn_ind
43381 };
43382
43383 /* error message helper function */
43384diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43385index 53d487f..f020f41 100644
43386--- a/drivers/isdn/icn/icn.c
43387+++ b/drivers/isdn/icn/icn.c
43388@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43389 if (count > len)
43390 count = len;
43391 if (user) {
43392- if (copy_from_user(msg, buf, count))
43393+ if (count > sizeof msg || copy_from_user(msg, buf, count))
43394 return -EFAULT;
43395 } else
43396 memcpy(msg, buf, count);
43397diff --git a/drivers/isdn/isdnloop/isdnloop.c b/drivers/isdn/isdnloop/isdnloop.c
43398index 02125e6..e1f8748 100644
43399--- a/drivers/isdn/isdnloop/isdnloop.c
43400+++ b/drivers/isdn/isdnloop/isdnloop.c
43401@@ -1070,6 +1070,12 @@ isdnloop_start(isdnloop_card *card, isdnloop_sdef *sdefp)
43402 return -EBUSY;
43403 if (copy_from_user((char *) &sdef, (char *) sdefp, sizeof(sdef)))
43404 return -EFAULT;
43405+
43406+ for (i = 0; i < 3; i++) {
43407+ if (!memchr(sdef.num[i], 0, sizeof(sdef.num[i])))
43408+ return -EINVAL;
43409+ }
43410+
43411 spin_lock_irqsave(&card->isdnloop_lock, flags);
43412 switch (sdef.ptype) {
43413 case ISDN_PTYPE_EURO:
43414diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43415index a4f05c5..1433bc5 100644
43416--- a/drivers/isdn/mISDN/dsp_cmx.c
43417+++ b/drivers/isdn/mISDN/dsp_cmx.c
43418@@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43419 static u16 dsp_count; /* last sample count */
43420 static int dsp_count_valid; /* if we have last sample count */
43421
43422-void
43423+void __intentional_overflow(-1)
43424 dsp_cmx_send(void *arg)
43425 {
43426 struct dsp_conf *conf;
43427diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43428index d93e245..e7ece6b 100644
43429--- a/drivers/leds/leds-clevo-mail.c
43430+++ b/drivers/leds/leds-clevo-mail.c
43431@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43432 * detected as working, but in reality it is not) as low as
43433 * possible.
43434 */
43435-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43436+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43437 {
43438 .callback = clevo_mail_led_dmi_callback,
43439 .ident = "Clevo D410J",
43440diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43441index 5b8f938..b73d657 100644
43442--- a/drivers/leds/leds-ss4200.c
43443+++ b/drivers/leds/leds-ss4200.c
43444@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43445 * detected as working, but in reality it is not) as low as
43446 * possible.
43447 */
43448-static struct dmi_system_id nas_led_whitelist[] __initdata = {
43449+static struct dmi_system_id nas_led_whitelist[] __initconst = {
43450 {
43451 .callback = ss4200_led_dmi_callback,
43452 .ident = "Intel SS4200-E",
43453diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
43454index 0bf1e4e..b4bf44e 100644
43455--- a/drivers/lguest/core.c
43456+++ b/drivers/lguest/core.c
43457@@ -97,9 +97,17 @@ static __init int map_switcher(void)
43458 * The end address needs +1 because __get_vm_area allocates an
43459 * extra guard page, so we need space for that.
43460 */
43461+
43462+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
43463+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43464+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
43465+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43466+#else
43467 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43468 VM_ALLOC, switcher_addr, switcher_addr
43469 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43470+#endif
43471+
43472 if (!switcher_vma) {
43473 err = -ENOMEM;
43474 printk("lguest: could not map switcher pages high\n");
43475@@ -124,7 +132,7 @@ static __init int map_switcher(void)
43476 * Now the Switcher is mapped at the right address, we can't fail!
43477 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
43478 */
43479- memcpy(switcher_vma->addr, start_switcher_text,
43480+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
43481 end_switcher_text - start_switcher_text);
43482
43483 printk(KERN_INFO "lguest: mapped switcher at %p\n",
43484diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
43485index bfb39bb..08a603b 100644
43486--- a/drivers/lguest/page_tables.c
43487+++ b/drivers/lguest/page_tables.c
43488@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
43489 /*:*/
43490
43491 #ifdef CONFIG_X86_PAE
43492-static void release_pmd(pmd_t *spmd)
43493+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
43494 {
43495 /* If the entry's not present, there's nothing to release. */
43496 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
43497diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
43498index 922a1ac..9dd0c2a 100644
43499--- a/drivers/lguest/x86/core.c
43500+++ b/drivers/lguest/x86/core.c
43501@@ -59,7 +59,7 @@ static struct {
43502 /* Offset from where switcher.S was compiled to where we've copied it */
43503 static unsigned long switcher_offset(void)
43504 {
43505- return switcher_addr - (unsigned long)start_switcher_text;
43506+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
43507 }
43508
43509 /* This cpu's struct lguest_pages (after the Switcher text page) */
43510@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
43511 * These copies are pretty cheap, so we do them unconditionally: */
43512 /* Save the current Host top-level page directory.
43513 */
43514+
43515+#ifdef CONFIG_PAX_PER_CPU_PGD
43516+ pages->state.host_cr3 = read_cr3();
43517+#else
43518 pages->state.host_cr3 = __pa(current->mm->pgd);
43519+#endif
43520+
43521 /*
43522 * Set up the Guest's page tables to see this CPU's pages (and no
43523 * other CPU's pages).
43524@@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
43525 * compiled-in switcher code and the high-mapped copy we just made.
43526 */
43527 for (i = 0; i < IDT_ENTRIES; i++)
43528- default_idt_entries[i] += switcher_offset();
43529+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
43530
43531 /*
43532 * Set up the Switcher's per-cpu areas.
43533@@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
43534 * it will be undisturbed when we switch. To change %cs and jump we
43535 * need this structure to feed to Intel's "lcall" instruction.
43536 */
43537- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
43538+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
43539 lguest_entry.segment = LGUEST_CS;
43540
43541 /*
43542diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
43543index 40634b0..4f5855e 100644
43544--- a/drivers/lguest/x86/switcher_32.S
43545+++ b/drivers/lguest/x86/switcher_32.S
43546@@ -87,6 +87,7 @@
43547 #include <asm/page.h>
43548 #include <asm/segment.h>
43549 #include <asm/lguest.h>
43550+#include <asm/processor-flags.h>
43551
43552 // We mark the start of the code to copy
43553 // It's placed in .text tho it's never run here
43554@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
43555 // Changes type when we load it: damn Intel!
43556 // For after we switch over our page tables
43557 // That entry will be read-only: we'd crash.
43558+
43559+#ifdef CONFIG_PAX_KERNEXEC
43560+ mov %cr0, %edx
43561+ xor $X86_CR0_WP, %edx
43562+ mov %edx, %cr0
43563+#endif
43564+
43565 movl $(GDT_ENTRY_TSS*8), %edx
43566 ltr %dx
43567
43568@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
43569 // Let's clear it again for our return.
43570 // The GDT descriptor of the Host
43571 // Points to the table after two "size" bytes
43572- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
43573+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
43574 // Clear "used" from type field (byte 5, bit 2)
43575- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
43576+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
43577+
43578+#ifdef CONFIG_PAX_KERNEXEC
43579+ mov %cr0, %eax
43580+ xor $X86_CR0_WP, %eax
43581+ mov %eax, %cr0
43582+#endif
43583
43584 // Once our page table's switched, the Guest is live!
43585 // The Host fades as we run this final step.
43586@@ -295,13 +309,12 @@ deliver_to_host:
43587 // I consulted gcc, and it gave
43588 // These instructions, which I gladly credit:
43589 leal (%edx,%ebx,8), %eax
43590- movzwl (%eax),%edx
43591- movl 4(%eax), %eax
43592- xorw %ax, %ax
43593- orl %eax, %edx
43594+ movl 4(%eax), %edx
43595+ movw (%eax), %dx
43596 // Now the address of the handler's in %edx
43597 // We call it now: its "iret" drops us home.
43598- jmp *%edx
43599+ ljmp $__KERNEL_CS, $1f
43600+1: jmp *%edx
43601
43602 // Every interrupt can come to us here
43603 // But we must truly tell each apart.
43604diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
43605index 9762f1b..3e79734 100644
43606--- a/drivers/md/bcache/closure.h
43607+++ b/drivers/md/bcache/closure.h
43608@@ -483,7 +483,7 @@ static inline void closure_queue(struct closure *cl)
43609 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
43610 struct workqueue_struct *wq)
43611 {
43612- BUG_ON(object_is_on_stack(cl));
43613+ BUG_ON(object_starts_on_stack(cl));
43614 closure_set_ip(cl);
43615 cl->fn = fn;
43616 cl->wq = wq;
43617diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
43618index 12dc29b..1596277 100644
43619--- a/drivers/md/bitmap.c
43620+++ b/drivers/md/bitmap.c
43621@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
43622 chunk_kb ? "KB" : "B");
43623 if (bitmap->storage.file) {
43624 seq_printf(seq, ", file: ");
43625- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
43626+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
43627 }
43628
43629 seq_printf(seq, "\n");
43630diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
43631index 5152142..623d141 100644
43632--- a/drivers/md/dm-ioctl.c
43633+++ b/drivers/md/dm-ioctl.c
43634@@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
43635 cmd == DM_LIST_VERSIONS_CMD)
43636 return 0;
43637
43638- if ((cmd == DM_DEV_CREATE_CMD)) {
43639+ if (cmd == DM_DEV_CREATE_CMD) {
43640 if (!*param->name) {
43641 DMWARN("name not supplied when creating device");
43642 return -EINVAL;
43643diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
43644index 9584443..9fc9ac9 100644
43645--- a/drivers/md/dm-raid1.c
43646+++ b/drivers/md/dm-raid1.c
43647@@ -40,7 +40,7 @@ enum dm_raid1_error {
43648
43649 struct mirror {
43650 struct mirror_set *ms;
43651- atomic_t error_count;
43652+ atomic_unchecked_t error_count;
43653 unsigned long error_type;
43654 struct dm_dev *dev;
43655 sector_t offset;
43656@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
43657 struct mirror *m;
43658
43659 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
43660- if (!atomic_read(&m->error_count))
43661+ if (!atomic_read_unchecked(&m->error_count))
43662 return m;
43663
43664 return NULL;
43665@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
43666 * simple way to tell if a device has encountered
43667 * errors.
43668 */
43669- atomic_inc(&m->error_count);
43670+ atomic_inc_unchecked(&m->error_count);
43671
43672 if (test_and_set_bit(error_type, &m->error_type))
43673 return;
43674@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
43675 struct mirror *m = get_default_mirror(ms);
43676
43677 do {
43678- if (likely(!atomic_read(&m->error_count)))
43679+ if (likely(!atomic_read_unchecked(&m->error_count)))
43680 return m;
43681
43682 if (m-- == ms->mirror)
43683@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
43684 {
43685 struct mirror *default_mirror = get_default_mirror(m->ms);
43686
43687- return !atomic_read(&default_mirror->error_count);
43688+ return !atomic_read_unchecked(&default_mirror->error_count);
43689 }
43690
43691 static int mirror_available(struct mirror_set *ms, struct bio *bio)
43692@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
43693 */
43694 if (likely(region_in_sync(ms, region, 1)))
43695 m = choose_mirror(ms, bio->bi_sector);
43696- else if (m && atomic_read(&m->error_count))
43697+ else if (m && atomic_read_unchecked(&m->error_count))
43698 m = NULL;
43699
43700 if (likely(m))
43701@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
43702 }
43703
43704 ms->mirror[mirror].ms = ms;
43705- atomic_set(&(ms->mirror[mirror].error_count), 0);
43706+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
43707 ms->mirror[mirror].error_type = 0;
43708 ms->mirror[mirror].offset = offset;
43709
43710@@ -1339,7 +1339,7 @@ static void mirror_resume(struct dm_target *ti)
43711 */
43712 static char device_status_char(struct mirror *m)
43713 {
43714- if (!atomic_read(&(m->error_count)))
43715+ if (!atomic_read_unchecked(&(m->error_count)))
43716 return 'A';
43717
43718 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43719diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43720index 28a9012..9c0f6a5 100644
43721--- a/drivers/md/dm-stats.c
43722+++ b/drivers/md/dm-stats.c
43723@@ -382,7 +382,7 @@ do_sync_free:
43724 synchronize_rcu_expedited();
43725 dm_stat_free(&s->rcu_head);
43726 } else {
43727- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43728+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43729 call_rcu(&s->rcu_head, dm_stat_free);
43730 }
43731 return 0;
43732@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43733 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43734 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43735 ));
43736- ACCESS_ONCE(last->last_sector) = end_sector;
43737- ACCESS_ONCE(last->last_rw) = bi_rw;
43738+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
43739+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43740 }
43741
43742 rcu_read_lock();
43743diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43744index 73c1712..7347292 100644
43745--- a/drivers/md/dm-stripe.c
43746+++ b/drivers/md/dm-stripe.c
43747@@ -21,7 +21,7 @@ struct stripe {
43748 struct dm_dev *dev;
43749 sector_t physical_start;
43750
43751- atomic_t error_count;
43752+ atomic_unchecked_t error_count;
43753 };
43754
43755 struct stripe_c {
43756@@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43757 kfree(sc);
43758 return r;
43759 }
43760- atomic_set(&(sc->stripe[i].error_count), 0);
43761+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43762 }
43763
43764 ti->private = sc;
43765@@ -327,7 +327,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43766 DMEMIT("%d ", sc->stripes);
43767 for (i = 0; i < sc->stripes; i++) {
43768 DMEMIT("%s ", sc->stripe[i].dev->name);
43769- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43770+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43771 'D' : 'A';
43772 }
43773 buffer[i] = '\0';
43774@@ -372,8 +372,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43775 */
43776 for (i = 0; i < sc->stripes; i++)
43777 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43778- atomic_inc(&(sc->stripe[i].error_count));
43779- if (atomic_read(&(sc->stripe[i].error_count)) <
43780+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
43781+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43782 DM_IO_ERROR_THRESHOLD)
43783 schedule_work(&sc->trigger_event);
43784 }
43785diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43786index 3ba6a38..b0fa9b0 100644
43787--- a/drivers/md/dm-table.c
43788+++ b/drivers/md/dm-table.c
43789@@ -291,7 +291,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43790 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43791 struct mapped_device *md)
43792 {
43793- static char *_claim_ptr = "I belong to device-mapper";
43794+ static char _claim_ptr[] = "I belong to device-mapper";
43795 struct block_device *bdev;
43796
43797 int r;
43798@@ -359,7 +359,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43799 if (!dev_size)
43800 return 0;
43801
43802- if ((start >= dev_size) || (start + len > dev_size)) {
43803+ if ((start >= dev_size) || (len > dev_size - start)) {
43804 DMWARN("%s: %s too small for target: "
43805 "start=%llu, len=%llu, dev_size=%llu",
43806 dm_device_name(ti->table->md), bdevname(bdev, b),
43807diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
43808index 3bb4506..56e20cc 100644
43809--- a/drivers/md/dm-thin-metadata.c
43810+++ b/drivers/md/dm-thin-metadata.c
43811@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43812 {
43813 pmd->info.tm = pmd->tm;
43814 pmd->info.levels = 2;
43815- pmd->info.value_type.context = pmd->data_sm;
43816+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43817 pmd->info.value_type.size = sizeof(__le64);
43818 pmd->info.value_type.inc = data_block_inc;
43819 pmd->info.value_type.dec = data_block_dec;
43820@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43821
43822 pmd->bl_info.tm = pmd->tm;
43823 pmd->bl_info.levels = 1;
43824- pmd->bl_info.value_type.context = pmd->data_sm;
43825+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43826 pmd->bl_info.value_type.size = sizeof(__le64);
43827 pmd->bl_info.value_type.inc = data_block_inc;
43828 pmd->bl_info.value_type.dec = data_block_dec;
43829diff --git a/drivers/md/dm.c b/drivers/md/dm.c
43830index b49c762..c9503cf 100644
43831--- a/drivers/md/dm.c
43832+++ b/drivers/md/dm.c
43833@@ -185,9 +185,9 @@ struct mapped_device {
43834 /*
43835 * Event handling.
43836 */
43837- atomic_t event_nr;
43838+ atomic_unchecked_t event_nr;
43839 wait_queue_head_t eventq;
43840- atomic_t uevent_seq;
43841+ atomic_unchecked_t uevent_seq;
43842 struct list_head uevent_list;
43843 spinlock_t uevent_lock; /* Protect access to uevent_list */
43844
43845@@ -2021,8 +2021,8 @@ static struct mapped_device *alloc_dev(int minor)
43846 spin_lock_init(&md->deferred_lock);
43847 atomic_set(&md->holders, 1);
43848 atomic_set(&md->open_count, 0);
43849- atomic_set(&md->event_nr, 0);
43850- atomic_set(&md->uevent_seq, 0);
43851+ atomic_set_unchecked(&md->event_nr, 0);
43852+ atomic_set_unchecked(&md->uevent_seq, 0);
43853 INIT_LIST_HEAD(&md->uevent_list);
43854 spin_lock_init(&md->uevent_lock);
43855
43856@@ -2176,7 +2176,7 @@ static void event_callback(void *context)
43857
43858 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
43859
43860- atomic_inc(&md->event_nr);
43861+ atomic_inc_unchecked(&md->event_nr);
43862 wake_up(&md->eventq);
43863 }
43864
43865@@ -2869,18 +2869,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
43866
43867 uint32_t dm_next_uevent_seq(struct mapped_device *md)
43868 {
43869- return atomic_add_return(1, &md->uevent_seq);
43870+ return atomic_add_return_unchecked(1, &md->uevent_seq);
43871 }
43872
43873 uint32_t dm_get_event_nr(struct mapped_device *md)
43874 {
43875- return atomic_read(&md->event_nr);
43876+ return atomic_read_unchecked(&md->event_nr);
43877 }
43878
43879 int dm_wait_event(struct mapped_device *md, int event_nr)
43880 {
43881 return wait_event_interruptible(md->eventq,
43882- (event_nr != atomic_read(&md->event_nr)));
43883+ (event_nr != atomic_read_unchecked(&md->event_nr)));
43884 }
43885
43886 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
43887diff --git a/drivers/md/md.c b/drivers/md/md.c
43888index 369d919..ba7049c 100644
43889--- a/drivers/md/md.c
43890+++ b/drivers/md/md.c
43891@@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
43892 * start build, activate spare
43893 */
43894 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
43895-static atomic_t md_event_count;
43896+static atomic_unchecked_t md_event_count;
43897 void md_new_event(struct mddev *mddev)
43898 {
43899- atomic_inc(&md_event_count);
43900+ atomic_inc_unchecked(&md_event_count);
43901 wake_up(&md_event_waiters);
43902 }
43903 EXPORT_SYMBOL_GPL(md_new_event);
43904@@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
43905 */
43906 static void md_new_event_inintr(struct mddev *mddev)
43907 {
43908- atomic_inc(&md_event_count);
43909+ atomic_inc_unchecked(&md_event_count);
43910 wake_up(&md_event_waiters);
43911 }
43912
43913@@ -1463,7 +1463,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
43914 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
43915 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
43916 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
43917- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43918+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43919
43920 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
43921 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
43922@@ -1710,7 +1710,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
43923 else
43924 sb->resync_offset = cpu_to_le64(0);
43925
43926- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
43927+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
43928
43929 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
43930 sb->size = cpu_to_le64(mddev->dev_sectors);
43931@@ -2715,7 +2715,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
43932 static ssize_t
43933 errors_show(struct md_rdev *rdev, char *page)
43934 {
43935- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
43936+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
43937 }
43938
43939 static ssize_t
43940@@ -2724,7 +2724,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
43941 char *e;
43942 unsigned long n = simple_strtoul(buf, &e, 10);
43943 if (*buf && (*e == 0 || *e == '\n')) {
43944- atomic_set(&rdev->corrected_errors, n);
43945+ atomic_set_unchecked(&rdev->corrected_errors, n);
43946 return len;
43947 }
43948 return -EINVAL;
43949@@ -3173,8 +3173,8 @@ int md_rdev_init(struct md_rdev *rdev)
43950 rdev->sb_loaded = 0;
43951 rdev->bb_page = NULL;
43952 atomic_set(&rdev->nr_pending, 0);
43953- atomic_set(&rdev->read_errors, 0);
43954- atomic_set(&rdev->corrected_errors, 0);
43955+ atomic_set_unchecked(&rdev->read_errors, 0);
43956+ atomic_set_unchecked(&rdev->corrected_errors, 0);
43957
43958 INIT_LIST_HEAD(&rdev->same_set);
43959 init_waitqueue_head(&rdev->blocked_wait);
43960@@ -7038,7 +7038,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
43961
43962 spin_unlock(&pers_lock);
43963 seq_printf(seq, "\n");
43964- seq->poll_event = atomic_read(&md_event_count);
43965+ seq->poll_event = atomic_read_unchecked(&md_event_count);
43966 return 0;
43967 }
43968 if (v == (void*)2) {
43969@@ -7141,7 +7141,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
43970 return error;
43971
43972 seq = file->private_data;
43973- seq->poll_event = atomic_read(&md_event_count);
43974+ seq->poll_event = atomic_read_unchecked(&md_event_count);
43975 return error;
43976 }
43977
43978@@ -7155,7 +7155,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
43979 /* always allow read */
43980 mask = POLLIN | POLLRDNORM;
43981
43982- if (seq->poll_event != atomic_read(&md_event_count))
43983+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
43984 mask |= POLLERR | POLLPRI;
43985 return mask;
43986 }
43987@@ -7199,7 +7199,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
43988 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
43989 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
43990 (int)part_stat_read(&disk->part0, sectors[1]) -
43991- atomic_read(&disk->sync_io);
43992+ atomic_read_unchecked(&disk->sync_io);
43993 /* sync IO will cause sync_io to increase before the disk_stats
43994 * as sync_io is counted when a request starts, and
43995 * disk_stats is counted when it completes.
43996diff --git a/drivers/md/md.h b/drivers/md/md.h
43997index 0095ec8..c89277a 100644
43998--- a/drivers/md/md.h
43999+++ b/drivers/md/md.h
44000@@ -94,13 +94,13 @@ struct md_rdev {
44001 * only maintained for arrays that
44002 * support hot removal
44003 */
44004- atomic_t read_errors; /* number of consecutive read errors that
44005+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
44006 * we have tried to ignore.
44007 */
44008 struct timespec last_read_error; /* monotonic time since our
44009 * last read error
44010 */
44011- atomic_t corrected_errors; /* number of corrected read errors,
44012+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44013 * for reporting to userspace and storing
44014 * in superblock.
44015 */
44016@@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44017
44018 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44019 {
44020- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44021+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44022 }
44023
44024 struct md_personality
44025diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44026index 579b582..9fb6185 100644
44027--- a/drivers/md/persistent-data/dm-space-map-metadata.c
44028+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44029@@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44030 * Flick into a mode where all blocks get allocated in the new area.
44031 */
44032 smm->begin = old_len;
44033- memcpy(sm, &bootstrap_ops, sizeof(*sm));
44034+ memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44035
44036 /*
44037 * Extend.
44038@@ -710,7 +710,7 @@ out:
44039 /*
44040 * Switch back to normal behaviour.
44041 */
44042- memcpy(sm, &ops, sizeof(*sm));
44043+ memcpy((void *)sm, &ops, sizeof(*sm));
44044 return r;
44045 }
44046
44047diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44048index 3e6d115..ffecdeb 100644
44049--- a/drivers/md/persistent-data/dm-space-map.h
44050+++ b/drivers/md/persistent-data/dm-space-map.h
44051@@ -71,6 +71,7 @@ struct dm_space_map {
44052 dm_sm_threshold_fn fn,
44053 void *context);
44054 };
44055+typedef struct dm_space_map __no_const dm_space_map_no_const;
44056
44057 /*----------------------------------------------------------------*/
44058
44059diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44060index 63b2e8d..225f16b 100644
44061--- a/drivers/md/raid1.c
44062+++ b/drivers/md/raid1.c
44063@@ -1921,7 +1921,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44064 if (r1_sync_page_io(rdev, sect, s,
44065 bio->bi_io_vec[idx].bv_page,
44066 READ) != 0)
44067- atomic_add(s, &rdev->corrected_errors);
44068+ atomic_add_unchecked(s, &rdev->corrected_errors);
44069 }
44070 sectors -= s;
44071 sect += s;
44072@@ -2155,7 +2155,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44073 test_bit(In_sync, &rdev->flags)) {
44074 if (r1_sync_page_io(rdev, sect, s,
44075 conf->tmppage, READ)) {
44076- atomic_add(s, &rdev->corrected_errors);
44077+ atomic_add_unchecked(s, &rdev->corrected_errors);
44078 printk(KERN_INFO
44079 "md/raid1:%s: read error corrected "
44080 "(%d sectors at %llu on %s)\n",
44081diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44082index 06eeb99..770613e 100644
44083--- a/drivers/md/raid10.c
44084+++ b/drivers/md/raid10.c
44085@@ -1963,7 +1963,7 @@ static void end_sync_read(struct bio *bio, int error)
44086 /* The write handler will notice the lack of
44087 * R10BIO_Uptodate and record any errors etc
44088 */
44089- atomic_add(r10_bio->sectors,
44090+ atomic_add_unchecked(r10_bio->sectors,
44091 &conf->mirrors[d].rdev->corrected_errors);
44092
44093 /* for reconstruct, we always reschedule after a read.
44094@@ -2321,7 +2321,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44095 {
44096 struct timespec cur_time_mon;
44097 unsigned long hours_since_last;
44098- unsigned int read_errors = atomic_read(&rdev->read_errors);
44099+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44100
44101 ktime_get_ts(&cur_time_mon);
44102
44103@@ -2343,9 +2343,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44104 * overflowing the shift of read_errors by hours_since_last.
44105 */
44106 if (hours_since_last >= 8 * sizeof(read_errors))
44107- atomic_set(&rdev->read_errors, 0);
44108+ atomic_set_unchecked(&rdev->read_errors, 0);
44109 else
44110- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44111+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44112 }
44113
44114 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44115@@ -2399,8 +2399,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44116 return;
44117
44118 check_decay_read_errors(mddev, rdev);
44119- atomic_inc(&rdev->read_errors);
44120- if (atomic_read(&rdev->read_errors) > max_read_errors) {
44121+ atomic_inc_unchecked(&rdev->read_errors);
44122+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44123 char b[BDEVNAME_SIZE];
44124 bdevname(rdev->bdev, b);
44125
44126@@ -2408,7 +2408,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44127 "md/raid10:%s: %s: Raid device exceeded "
44128 "read_error threshold [cur %d:max %d]\n",
44129 mdname(mddev), b,
44130- atomic_read(&rdev->read_errors), max_read_errors);
44131+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44132 printk(KERN_NOTICE
44133 "md/raid10:%s: %s: Failing raid device\n",
44134 mdname(mddev), b);
44135@@ -2563,7 +2563,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44136 sect +
44137 choose_data_offset(r10_bio, rdev)),
44138 bdevname(rdev->bdev, b));
44139- atomic_add(s, &rdev->corrected_errors);
44140+ atomic_add_unchecked(s, &rdev->corrected_errors);
44141 }
44142
44143 rdev_dec_pending(rdev, mddev);
44144diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44145index 48cdec8..c7726b1 100644
44146--- a/drivers/md/raid5.c
44147+++ b/drivers/md/raid5.c
44148@@ -1991,21 +1991,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44149 mdname(conf->mddev), STRIPE_SECTORS,
44150 (unsigned long long)s,
44151 bdevname(rdev->bdev, b));
44152- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44153+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44154 clear_bit(R5_ReadError, &sh->dev[i].flags);
44155 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44156 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44157 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44158
44159- if (atomic_read(&rdev->read_errors))
44160- atomic_set(&rdev->read_errors, 0);
44161+ if (atomic_read_unchecked(&rdev->read_errors))
44162+ atomic_set_unchecked(&rdev->read_errors, 0);
44163 } else {
44164 const char *bdn = bdevname(rdev->bdev, b);
44165 int retry = 0;
44166 int set_bad = 0;
44167
44168 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44169- atomic_inc(&rdev->read_errors);
44170+ atomic_inc_unchecked(&rdev->read_errors);
44171 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44172 printk_ratelimited(
44173 KERN_WARNING
44174@@ -2033,7 +2033,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44175 mdname(conf->mddev),
44176 (unsigned long long)s,
44177 bdn);
44178- } else if (atomic_read(&rdev->read_errors)
44179+ } else if (atomic_read_unchecked(&rdev->read_errors)
44180 > conf->max_nr_stripes)
44181 printk(KERN_WARNING
44182 "md/raid:%s: Too many read errors, failing device %s.\n",
44183diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44184index 983db75..ef9248c 100644
44185--- a/drivers/media/dvb-core/dvbdev.c
44186+++ b/drivers/media/dvb-core/dvbdev.c
44187@@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44188 const struct dvb_device *template, void *priv, int type)
44189 {
44190 struct dvb_device *dvbdev;
44191- struct file_operations *dvbdevfops;
44192+ file_operations_no_const *dvbdevfops;
44193 struct device *clsdev;
44194 int minor;
44195 int id;
44196diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44197index 9b6c3bb..baeb5c7 100644
44198--- a/drivers/media/dvb-frontends/dib3000.h
44199+++ b/drivers/media/dvb-frontends/dib3000.h
44200@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44201 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44202 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44203 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44204-};
44205+} __no_const;
44206
44207 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44208 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44209diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44210index ed8cb90..5ef7f79 100644
44211--- a/drivers/media/pci/cx88/cx88-video.c
44212+++ b/drivers/media/pci/cx88/cx88-video.c
44213@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44214
44215 /* ------------------------------------------------------------------ */
44216
44217-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44218-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44219-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44220+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44221+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44222+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44223
44224 module_param_array(video_nr, int, NULL, 0444);
44225 module_param_array(vbi_nr, int, NULL, 0444);
44226diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44227index 802642d..5534900 100644
44228--- a/drivers/media/pci/ivtv/ivtv-driver.c
44229+++ b/drivers/media/pci/ivtv/ivtv-driver.c
44230@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44231 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44232
44233 /* ivtv instance counter */
44234-static atomic_t ivtv_instance = ATOMIC_INIT(0);
44235+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44236
44237 /* Parameter declarations */
44238 static int cardtype[IVTV_MAX_CARDS];
44239diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44240index dfd0a21..6bbb465 100644
44241--- a/drivers/media/platform/omap/omap_vout.c
44242+++ b/drivers/media/platform/omap/omap_vout.c
44243@@ -63,7 +63,6 @@ enum omap_vout_channels {
44244 OMAP_VIDEO2,
44245 };
44246
44247-static struct videobuf_queue_ops video_vbq_ops;
44248 /* Variables configurable through module params*/
44249 static u32 video1_numbuffers = 3;
44250 static u32 video2_numbuffers = 3;
44251@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
44252 {
44253 struct videobuf_queue *q;
44254 struct omap_vout_device *vout = NULL;
44255+ static struct videobuf_queue_ops video_vbq_ops = {
44256+ .buf_setup = omap_vout_buffer_setup,
44257+ .buf_prepare = omap_vout_buffer_prepare,
44258+ .buf_release = omap_vout_buffer_release,
44259+ .buf_queue = omap_vout_buffer_queue,
44260+ };
44261
44262 vout = video_drvdata(file);
44263 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44264@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
44265 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44266
44267 q = &vout->vbq;
44268- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44269- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44270- video_vbq_ops.buf_release = omap_vout_buffer_release;
44271- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44272 spin_lock_init(&vout->vbq_lock);
44273
44274 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44275diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44276index fb2acc5..a2fcbdc4 100644
44277--- a/drivers/media/platform/s5p-tv/mixer.h
44278+++ b/drivers/media/platform/s5p-tv/mixer.h
44279@@ -156,7 +156,7 @@ struct mxr_layer {
44280 /** layer index (unique identifier) */
44281 int idx;
44282 /** callbacks for layer methods */
44283- struct mxr_layer_ops ops;
44284+ struct mxr_layer_ops *ops;
44285 /** format array */
44286 const struct mxr_format **fmt_array;
44287 /** size of format array */
44288diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44289index 74344c7..a39e70e 100644
44290--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44291+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44292@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44293 {
44294 struct mxr_layer *layer;
44295 int ret;
44296- struct mxr_layer_ops ops = {
44297+ static struct mxr_layer_ops ops = {
44298 .release = mxr_graph_layer_release,
44299 .buffer_set = mxr_graph_buffer_set,
44300 .stream_set = mxr_graph_stream_set,
44301diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44302index b713403..53cb5ad 100644
44303--- a/drivers/media/platform/s5p-tv/mixer_reg.c
44304+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44305@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44306 layer->update_buf = next;
44307 }
44308
44309- layer->ops.buffer_set(layer, layer->update_buf);
44310+ layer->ops->buffer_set(layer, layer->update_buf);
44311
44312 if (done && done != layer->shadow_buf)
44313 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44314diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44315index 81b97db..b089ccd 100644
44316--- a/drivers/media/platform/s5p-tv/mixer_video.c
44317+++ b/drivers/media/platform/s5p-tv/mixer_video.c
44318@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44319 layer->geo.src.height = layer->geo.src.full_height;
44320
44321 mxr_geometry_dump(mdev, &layer->geo);
44322- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44323+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44324 mxr_geometry_dump(mdev, &layer->geo);
44325 }
44326
44327@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44328 layer->geo.dst.full_width = mbus_fmt.width;
44329 layer->geo.dst.full_height = mbus_fmt.height;
44330 layer->geo.dst.field = mbus_fmt.field;
44331- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44332+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44333
44334 mxr_geometry_dump(mdev, &layer->geo);
44335 }
44336@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44337 /* set source size to highest accepted value */
44338 geo->src.full_width = max(geo->dst.full_width, pix->width);
44339 geo->src.full_height = max(geo->dst.full_height, pix->height);
44340- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44341+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44342 mxr_geometry_dump(mdev, &layer->geo);
44343 /* set cropping to total visible screen */
44344 geo->src.width = pix->width;
44345@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44346 geo->src.x_offset = 0;
44347 geo->src.y_offset = 0;
44348 /* assure consistency of geometry */
44349- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44350+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44351 mxr_geometry_dump(mdev, &layer->geo);
44352 /* set full size to lowest possible value */
44353 geo->src.full_width = 0;
44354 geo->src.full_height = 0;
44355- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44356+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44357 mxr_geometry_dump(mdev, &layer->geo);
44358
44359 /* returning results */
44360@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44361 target->width = s->r.width;
44362 target->height = s->r.height;
44363
44364- layer->ops.fix_geometry(layer, stage, s->flags);
44365+ layer->ops->fix_geometry(layer, stage, s->flags);
44366
44367 /* retrieve update selection rectangle */
44368 res.left = target->x_offset;
44369@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44370 mxr_output_get(mdev);
44371
44372 mxr_layer_update_output(layer);
44373- layer->ops.format_set(layer);
44374+ layer->ops->format_set(layer);
44375 /* enabling layer in hardware */
44376 spin_lock_irqsave(&layer->enq_slock, flags);
44377 layer->state = MXR_LAYER_STREAMING;
44378 spin_unlock_irqrestore(&layer->enq_slock, flags);
44379
44380- layer->ops.stream_set(layer, MXR_ENABLE);
44381+ layer->ops->stream_set(layer, MXR_ENABLE);
44382 mxr_streamer_get(mdev);
44383
44384 return 0;
44385@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
44386 spin_unlock_irqrestore(&layer->enq_slock, flags);
44387
44388 /* disabling layer in hardware */
44389- layer->ops.stream_set(layer, MXR_DISABLE);
44390+ layer->ops->stream_set(layer, MXR_DISABLE);
44391 /* remove one streamer */
44392 mxr_streamer_put(mdev);
44393 /* allow changes in output configuration */
44394@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44395
44396 void mxr_layer_release(struct mxr_layer *layer)
44397 {
44398- if (layer->ops.release)
44399- layer->ops.release(layer);
44400+ if (layer->ops->release)
44401+ layer->ops->release(layer);
44402 }
44403
44404 void mxr_base_layer_release(struct mxr_layer *layer)
44405@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44406
44407 layer->mdev = mdev;
44408 layer->idx = idx;
44409- layer->ops = *ops;
44410+ layer->ops = ops;
44411
44412 spin_lock_init(&layer->enq_slock);
44413 INIT_LIST_HEAD(&layer->enq_list);
44414diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44415index c9388c4..ce71ece 100644
44416--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44417+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44418@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44419 {
44420 struct mxr_layer *layer;
44421 int ret;
44422- struct mxr_layer_ops ops = {
44423+ static struct mxr_layer_ops ops = {
44424 .release = mxr_vp_layer_release,
44425 .buffer_set = mxr_vp_buffer_set,
44426 .stream_set = mxr_vp_stream_set,
44427diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44428index 2d4e73b..8b4d5b6 100644
44429--- a/drivers/media/platform/vivi.c
44430+++ b/drivers/media/platform/vivi.c
44431@@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44432 MODULE_LICENSE("Dual BSD/GPL");
44433 MODULE_VERSION(VIVI_VERSION);
44434
44435-static unsigned video_nr = -1;
44436-module_param(video_nr, uint, 0644);
44437+static int video_nr = -1;
44438+module_param(video_nr, int, 0644);
44439 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
44440
44441 static unsigned n_devs = 1;
44442diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
44443index 545c04c..a14bded 100644
44444--- a/drivers/media/radio/radio-cadet.c
44445+++ b/drivers/media/radio/radio-cadet.c
44446@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44447 unsigned char readbuf[RDS_BUFFER];
44448 int i = 0;
44449
44450+ if (count > RDS_BUFFER)
44451+ return -EFAULT;
44452 mutex_lock(&dev->lock);
44453 if (dev->rdsstat == 0)
44454 cadet_start_rds(dev);
44455@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44456 while (i < count && dev->rdsin != dev->rdsout)
44457 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
44458
44459- if (i && copy_to_user(data, readbuf, i))
44460+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
44461 i = -EFAULT;
44462 unlock:
44463 mutex_unlock(&dev->lock);
44464diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
44465index 5236035..c622c74 100644
44466--- a/drivers/media/radio/radio-maxiradio.c
44467+++ b/drivers/media/radio/radio-maxiradio.c
44468@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
44469 /* TEA5757 pin mappings */
44470 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
44471
44472-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
44473+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
44474
44475 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
44476 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
44477diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
44478index 050b3bb..79f62b9 100644
44479--- a/drivers/media/radio/radio-shark.c
44480+++ b/drivers/media/radio/radio-shark.c
44481@@ -79,7 +79,7 @@ struct shark_device {
44482 u32 last_val;
44483 };
44484
44485-static atomic_t shark_instance = ATOMIC_INIT(0);
44486+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44487
44488 static void shark_write_val(struct snd_tea575x *tea, u32 val)
44489 {
44490diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
44491index 8654e0d..0608a64 100644
44492--- a/drivers/media/radio/radio-shark2.c
44493+++ b/drivers/media/radio/radio-shark2.c
44494@@ -74,7 +74,7 @@ struct shark_device {
44495 u8 *transfer_buffer;
44496 };
44497
44498-static atomic_t shark_instance = ATOMIC_INIT(0);
44499+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44500
44501 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
44502 {
44503diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
44504index 2fd9009..278cc1e 100644
44505--- a/drivers/media/radio/radio-si476x.c
44506+++ b/drivers/media/radio/radio-si476x.c
44507@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
44508 struct si476x_radio *radio;
44509 struct v4l2_ctrl *ctrl;
44510
44511- static atomic_t instance = ATOMIC_INIT(0);
44512+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
44513
44514 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
44515 if (!radio)
44516diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
44517index 46da365..3ba4206 100644
44518--- a/drivers/media/rc/rc-main.c
44519+++ b/drivers/media/rc/rc-main.c
44520@@ -1065,7 +1065,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
44521 int rc_register_device(struct rc_dev *dev)
44522 {
44523 static bool raw_init = false; /* raw decoders loaded? */
44524- static atomic_t devno = ATOMIC_INIT(0);
44525+ static atomic_unchecked_t devno = ATOMIC_INIT(0);
44526 struct rc_map *rc_map;
44527 const char *path;
44528 int rc;
44529@@ -1096,7 +1096,7 @@ int rc_register_device(struct rc_dev *dev)
44530 */
44531 mutex_lock(&dev->lock);
44532
44533- dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
44534+ dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
44535 dev_set_name(&dev->dev, "rc%ld", dev->devno);
44536 dev_set_drvdata(&dev->dev, dev);
44537 rc = device_add(&dev->dev);
44538diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
44539index a1c641e..3007da9 100644
44540--- a/drivers/media/usb/dvb-usb/cxusb.c
44541+++ b/drivers/media/usb/dvb-usb/cxusb.c
44542@@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
44543
44544 struct dib0700_adapter_state {
44545 int (*set_param_save) (struct dvb_frontend *);
44546-};
44547+} __no_const;
44548
44549 static int dib7070_set_param_override(struct dvb_frontend *fe)
44550 {
44551diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
44552index f272ed8..6289f9c 100644
44553--- a/drivers/media/usb/dvb-usb/dw2102.c
44554+++ b/drivers/media/usb/dvb-usb/dw2102.c
44555@@ -121,7 +121,7 @@ struct su3000_state {
44556
44557 struct s6x0_state {
44558 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
44559-};
44560+} __no_const;
44561
44562 /* debug */
44563 static int dvb_usb_dw2102_debug;
44564diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44565index 8f7a6a4..eb0e1d4 100644
44566--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44567+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44568@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
44569 __u32 reserved;
44570 };
44571
44572-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44573+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44574 enum v4l2_memory memory)
44575 {
44576 void __user *up_pln;
44577@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44578 return 0;
44579 }
44580
44581-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44582+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44583 enum v4l2_memory memory)
44584 {
44585 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
44586@@ -425,7 +425,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44587 * by passing a very big num_planes value */
44588 uplane = compat_alloc_user_space(num_planes *
44589 sizeof(struct v4l2_plane));
44590- kp->m.planes = uplane;
44591+ kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
44592
44593 while (--num_planes >= 0) {
44594 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
44595@@ -496,7 +496,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44596 if (num_planes == 0)
44597 return 0;
44598
44599- uplane = kp->m.planes;
44600+ uplane = (struct v4l2_plane __force_user *)kp->m.planes;
44601 if (get_user(p, &up->m.planes))
44602 return -EFAULT;
44603 uplane32 = compat_ptr(p);
44604@@ -550,7 +550,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
44605 get_user(kp->capability, &up->capability) ||
44606 get_user(kp->flags, &up->flags))
44607 return -EFAULT;
44608- kp->base = compat_ptr(tmp);
44609+ kp->base = (void __force_kernel *)compat_ptr(tmp);
44610 get_v4l2_pix_format(&kp->fmt, &up->fmt);
44611 return 0;
44612 }
44613@@ -656,7 +656,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44614 n * sizeof(struct v4l2_ext_control32)))
44615 return -EFAULT;
44616 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
44617- kp->controls = kcontrols;
44618+ kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
44619 while (--n >= 0) {
44620 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
44621 return -EFAULT;
44622@@ -678,7 +678,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44623 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
44624 {
44625 struct v4l2_ext_control32 __user *ucontrols;
44626- struct v4l2_ext_control __user *kcontrols = kp->controls;
44627+ struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
44628 int n = kp->count;
44629 compat_caddr_t p;
44630
44631@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
44632 put_user(kp->start_block, &up->start_block) ||
44633 put_user(kp->blocks, &up->blocks) ||
44634 put_user(tmp, &up->edid) ||
44635- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
44636+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
44637 return -EFAULT;
44638 return 0;
44639 }
44640diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
44641index fb46790..ae1f8fa 100644
44642--- a/drivers/media/v4l2-core/v4l2-ctrls.c
44643+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
44644@@ -1396,8 +1396,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
44645 return 0;
44646
44647 case V4L2_CTRL_TYPE_STRING:
44648- len = strlen(c->string);
44649- if (len < ctrl->minimum)
44650+ len = strlen_user(c->string);
44651+ if (!len || len < ctrl->minimum)
44652 return -ERANGE;
44653 if ((len - ctrl->minimum) % ctrl->step)
44654 return -ERANGE;
44655diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
44656index 02d1b63..5fd6b16 100644
44657--- a/drivers/media/v4l2-core/v4l2-device.c
44658+++ b/drivers/media/v4l2-core/v4l2-device.c
44659@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
44660 EXPORT_SYMBOL_GPL(v4l2_device_put);
44661
44662 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
44663- atomic_t *instance)
44664+ atomic_unchecked_t *instance)
44665 {
44666- int num = atomic_inc_return(instance) - 1;
44667+ int num = atomic_inc_return_unchecked(instance) - 1;
44668 int len = strlen(basename);
44669
44670 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
44671diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
44672index 68e6b5e..8eb2aec 100644
44673--- a/drivers/media/v4l2-core/v4l2-ioctl.c
44674+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
44675@@ -1939,7 +1939,8 @@ struct v4l2_ioctl_info {
44676 struct file *file, void *fh, void *p);
44677 } u;
44678 void (*debug)(const void *arg, bool write_only);
44679-};
44680+} __do_const;
44681+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
44682
44683 /* This control needs a priority check */
44684 #define INFO_FL_PRIO (1 << 0)
44685@@ -2120,7 +2121,7 @@ static long __video_do_ioctl(struct file *file,
44686 struct video_device *vfd = video_devdata(file);
44687 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
44688 bool write_only = false;
44689- struct v4l2_ioctl_info default_info;
44690+ v4l2_ioctl_info_no_const default_info;
44691 const struct v4l2_ioctl_info *info;
44692 void *fh = file->private_data;
44693 struct v4l2_fh *vfh = NULL;
44694@@ -2194,7 +2195,7 @@ done:
44695 }
44696
44697 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44698- void * __user *user_ptr, void ***kernel_ptr)
44699+ void __user **user_ptr, void ***kernel_ptr)
44700 {
44701 int ret = 0;
44702
44703@@ -2210,7 +2211,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44704 ret = -EINVAL;
44705 break;
44706 }
44707- *user_ptr = (void __user *)buf->m.planes;
44708+ *user_ptr = (void __force_user *)buf->m.planes;
44709 *kernel_ptr = (void *)&buf->m.planes;
44710 *array_size = sizeof(struct v4l2_plane) * buf->length;
44711 ret = 1;
44712@@ -2245,7 +2246,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44713 ret = -EINVAL;
44714 break;
44715 }
44716- *user_ptr = (void __user *)ctrls->controls;
44717+ *user_ptr = (void __force_user *)ctrls->controls;
44718 *kernel_ptr = (void *)&ctrls->controls;
44719 *array_size = sizeof(struct v4l2_ext_control)
44720 * ctrls->count;
44721@@ -2340,7 +2341,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
44722 err = -ENOTTY;
44723
44724 if (has_array_args) {
44725- *kernel_ptr = user_ptr;
44726+ *kernel_ptr = (void __force_kernel *)user_ptr;
44727 if (copy_to_user(user_ptr, mbuf, array_size))
44728 err = -EFAULT;
44729 goto out_array_args;
44730diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
44731index 767ff4d..c69d259 100644
44732--- a/drivers/message/fusion/mptbase.c
44733+++ b/drivers/message/fusion/mptbase.c
44734@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44735 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
44736 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
44737
44738+#ifdef CONFIG_GRKERNSEC_HIDESYM
44739+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
44740+#else
44741 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
44742 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
44743+#endif
44744+
44745 /*
44746 * Rounding UP to nearest 4-kB boundary here...
44747 */
44748@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44749 ioc->facts.GlobalCredits);
44750
44751 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
44752+#ifdef CONFIG_GRKERNSEC_HIDESYM
44753+ NULL, NULL);
44754+#else
44755 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
44756+#endif
44757 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
44758 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
44759 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
44760diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
44761index dd239bd..689c4f7 100644
44762--- a/drivers/message/fusion/mptsas.c
44763+++ b/drivers/message/fusion/mptsas.c
44764@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
44765 return 0;
44766 }
44767
44768+static inline void
44769+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44770+{
44771+ if (phy_info->port_details) {
44772+ phy_info->port_details->rphy = rphy;
44773+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44774+ ioc->name, rphy));
44775+ }
44776+
44777+ if (rphy) {
44778+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44779+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44780+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44781+ ioc->name, rphy, rphy->dev.release));
44782+ }
44783+}
44784+
44785 /* no mutex */
44786 static void
44787 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
44788@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
44789 return NULL;
44790 }
44791
44792-static inline void
44793-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44794-{
44795- if (phy_info->port_details) {
44796- phy_info->port_details->rphy = rphy;
44797- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44798- ioc->name, rphy));
44799- }
44800-
44801- if (rphy) {
44802- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44803- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44804- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44805- ioc->name, rphy, rphy->dev.release));
44806- }
44807-}
44808-
44809 static inline struct sas_port *
44810 mptsas_get_port(struct mptsas_phyinfo *phy_info)
44811 {
44812diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
44813index 727819c..ad74694 100644
44814--- a/drivers/message/fusion/mptscsih.c
44815+++ b/drivers/message/fusion/mptscsih.c
44816@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
44817
44818 h = shost_priv(SChost);
44819
44820- if (h) {
44821- if (h->info_kbuf == NULL)
44822- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44823- return h->info_kbuf;
44824- h->info_kbuf[0] = '\0';
44825+ if (!h)
44826+ return NULL;
44827
44828- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44829- h->info_kbuf[size-1] = '\0';
44830- }
44831+ if (h->info_kbuf == NULL)
44832+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44833+ return h->info_kbuf;
44834+ h->info_kbuf[0] = '\0';
44835+
44836+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44837+ h->info_kbuf[size-1] = '\0';
44838
44839 return h->info_kbuf;
44840 }
44841diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
44842index b7d87cd..3fb36da 100644
44843--- a/drivers/message/i2o/i2o_proc.c
44844+++ b/drivers/message/i2o/i2o_proc.c
44845@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
44846 "Array Controller Device"
44847 };
44848
44849-static char *chtostr(char *tmp, u8 *chars, int n)
44850-{
44851- tmp[0] = 0;
44852- return strncat(tmp, (char *)chars, n);
44853-}
44854-
44855 static int i2o_report_query_status(struct seq_file *seq, int block_status,
44856 char *group)
44857 {
44858@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
44859 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
44860 {
44861 struct i2o_controller *c = (struct i2o_controller *)seq->private;
44862- static u32 work32[5];
44863- static u8 *work8 = (u8 *) work32;
44864- static u16 *work16 = (u16 *) work32;
44865+ u32 work32[5];
44866+ u8 *work8 = (u8 *) work32;
44867+ u16 *work16 = (u16 *) work32;
44868 int token;
44869 u32 hwcap;
44870
44871@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44872 } *result;
44873
44874 i2o_exec_execute_ddm_table ddm_table;
44875- char tmp[28 + 1];
44876
44877 result = kmalloc(sizeof(*result), GFP_KERNEL);
44878 if (!result)
44879@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44880
44881 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
44882 seq_printf(seq, "%-#8x", ddm_table.module_id);
44883- seq_printf(seq, "%-29s",
44884- chtostr(tmp, ddm_table.module_name_version, 28));
44885+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
44886 seq_printf(seq, "%9d ", ddm_table.data_size);
44887 seq_printf(seq, "%8d", ddm_table.code_size);
44888
44889@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44890
44891 i2o_driver_result_table *result;
44892 i2o_driver_store_table *dst;
44893- char tmp[28 + 1];
44894
44895 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
44896 if (result == NULL)
44897@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44898
44899 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
44900 seq_printf(seq, "%-#8x", dst->module_id);
44901- seq_printf(seq, "%-29s",
44902- chtostr(tmp, dst->module_name_version, 28));
44903- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
44904+ seq_printf(seq, "%-.28s", dst->module_name_version);
44905+ seq_printf(seq, "%-.8s", dst->date);
44906 seq_printf(seq, "%8d ", dst->module_size);
44907 seq_printf(seq, "%8d ", dst->mpb_size);
44908 seq_printf(seq, "0x%04x", dst->module_flags);
44909@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
44910 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44911 {
44912 struct i2o_device *d = (struct i2o_device *)seq->private;
44913- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44914+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44915 // == (allow) 512d bytes (max)
44916- static u16 *work16 = (u16 *) work32;
44917+ u16 *work16 = (u16 *) work32;
44918 int token;
44919- char tmp[16 + 1];
44920
44921 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
44922
44923@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44924 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
44925 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
44926 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
44927- seq_printf(seq, "Vendor info : %s\n",
44928- chtostr(tmp, (u8 *) (work32 + 2), 16));
44929- seq_printf(seq, "Product info : %s\n",
44930- chtostr(tmp, (u8 *) (work32 + 6), 16));
44931- seq_printf(seq, "Description : %s\n",
44932- chtostr(tmp, (u8 *) (work32 + 10), 16));
44933- seq_printf(seq, "Product rev. : %s\n",
44934- chtostr(tmp, (u8 *) (work32 + 14), 8));
44935+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
44936+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
44937+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
44938+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
44939
44940 seq_printf(seq, "Serial number : ");
44941 print_serial_number(seq, (u8 *) (work32 + 16),
44942@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44943 u8 pad[256]; // allow up to 256 byte (max) serial number
44944 } result;
44945
44946- char tmp[24 + 1];
44947-
44948 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
44949
44950 if (token < 0) {
44951@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44952 }
44953
44954 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
44955- seq_printf(seq, "Module name : %s\n",
44956- chtostr(tmp, result.module_name, 24));
44957- seq_printf(seq, "Module revision : %s\n",
44958- chtostr(tmp, result.module_rev, 8));
44959+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
44960+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
44961
44962 seq_printf(seq, "Serial number : ");
44963 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
44964@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44965 u8 instance_number[4];
44966 } result;
44967
44968- char tmp[64 + 1];
44969-
44970 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
44971
44972 if (token < 0) {
44973@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44974 return 0;
44975 }
44976
44977- seq_printf(seq, "Device name : %s\n",
44978- chtostr(tmp, result.device_name, 64));
44979- seq_printf(seq, "Service name : %s\n",
44980- chtostr(tmp, result.service_name, 64));
44981- seq_printf(seq, "Physical name : %s\n",
44982- chtostr(tmp, result.physical_location, 64));
44983- seq_printf(seq, "Instance number : %s\n",
44984- chtostr(tmp, result.instance_number, 4));
44985+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
44986+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
44987+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
44988+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
44989
44990 return 0;
44991 }
44992@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44993 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
44994 {
44995 struct i2o_device *d = (struct i2o_device *)seq->private;
44996- static u32 work32[12];
44997- static u16 *work16 = (u16 *) work32;
44998- static u8 *work8 = (u8 *) work32;
44999+ u32 work32[12];
45000+ u16 *work16 = (u16 *) work32;
45001+ u8 *work8 = (u8 *) work32;
45002 int token;
45003
45004 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
45005diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
45006index a8c08f3..155fe3d 100644
45007--- a/drivers/message/i2o/iop.c
45008+++ b/drivers/message/i2o/iop.c
45009@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
45010
45011 spin_lock_irqsave(&c->context_list_lock, flags);
45012
45013- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
45014- atomic_inc(&c->context_list_counter);
45015+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
45016+ atomic_inc_unchecked(&c->context_list_counter);
45017
45018- entry->context = atomic_read(&c->context_list_counter);
45019+ entry->context = atomic_read_unchecked(&c->context_list_counter);
45020
45021 list_add(&entry->list, &c->context_list);
45022
45023@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
45024
45025 #if BITS_PER_LONG == 64
45026 spin_lock_init(&c->context_list_lock);
45027- atomic_set(&c->context_list_counter, 0);
45028+ atomic_set_unchecked(&c->context_list_counter, 0);
45029 INIT_LIST_HEAD(&c->context_list);
45030 #endif
45031
45032diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
45033index e33e385..28dfd23 100644
45034--- a/drivers/mfd/ab8500-debugfs.c
45035+++ b/drivers/mfd/ab8500-debugfs.c
45036@@ -100,7 +100,7 @@ static int irq_last;
45037 static u32 *irq_count;
45038 static int num_irqs;
45039
45040-static struct device_attribute **dev_attr;
45041+static device_attribute_no_const **dev_attr;
45042 static char **event_name;
45043
45044 static u8 avg_sample = SAMPLE_16;
45045diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
45046index fcbb2e9..2635e11 100644
45047--- a/drivers/mfd/janz-cmodio.c
45048+++ b/drivers/mfd/janz-cmodio.c
45049@@ -13,6 +13,7 @@
45050
45051 #include <linux/kernel.h>
45052 #include <linux/module.h>
45053+#include <linux/slab.h>
45054 #include <linux/init.h>
45055 #include <linux/pci.h>
45056 #include <linux/interrupt.h>
45057diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
45058index 176aa26..27811b2 100644
45059--- a/drivers/mfd/max8925-i2c.c
45060+++ b/drivers/mfd/max8925-i2c.c
45061@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
45062 const struct i2c_device_id *id)
45063 {
45064 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
45065- static struct max8925_chip *chip;
45066+ struct max8925_chip *chip;
45067 struct device_node *node = client->dev.of_node;
45068
45069 if (node && !pdata) {
45070diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
45071index c0f608e..286f8ec 100644
45072--- a/drivers/mfd/tps65910.c
45073+++ b/drivers/mfd/tps65910.c
45074@@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
45075 struct tps65910_platform_data *pdata)
45076 {
45077 int ret = 0;
45078- static struct regmap_irq_chip *tps6591x_irqs_chip;
45079+ struct regmap_irq_chip *tps6591x_irqs_chip;
45080
45081 if (!irq) {
45082 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
45083diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
45084index 9aa6d1e..1631bfc 100644
45085--- a/drivers/mfd/twl4030-irq.c
45086+++ b/drivers/mfd/twl4030-irq.c
45087@@ -35,6 +35,7 @@
45088 #include <linux/of.h>
45089 #include <linux/irqdomain.h>
45090 #include <linux/i2c/twl.h>
45091+#include <asm/pgtable.h>
45092
45093 #include "twl-core.h"
45094
45095@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45096 * Install an irq handler for each of the SIH modules;
45097 * clone dummy irq_chip since PIH can't *do* anything
45098 */
45099- twl4030_irq_chip = dummy_irq_chip;
45100- twl4030_irq_chip.name = "twl4030";
45101+ pax_open_kernel();
45102+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45103+ *(const char **)&twl4030_irq_chip.name = "twl4030";
45104
45105- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45106+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45107+ pax_close_kernel();
45108
45109 for (i = irq_base; i < irq_end; i++) {
45110 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45111diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45112index 464419b..64bae8d 100644
45113--- a/drivers/misc/c2port/core.c
45114+++ b/drivers/misc/c2port/core.c
45115@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45116 goto error_idr_alloc;
45117 c2dev->id = ret;
45118
45119- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45120+ pax_open_kernel();
45121+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45122+ pax_close_kernel();
45123
45124 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45125 "c2port%d", c2dev->id);
45126diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45127index 9c34e57..b981cda 100644
45128--- a/drivers/misc/eeprom/sunxi_sid.c
45129+++ b/drivers/misc/eeprom/sunxi_sid.c
45130@@ -127,7 +127,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45131
45132 platform_set_drvdata(pdev, sid_data);
45133
45134- sid_bin_attr.size = sid_data->keysize;
45135+ pax_open_kernel();
45136+ *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45137+ pax_close_kernel();
45138 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45139 return -ENODEV;
45140
45141diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45142index 36f5d52..32311c3 100644
45143--- a/drivers/misc/kgdbts.c
45144+++ b/drivers/misc/kgdbts.c
45145@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45146 char before[BREAK_INSTR_SIZE];
45147 char after[BREAK_INSTR_SIZE];
45148
45149- probe_kernel_read(before, (char *)kgdbts_break_test,
45150+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45151 BREAK_INSTR_SIZE);
45152 init_simple_test();
45153 ts.tst = plant_and_detach_test;
45154@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45155 /* Activate test with initial breakpoint */
45156 if (!is_early)
45157 kgdb_breakpoint();
45158- probe_kernel_read(after, (char *)kgdbts_break_test,
45159+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45160 BREAK_INSTR_SIZE);
45161 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45162 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45163diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45164index 036effe..b3a6336 100644
45165--- a/drivers/misc/lis3lv02d/lis3lv02d.c
45166+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45167@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45168 * the lid is closed. This leads to interrupts as soon as a little move
45169 * is done.
45170 */
45171- atomic_inc(&lis3->count);
45172+ atomic_inc_unchecked(&lis3->count);
45173
45174 wake_up_interruptible(&lis3->misc_wait);
45175 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45176@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45177 if (lis3->pm_dev)
45178 pm_runtime_get_sync(lis3->pm_dev);
45179
45180- atomic_set(&lis3->count, 0);
45181+ atomic_set_unchecked(&lis3->count, 0);
45182 return 0;
45183 }
45184
45185@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45186 add_wait_queue(&lis3->misc_wait, &wait);
45187 while (true) {
45188 set_current_state(TASK_INTERRUPTIBLE);
45189- data = atomic_xchg(&lis3->count, 0);
45190+ data = atomic_xchg_unchecked(&lis3->count, 0);
45191 if (data)
45192 break;
45193
45194@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45195 struct lis3lv02d, miscdev);
45196
45197 poll_wait(file, &lis3->misc_wait, wait);
45198- if (atomic_read(&lis3->count))
45199+ if (atomic_read_unchecked(&lis3->count))
45200 return POLLIN | POLLRDNORM;
45201 return 0;
45202 }
45203diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45204index c439c82..1f20f57 100644
45205--- a/drivers/misc/lis3lv02d/lis3lv02d.h
45206+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45207@@ -297,7 +297,7 @@ struct lis3lv02d {
45208 struct input_polled_dev *idev; /* input device */
45209 struct platform_device *pdev; /* platform device */
45210 struct regulator_bulk_data regulators[2];
45211- atomic_t count; /* interrupt count after last read */
45212+ atomic_unchecked_t count; /* interrupt count after last read */
45213 union axis_conversion ac; /* hw -> logical axis */
45214 int mapped_btns[3];
45215
45216diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45217index 2f30bad..c4c13d0 100644
45218--- a/drivers/misc/sgi-gru/gruhandles.c
45219+++ b/drivers/misc/sgi-gru/gruhandles.c
45220@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45221 unsigned long nsec;
45222
45223 nsec = CLKS2NSEC(clks);
45224- atomic_long_inc(&mcs_op_statistics[op].count);
45225- atomic_long_add(nsec, &mcs_op_statistics[op].total);
45226+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45227+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45228 if (mcs_op_statistics[op].max < nsec)
45229 mcs_op_statistics[op].max = nsec;
45230 }
45231diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45232index 4f76359..cdfcb2e 100644
45233--- a/drivers/misc/sgi-gru/gruprocfs.c
45234+++ b/drivers/misc/sgi-gru/gruprocfs.c
45235@@ -32,9 +32,9 @@
45236
45237 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45238
45239-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45240+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45241 {
45242- unsigned long val = atomic_long_read(v);
45243+ unsigned long val = atomic_long_read_unchecked(v);
45244
45245 seq_printf(s, "%16lu %s\n", val, id);
45246 }
45247@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45248
45249 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45250 for (op = 0; op < mcsop_last; op++) {
45251- count = atomic_long_read(&mcs_op_statistics[op].count);
45252- total = atomic_long_read(&mcs_op_statistics[op].total);
45253+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45254+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45255 max = mcs_op_statistics[op].max;
45256 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45257 count ? total / count : 0, max);
45258diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45259index 5c3ce24..4915ccb 100644
45260--- a/drivers/misc/sgi-gru/grutables.h
45261+++ b/drivers/misc/sgi-gru/grutables.h
45262@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45263 * GRU statistics.
45264 */
45265 struct gru_stats_s {
45266- atomic_long_t vdata_alloc;
45267- atomic_long_t vdata_free;
45268- atomic_long_t gts_alloc;
45269- atomic_long_t gts_free;
45270- atomic_long_t gms_alloc;
45271- atomic_long_t gms_free;
45272- atomic_long_t gts_double_allocate;
45273- atomic_long_t assign_context;
45274- atomic_long_t assign_context_failed;
45275- atomic_long_t free_context;
45276- atomic_long_t load_user_context;
45277- atomic_long_t load_kernel_context;
45278- atomic_long_t lock_kernel_context;
45279- atomic_long_t unlock_kernel_context;
45280- atomic_long_t steal_user_context;
45281- atomic_long_t steal_kernel_context;
45282- atomic_long_t steal_context_failed;
45283- atomic_long_t nopfn;
45284- atomic_long_t asid_new;
45285- atomic_long_t asid_next;
45286- atomic_long_t asid_wrap;
45287- atomic_long_t asid_reuse;
45288- atomic_long_t intr;
45289- atomic_long_t intr_cbr;
45290- atomic_long_t intr_tfh;
45291- atomic_long_t intr_spurious;
45292- atomic_long_t intr_mm_lock_failed;
45293- atomic_long_t call_os;
45294- atomic_long_t call_os_wait_queue;
45295- atomic_long_t user_flush_tlb;
45296- atomic_long_t user_unload_context;
45297- atomic_long_t user_exception;
45298- atomic_long_t set_context_option;
45299- atomic_long_t check_context_retarget_intr;
45300- atomic_long_t check_context_unload;
45301- atomic_long_t tlb_dropin;
45302- atomic_long_t tlb_preload_page;
45303- atomic_long_t tlb_dropin_fail_no_asid;
45304- atomic_long_t tlb_dropin_fail_upm;
45305- atomic_long_t tlb_dropin_fail_invalid;
45306- atomic_long_t tlb_dropin_fail_range_active;
45307- atomic_long_t tlb_dropin_fail_idle;
45308- atomic_long_t tlb_dropin_fail_fmm;
45309- atomic_long_t tlb_dropin_fail_no_exception;
45310- atomic_long_t tfh_stale_on_fault;
45311- atomic_long_t mmu_invalidate_range;
45312- atomic_long_t mmu_invalidate_page;
45313- atomic_long_t flush_tlb;
45314- atomic_long_t flush_tlb_gru;
45315- atomic_long_t flush_tlb_gru_tgh;
45316- atomic_long_t flush_tlb_gru_zero_asid;
45317+ atomic_long_unchecked_t vdata_alloc;
45318+ atomic_long_unchecked_t vdata_free;
45319+ atomic_long_unchecked_t gts_alloc;
45320+ atomic_long_unchecked_t gts_free;
45321+ atomic_long_unchecked_t gms_alloc;
45322+ atomic_long_unchecked_t gms_free;
45323+ atomic_long_unchecked_t gts_double_allocate;
45324+ atomic_long_unchecked_t assign_context;
45325+ atomic_long_unchecked_t assign_context_failed;
45326+ atomic_long_unchecked_t free_context;
45327+ atomic_long_unchecked_t load_user_context;
45328+ atomic_long_unchecked_t load_kernel_context;
45329+ atomic_long_unchecked_t lock_kernel_context;
45330+ atomic_long_unchecked_t unlock_kernel_context;
45331+ atomic_long_unchecked_t steal_user_context;
45332+ atomic_long_unchecked_t steal_kernel_context;
45333+ atomic_long_unchecked_t steal_context_failed;
45334+ atomic_long_unchecked_t nopfn;
45335+ atomic_long_unchecked_t asid_new;
45336+ atomic_long_unchecked_t asid_next;
45337+ atomic_long_unchecked_t asid_wrap;
45338+ atomic_long_unchecked_t asid_reuse;
45339+ atomic_long_unchecked_t intr;
45340+ atomic_long_unchecked_t intr_cbr;
45341+ atomic_long_unchecked_t intr_tfh;
45342+ atomic_long_unchecked_t intr_spurious;
45343+ atomic_long_unchecked_t intr_mm_lock_failed;
45344+ atomic_long_unchecked_t call_os;
45345+ atomic_long_unchecked_t call_os_wait_queue;
45346+ atomic_long_unchecked_t user_flush_tlb;
45347+ atomic_long_unchecked_t user_unload_context;
45348+ atomic_long_unchecked_t user_exception;
45349+ atomic_long_unchecked_t set_context_option;
45350+ atomic_long_unchecked_t check_context_retarget_intr;
45351+ atomic_long_unchecked_t check_context_unload;
45352+ atomic_long_unchecked_t tlb_dropin;
45353+ atomic_long_unchecked_t tlb_preload_page;
45354+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45355+ atomic_long_unchecked_t tlb_dropin_fail_upm;
45356+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
45357+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
45358+ atomic_long_unchecked_t tlb_dropin_fail_idle;
45359+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
45360+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45361+ atomic_long_unchecked_t tfh_stale_on_fault;
45362+ atomic_long_unchecked_t mmu_invalidate_range;
45363+ atomic_long_unchecked_t mmu_invalidate_page;
45364+ atomic_long_unchecked_t flush_tlb;
45365+ atomic_long_unchecked_t flush_tlb_gru;
45366+ atomic_long_unchecked_t flush_tlb_gru_tgh;
45367+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45368
45369- atomic_long_t copy_gpa;
45370- atomic_long_t read_gpa;
45371+ atomic_long_unchecked_t copy_gpa;
45372+ atomic_long_unchecked_t read_gpa;
45373
45374- atomic_long_t mesq_receive;
45375- atomic_long_t mesq_receive_none;
45376- atomic_long_t mesq_send;
45377- atomic_long_t mesq_send_failed;
45378- atomic_long_t mesq_noop;
45379- atomic_long_t mesq_send_unexpected_error;
45380- atomic_long_t mesq_send_lb_overflow;
45381- atomic_long_t mesq_send_qlimit_reached;
45382- atomic_long_t mesq_send_amo_nacked;
45383- atomic_long_t mesq_send_put_nacked;
45384- atomic_long_t mesq_page_overflow;
45385- atomic_long_t mesq_qf_locked;
45386- atomic_long_t mesq_qf_noop_not_full;
45387- atomic_long_t mesq_qf_switch_head_failed;
45388- atomic_long_t mesq_qf_unexpected_error;
45389- atomic_long_t mesq_noop_unexpected_error;
45390- atomic_long_t mesq_noop_lb_overflow;
45391- atomic_long_t mesq_noop_qlimit_reached;
45392- atomic_long_t mesq_noop_amo_nacked;
45393- atomic_long_t mesq_noop_put_nacked;
45394- atomic_long_t mesq_noop_page_overflow;
45395+ atomic_long_unchecked_t mesq_receive;
45396+ atomic_long_unchecked_t mesq_receive_none;
45397+ atomic_long_unchecked_t mesq_send;
45398+ atomic_long_unchecked_t mesq_send_failed;
45399+ atomic_long_unchecked_t mesq_noop;
45400+ atomic_long_unchecked_t mesq_send_unexpected_error;
45401+ atomic_long_unchecked_t mesq_send_lb_overflow;
45402+ atomic_long_unchecked_t mesq_send_qlimit_reached;
45403+ atomic_long_unchecked_t mesq_send_amo_nacked;
45404+ atomic_long_unchecked_t mesq_send_put_nacked;
45405+ atomic_long_unchecked_t mesq_page_overflow;
45406+ atomic_long_unchecked_t mesq_qf_locked;
45407+ atomic_long_unchecked_t mesq_qf_noop_not_full;
45408+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
45409+ atomic_long_unchecked_t mesq_qf_unexpected_error;
45410+ atomic_long_unchecked_t mesq_noop_unexpected_error;
45411+ atomic_long_unchecked_t mesq_noop_lb_overflow;
45412+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
45413+ atomic_long_unchecked_t mesq_noop_amo_nacked;
45414+ atomic_long_unchecked_t mesq_noop_put_nacked;
45415+ atomic_long_unchecked_t mesq_noop_page_overflow;
45416
45417 };
45418
45419@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45420 tghop_invalidate, mcsop_last};
45421
45422 struct mcs_op_statistic {
45423- atomic_long_t count;
45424- atomic_long_t total;
45425+ atomic_long_unchecked_t count;
45426+ atomic_long_unchecked_t total;
45427 unsigned long max;
45428 };
45429
45430@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45431
45432 #define STAT(id) do { \
45433 if (gru_options & OPT_STATS) \
45434- atomic_long_inc(&gru_stats.id); \
45435+ atomic_long_inc_unchecked(&gru_stats.id); \
45436 } while (0)
45437
45438 #ifdef CONFIG_SGI_GRU_DEBUG
45439diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45440index c862cd4..0d176fe 100644
45441--- a/drivers/misc/sgi-xp/xp.h
45442+++ b/drivers/misc/sgi-xp/xp.h
45443@@ -288,7 +288,7 @@ struct xpc_interface {
45444 xpc_notify_func, void *);
45445 void (*received) (short, int, void *);
45446 enum xp_retval (*partid_to_nasids) (short, void *);
45447-};
45448+} __no_const;
45449
45450 extern struct xpc_interface xpc_interface;
45451
45452diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45453index 01be66d..e3a0c7e 100644
45454--- a/drivers/misc/sgi-xp/xp_main.c
45455+++ b/drivers/misc/sgi-xp/xp_main.c
45456@@ -78,13 +78,13 @@ xpc_notloaded(void)
45457 }
45458
45459 struct xpc_interface xpc_interface = {
45460- (void (*)(int))xpc_notloaded,
45461- (void (*)(int))xpc_notloaded,
45462- (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45463- (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45464+ .connect = (void (*)(int))xpc_notloaded,
45465+ .disconnect = (void (*)(int))xpc_notloaded,
45466+ .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45467+ .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45468 void *))xpc_notloaded,
45469- (void (*)(short, int, void *))xpc_notloaded,
45470- (enum xp_retval(*)(short, void *))xpc_notloaded
45471+ .received = (void (*)(short, int, void *))xpc_notloaded,
45472+ .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
45473 };
45474 EXPORT_SYMBOL_GPL(xpc_interface);
45475
45476diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
45477index b94d5f7..7f494c5 100644
45478--- a/drivers/misc/sgi-xp/xpc.h
45479+++ b/drivers/misc/sgi-xp/xpc.h
45480@@ -835,6 +835,7 @@ struct xpc_arch_operations {
45481 void (*received_payload) (struct xpc_channel *, void *);
45482 void (*notify_senders_of_disconnect) (struct xpc_channel *);
45483 };
45484+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
45485
45486 /* struct xpc_partition act_state values (for XPC HB) */
45487
45488@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
45489 /* found in xpc_main.c */
45490 extern struct device *xpc_part;
45491 extern struct device *xpc_chan;
45492-extern struct xpc_arch_operations xpc_arch_ops;
45493+extern xpc_arch_operations_no_const xpc_arch_ops;
45494 extern int xpc_disengage_timelimit;
45495 extern int xpc_disengage_timedout;
45496 extern int xpc_activate_IRQ_rcvd;
45497diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
45498index 82dc574..8539ab2 100644
45499--- a/drivers/misc/sgi-xp/xpc_main.c
45500+++ b/drivers/misc/sgi-xp/xpc_main.c
45501@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
45502 .notifier_call = xpc_system_die,
45503 };
45504
45505-struct xpc_arch_operations xpc_arch_ops;
45506+xpc_arch_operations_no_const xpc_arch_ops;
45507
45508 /*
45509 * Timer function to enforce the timelimit on the partition disengage.
45510@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
45511
45512 if (((die_args->trapnr == X86_TRAP_MF) ||
45513 (die_args->trapnr == X86_TRAP_XF)) &&
45514- !user_mode_vm(die_args->regs))
45515+ !user_mode(die_args->regs))
45516 xpc_die_deactivate();
45517
45518 break;
45519diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
45520index 7b5424f..ed1d6ac 100644
45521--- a/drivers/mmc/card/block.c
45522+++ b/drivers/mmc/card/block.c
45523@@ -575,7 +575,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
45524 if (idata->ic.postsleep_min_us)
45525 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
45526
45527- if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
45528+ if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
45529 err = -EFAULT;
45530 goto cmd_rel_host;
45531 }
45532diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
45533index e5b5eeb..7bf2212 100644
45534--- a/drivers/mmc/core/mmc_ops.c
45535+++ b/drivers/mmc/core/mmc_ops.c
45536@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
45537 void *data_buf;
45538 int is_on_stack;
45539
45540- is_on_stack = object_is_on_stack(buf);
45541+ is_on_stack = object_starts_on_stack(buf);
45542 if (is_on_stack) {
45543 /*
45544 * dma onto stack is unsafe/nonportable, but callers to this
45545diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
45546index 6bf24ab..13d0293b 100644
45547--- a/drivers/mmc/host/dw_mmc.h
45548+++ b/drivers/mmc/host/dw_mmc.h
45549@@ -258,5 +258,5 @@ struct dw_mci_drv_data {
45550 int (*parse_dt)(struct dw_mci *host);
45551 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
45552 struct dw_mci_tuning_data *tuning_data);
45553-};
45554+} __do_const;
45555 #endif /* _DW_MMC_H_ */
45556diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
45557index f320579..7b7ebac 100644
45558--- a/drivers/mmc/host/mmci.c
45559+++ b/drivers/mmc/host/mmci.c
45560@@ -1504,7 +1504,9 @@ static int mmci_probe(struct amba_device *dev,
45561 }
45562
45563 if (variant->busy_detect) {
45564- mmci_ops.card_busy = mmci_card_busy;
45565+ pax_open_kernel();
45566+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
45567+ pax_close_kernel();
45568 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
45569 }
45570
45571diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
45572index 1dcaf8a..025af25 100644
45573--- a/drivers/mmc/host/sdhci-esdhc-imx.c
45574+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
45575@@ -1009,9 +1009,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
45576 host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN;
45577 }
45578
45579- if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
45580- sdhci_esdhc_ops.platform_execute_tuning =
45581+ if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
45582+ pax_open_kernel();
45583+ *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
45584 esdhc_executing_tuning;
45585+ pax_close_kernel();
45586+ }
45587 boarddata = &imx_data->boarddata;
45588 if (sdhci_esdhc_imx_probe_dt(pdev, boarddata) < 0) {
45589 if (!host->mmc->parent->platform_data) {
45590diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
45591index 6debda9..2ba7427 100644
45592--- a/drivers/mmc/host/sdhci-s3c.c
45593+++ b/drivers/mmc/host/sdhci-s3c.c
45594@@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
45595 * we can use overriding functions instead of default.
45596 */
45597 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
45598- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45599- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45600- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45601+ pax_open_kernel();
45602+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45603+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45604+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45605+ pax_close_kernel();
45606 }
45607
45608 /* It supports additional host capabilities if needed */
45609diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
45610index 096993f..f02c23b 100644
45611--- a/drivers/mtd/chips/cfi_cmdset_0020.c
45612+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
45613@@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
45614 size_t totlen = 0, thislen;
45615 int ret = 0;
45616 size_t buflen = 0;
45617- static char *buffer;
45618+ char *buffer;
45619
45620 if (!ECCBUF_SIZE) {
45621 /* We should fall back to a general writev implementation.
45622diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
45623index 370b9dd..1a1176b 100644
45624--- a/drivers/mtd/nand/denali.c
45625+++ b/drivers/mtd/nand/denali.c
45626@@ -24,6 +24,7 @@
45627 #include <linux/slab.h>
45628 #include <linux/mtd/mtd.h>
45629 #include <linux/module.h>
45630+#include <linux/slab.h>
45631
45632 #include "denali.h"
45633
45634diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
45635index 51b9d6a..52af9a7 100644
45636--- a/drivers/mtd/nftlmount.c
45637+++ b/drivers/mtd/nftlmount.c
45638@@ -24,6 +24,7 @@
45639 #include <asm/errno.h>
45640 #include <linux/delay.h>
45641 #include <linux/slab.h>
45642+#include <linux/sched.h>
45643 #include <linux/mtd/mtd.h>
45644 #include <linux/mtd/nand.h>
45645 #include <linux/mtd/nftl.h>
45646diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
45647index 4b8e895..6b3c498 100644
45648--- a/drivers/mtd/sm_ftl.c
45649+++ b/drivers/mtd/sm_ftl.c
45650@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
45651 #define SM_CIS_VENDOR_OFFSET 0x59
45652 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
45653 {
45654- struct attribute_group *attr_group;
45655+ attribute_group_no_const *attr_group;
45656 struct attribute **attributes;
45657 struct sm_sysfs_attribute *vendor_attribute;
45658
45659diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
45660index 4b8c58b..a200546 100644
45661--- a/drivers/net/bonding/bond_main.c
45662+++ b/drivers/net/bonding/bond_main.c
45663@@ -4527,6 +4527,7 @@ static void __exit bonding_exit(void)
45664
45665 bond_netlink_fini();
45666 unregister_pernet_subsys(&bond_net_ops);
45667+ rtnl_link_unregister(&bond_link_ops);
45668
45669 #ifdef CONFIG_NET_POLL_CONTROLLER
45670 /*
45671diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
45672index 40e7b1c..6a70fff 100644
45673--- a/drivers/net/bonding/bond_netlink.c
45674+++ b/drivers/net/bonding/bond_netlink.c
45675@@ -102,7 +102,7 @@ nla_put_failure:
45676 return -EMSGSIZE;
45677 }
45678
45679-struct rtnl_link_ops bond_link_ops __read_mostly = {
45680+struct rtnl_link_ops bond_link_ops = {
45681 .kind = "bond",
45682 .priv_size = sizeof(struct bonding),
45683 .setup = bond_setup,
45684diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
45685index 3c06947..fd0e5de 100644
45686--- a/drivers/net/can/Kconfig
45687+++ b/drivers/net/can/Kconfig
45688@@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
45689
45690 config CAN_FLEXCAN
45691 tristate "Support for Freescale FLEXCAN based chips"
45692- depends on ARM || PPC
45693+ depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
45694 ---help---
45695 Say Y here if you want to support for Freescale FlexCAN.
45696
45697diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
45698index 36fa577..a158806 100644
45699--- a/drivers/net/ethernet/8390/ax88796.c
45700+++ b/drivers/net/ethernet/8390/ax88796.c
45701@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
45702 if (ax->plat->reg_offsets)
45703 ei_local->reg_offset = ax->plat->reg_offsets;
45704 else {
45705+ resource_size_t _mem_size = mem_size;
45706+ do_div(_mem_size, 0x18);
45707 ei_local->reg_offset = ax->reg_offsets;
45708 for (ret = 0; ret < 0x18; ret++)
45709- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
45710+ ax->reg_offsets[ret] = _mem_size * ret;
45711 }
45712
45713 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
45714diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45715index 41f3ca5a..1ee5364 100644
45716--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45717+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45718@@ -1139,7 +1139,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
45719 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
45720 {
45721 /* RX_MODE controlling object */
45722- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
45723+ bnx2x_init_rx_mode_obj(bp);
45724
45725 /* multicast configuration controlling object */
45726 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
45727diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45728index 18438a5..c923b8e 100644
45729--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45730+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45731@@ -2591,15 +2591,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
45732 return rc;
45733 }
45734
45735-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45736- struct bnx2x_rx_mode_obj *o)
45737+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
45738 {
45739 if (CHIP_IS_E1x(bp)) {
45740- o->wait_comp = bnx2x_empty_rx_mode_wait;
45741- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
45742+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
45743+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
45744 } else {
45745- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
45746- o->config_rx_mode = bnx2x_set_rx_mode_e2;
45747+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
45748+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
45749 }
45750 }
45751
45752diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45753index 6a53c15..6e7d1e7 100644
45754--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45755+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45756@@ -1332,8 +1332,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
45757
45758 /********************* RX MODE ****************/
45759
45760-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45761- struct bnx2x_rx_mode_obj *o);
45762+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
45763
45764 /**
45765 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
45766diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
45767index cf9917b..c658558 100644
45768--- a/drivers/net/ethernet/broadcom/tg3.h
45769+++ b/drivers/net/ethernet/broadcom/tg3.h
45770@@ -150,6 +150,7 @@
45771 #define CHIPREV_ID_5750_A0 0x4000
45772 #define CHIPREV_ID_5750_A1 0x4001
45773 #define CHIPREV_ID_5750_A3 0x4003
45774+#define CHIPREV_ID_5750_C1 0x4201
45775 #define CHIPREV_ID_5750_C2 0x4202
45776 #define CHIPREV_ID_5752_A0_HW 0x5000
45777 #define CHIPREV_ID_5752_A0 0x6000
45778diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
45779index 3ca77fa..fcc015f 100644
45780--- a/drivers/net/ethernet/brocade/bna/bna_enet.c
45781+++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
45782@@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
45783 }
45784
45785 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
45786- bna_cb_ioceth_enable,
45787- bna_cb_ioceth_disable,
45788- bna_cb_ioceth_hbfail,
45789- bna_cb_ioceth_reset
45790+ .enable_cbfn = bna_cb_ioceth_enable,
45791+ .disable_cbfn = bna_cb_ioceth_disable,
45792+ .hbfail_cbfn = bna_cb_ioceth_hbfail,
45793+ .reset_cbfn = bna_cb_ioceth_reset
45794 };
45795
45796 static void bna_attr_init(struct bna_ioceth *ioceth)
45797diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45798index 8cffcdf..aadf043 100644
45799--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45800+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45801@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
45802 */
45803 struct l2t_skb_cb {
45804 arp_failure_handler_func arp_failure_handler;
45805-};
45806+} __no_const;
45807
45808 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
45809
45810diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45811index fff02ed..d421412 100644
45812--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45813+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45814@@ -2120,7 +2120,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
45815
45816 int i;
45817 struct adapter *ap = netdev2adap(dev);
45818- static const unsigned int *reg_ranges;
45819+ const unsigned int *reg_ranges;
45820 int arr_size = 0, buf_size = 0;
45821
45822 if (is_t4(ap->params.chip)) {
45823diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
45824index c05b66d..ed69872 100644
45825--- a/drivers/net/ethernet/dec/tulip/de4x5.c
45826+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
45827@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45828 for (i=0; i<ETH_ALEN; i++) {
45829 tmp.addr[i] = dev->dev_addr[i];
45830 }
45831- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45832+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45833 break;
45834
45835 case DE4X5_SET_HWADDR: /* Set the hardware address */
45836@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45837 spin_lock_irqsave(&lp->lock, flags);
45838 memcpy(&statbuf, &lp->pktStats, ioc->len);
45839 spin_unlock_irqrestore(&lp->lock, flags);
45840- if (copy_to_user(ioc->data, &statbuf, ioc->len))
45841+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
45842 return -EFAULT;
45843 break;
45844 }
45845diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
45846index a37039d..a51d7e8 100644
45847--- a/drivers/net/ethernet/emulex/benet/be_main.c
45848+++ b/drivers/net/ethernet/emulex/benet/be_main.c
45849@@ -533,7 +533,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
45850
45851 if (wrapped)
45852 newacc += 65536;
45853- ACCESS_ONCE(*acc) = newacc;
45854+ ACCESS_ONCE_RW(*acc) = newacc;
45855 }
45856
45857 static void populate_erx_stats(struct be_adapter *adapter,
45858diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
45859index 212f44b..fb69959 100644
45860--- a/drivers/net/ethernet/faraday/ftgmac100.c
45861+++ b/drivers/net/ethernet/faraday/ftgmac100.c
45862@@ -31,6 +31,8 @@
45863 #include <linux/netdevice.h>
45864 #include <linux/phy.h>
45865 #include <linux/platform_device.h>
45866+#include <linux/interrupt.h>
45867+#include <linux/irqreturn.h>
45868 #include <net/ip.h>
45869
45870 #include "ftgmac100.h"
45871diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
45872index 8be5b40..081bc1b 100644
45873--- a/drivers/net/ethernet/faraday/ftmac100.c
45874+++ b/drivers/net/ethernet/faraday/ftmac100.c
45875@@ -31,6 +31,8 @@
45876 #include <linux/module.h>
45877 #include <linux/netdevice.h>
45878 #include <linux/platform_device.h>
45879+#include <linux/interrupt.h>
45880+#include <linux/irqreturn.h>
45881
45882 #include "ftmac100.h"
45883
45884diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45885index 5184e2a..acb28c3 100644
45886--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45887+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45888@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
45889 }
45890
45891 /* update the base incval used to calculate frequency adjustment */
45892- ACCESS_ONCE(adapter->base_incval) = incval;
45893+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
45894 smp_mb();
45895
45896 /* need lock to prevent incorrect read while modifying cyclecounter */
45897diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45898index fbe5363..266b4e3 100644
45899--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
45900+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45901@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45902 struct __vxge_hw_fifo *fifo;
45903 struct vxge_hw_fifo_config *config;
45904 u32 txdl_size, txdl_per_memblock;
45905- struct vxge_hw_mempool_cbs fifo_mp_callback;
45906+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
45907+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
45908+ };
45909+
45910 struct __vxge_hw_virtualpath *vpath;
45911
45912 if ((vp == NULL) || (attr == NULL)) {
45913@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45914 goto exit;
45915 }
45916
45917- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
45918-
45919 fifo->mempool =
45920 __vxge_hw_mempool_create(vpath->hldev,
45921 fifo->config->memblock_size,
45922diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45923index 918e18d..4ca3650 100644
45924--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45925+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45926@@ -2086,7 +2086,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
45927 adapter->max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
45928 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
45929 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
45930- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45931+ pax_open_kernel();
45932+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45933+ pax_close_kernel();
45934 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45935 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
45936 adapter->max_tx_rings = QLCNIC_MAX_TX_RINGS;
45937diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45938index 734d286..b017bf5 100644
45939--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45940+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45941@@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
45942 case QLCNIC_NON_PRIV_FUNC:
45943 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
45944 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45945- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45946+ pax_open_kernel();
45947+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45948+ pax_close_kernel();
45949 break;
45950 case QLCNIC_PRIV_FUNC:
45951 ahw->op_mode = QLCNIC_PRIV_FUNC;
45952 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
45953- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45954+ pax_open_kernel();
45955+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45956+ pax_close_kernel();
45957 break;
45958 case QLCNIC_MGMT_FUNC:
45959 ahw->op_mode = QLCNIC_MGMT_FUNC;
45960 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45961- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45962+ pax_open_kernel();
45963+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45964+ pax_close_kernel();
45965 break;
45966 default:
45967 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
45968diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45969index 7763962..c3499a7 100644
45970--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45971+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45972@@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
45973 struct qlcnic_dump_entry *entry;
45974 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
45975 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
45976- static const struct qlcnic_dump_operations *fw_dump_ops;
45977+ const struct qlcnic_dump_operations *fw_dump_ops;
45978 struct device *dev = &adapter->pdev->dev;
45979 struct qlcnic_hardware_context *ahw;
45980 void *temp_buffer;
45981diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
45982index c737f0e..32b8682 100644
45983--- a/drivers/net/ethernet/realtek/r8169.c
45984+++ b/drivers/net/ethernet/realtek/r8169.c
45985@@ -759,22 +759,22 @@ struct rtl8169_private {
45986 struct mdio_ops {
45987 void (*write)(struct rtl8169_private *, int, int);
45988 int (*read)(struct rtl8169_private *, int);
45989- } mdio_ops;
45990+ } __no_const mdio_ops;
45991
45992 struct pll_power_ops {
45993 void (*down)(struct rtl8169_private *);
45994 void (*up)(struct rtl8169_private *);
45995- } pll_power_ops;
45996+ } __no_const pll_power_ops;
45997
45998 struct jumbo_ops {
45999 void (*enable)(struct rtl8169_private *);
46000 void (*disable)(struct rtl8169_private *);
46001- } jumbo_ops;
46002+ } __no_const jumbo_ops;
46003
46004 struct csi_ops {
46005 void (*write)(struct rtl8169_private *, int, int);
46006 u32 (*read)(struct rtl8169_private *, int);
46007- } csi_ops;
46008+ } __no_const csi_ops;
46009
46010 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
46011 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
46012diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
46013index a124103..59c74f8 100644
46014--- a/drivers/net/ethernet/sfc/ptp.c
46015+++ b/drivers/net/ethernet/sfc/ptp.c
46016@@ -541,7 +541,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
46017 ptp->start.dma_addr);
46018
46019 /* Clear flag that signals MC ready */
46020- ACCESS_ONCE(*start) = 0;
46021+ ACCESS_ONCE_RW(*start) = 0;
46022 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
46023 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
46024 EFX_BUG_ON_PARANOID(rc);
46025diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46026index 50617c5..b13724c 100644
46027--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46028+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46029@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
46030
46031 writel(value, ioaddr + MMC_CNTRL);
46032
46033- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46034- MMC_CNTRL, value);
46035+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46036+// MMC_CNTRL, value);
46037 }
46038
46039 /* To mask all all interrupts.*/
46040diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
46041index e6fe0d8..2b7d752 100644
46042--- a/drivers/net/hyperv/hyperv_net.h
46043+++ b/drivers/net/hyperv/hyperv_net.h
46044@@ -101,7 +101,7 @@ struct rndis_device {
46045
46046 enum rndis_device_state state;
46047 bool link_state;
46048- atomic_t new_req_id;
46049+ atomic_unchecked_t new_req_id;
46050
46051 spinlock_t request_lock;
46052 struct list_head req_list;
46053diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
46054index 0775f0a..d4fb316 100644
46055--- a/drivers/net/hyperv/rndis_filter.c
46056+++ b/drivers/net/hyperv/rndis_filter.c
46057@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
46058 * template
46059 */
46060 set = &rndis_msg->msg.set_req;
46061- set->req_id = atomic_inc_return(&dev->new_req_id);
46062+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46063
46064 /* Add to the request list */
46065 spin_lock_irqsave(&dev->request_lock, flags);
46066@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
46067
46068 /* Setup the rndis set */
46069 halt = &request->request_msg.msg.halt_req;
46070- halt->req_id = atomic_inc_return(&dev->new_req_id);
46071+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46072
46073 /* Ignore return since this msg is optional. */
46074 rndis_filter_send_request(dev, request);
46075diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
46076index bf0d55e..82bcfbd1 100644
46077--- a/drivers/net/ieee802154/fakehard.c
46078+++ b/drivers/net/ieee802154/fakehard.c
46079@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
46080 phy->transmit_power = 0xbf;
46081
46082 dev->netdev_ops = &fake_ops;
46083- dev->ml_priv = &fake_mlme;
46084+ dev->ml_priv = (void *)&fake_mlme;
46085
46086 priv = netdev_priv(dev);
46087 priv->phy = phy;
46088diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46089index d7e2907..1f8bfee 100644
46090--- a/drivers/net/macvlan.c
46091+++ b/drivers/net/macvlan.c
46092@@ -993,13 +993,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46093 int macvlan_link_register(struct rtnl_link_ops *ops)
46094 {
46095 /* common fields */
46096- ops->priv_size = sizeof(struct macvlan_dev);
46097- ops->validate = macvlan_validate;
46098- ops->maxtype = IFLA_MACVLAN_MAX;
46099- ops->policy = macvlan_policy;
46100- ops->changelink = macvlan_changelink;
46101- ops->get_size = macvlan_get_size;
46102- ops->fill_info = macvlan_fill_info;
46103+ pax_open_kernel();
46104+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46105+ *(void **)&ops->validate = macvlan_validate;
46106+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46107+ *(const void **)&ops->policy = macvlan_policy;
46108+ *(void **)&ops->changelink = macvlan_changelink;
46109+ *(void **)&ops->get_size = macvlan_get_size;
46110+ *(void **)&ops->fill_info = macvlan_fill_info;
46111+ pax_close_kernel();
46112
46113 return rtnl_link_register(ops);
46114 };
46115@@ -1054,7 +1056,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46116 return NOTIFY_DONE;
46117 }
46118
46119-static struct notifier_block macvlan_notifier_block __read_mostly = {
46120+static struct notifier_block macvlan_notifier_block = {
46121 .notifier_call = macvlan_device_event,
46122 };
46123
46124diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46125index 2a89da0..c17fe1d 100644
46126--- a/drivers/net/macvtap.c
46127+++ b/drivers/net/macvtap.c
46128@@ -1012,7 +1012,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46129 }
46130
46131 ret = 0;
46132- if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46133+ if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46134 put_user(q->flags, &ifr->ifr_flags))
46135 ret = -EFAULT;
46136 macvtap_put_vlan(vlan);
46137@@ -1182,7 +1182,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46138 return NOTIFY_DONE;
46139 }
46140
46141-static struct notifier_block macvtap_notifier_block __read_mostly = {
46142+static struct notifier_block macvtap_notifier_block = {
46143 .notifier_call = macvtap_device_event,
46144 };
46145
46146diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
46147index daec9b0..6428fcb 100644
46148--- a/drivers/net/phy/mdio-bitbang.c
46149+++ b/drivers/net/phy/mdio-bitbang.c
46150@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
46151 struct mdiobb_ctrl *ctrl = bus->priv;
46152
46153 module_put(ctrl->ops->owner);
46154+ mdiobus_unregister(bus);
46155 mdiobus_free(bus);
46156 }
46157 EXPORT_SYMBOL(free_mdio_bitbang);
46158diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46159index 72ff14b..11d442d 100644
46160--- a/drivers/net/ppp/ppp_generic.c
46161+++ b/drivers/net/ppp/ppp_generic.c
46162@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46163 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46164 struct ppp_stats stats;
46165 struct ppp_comp_stats cstats;
46166- char *vers;
46167
46168 switch (cmd) {
46169 case SIOCGPPPSTATS:
46170@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46171 break;
46172
46173 case SIOCGPPPVER:
46174- vers = PPP_VERSION;
46175- if (copy_to_user(addr, vers, strlen(vers) + 1))
46176+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46177 break;
46178 err = 0;
46179 break;
46180diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46181index 1252d9c..80e660b 100644
46182--- a/drivers/net/slip/slhc.c
46183+++ b/drivers/net/slip/slhc.c
46184@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46185 register struct tcphdr *thp;
46186 register struct iphdr *ip;
46187 register struct cstate *cs;
46188- int len, hdrlen;
46189+ long len, hdrlen;
46190 unsigned char *cp = icp;
46191
46192 /* We've got a compressed packet; read the change byte */
46193diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46194index b75ae5b..953c157 100644
46195--- a/drivers/net/team/team.c
46196+++ b/drivers/net/team/team.c
46197@@ -2865,7 +2865,7 @@ static int team_device_event(struct notifier_block *unused,
46198 return NOTIFY_DONE;
46199 }
46200
46201-static struct notifier_block team_notifier_block __read_mostly = {
46202+static struct notifier_block team_notifier_block = {
46203 .notifier_call = team_device_event,
46204 };
46205
46206diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46207index 55c9238..ebb6ee5 100644
46208--- a/drivers/net/tun.c
46209+++ b/drivers/net/tun.c
46210@@ -1841,7 +1841,7 @@ unlock:
46211 }
46212
46213 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46214- unsigned long arg, int ifreq_len)
46215+ unsigned long arg, size_t ifreq_len)
46216 {
46217 struct tun_file *tfile = file->private_data;
46218 struct tun_struct *tun;
46219@@ -1854,6 +1854,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46220 unsigned int ifindex;
46221 int ret;
46222
46223+ if (ifreq_len > sizeof ifr)
46224+ return -EFAULT;
46225+
46226 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46227 if (copy_from_user(&ifr, argp, ifreq_len))
46228 return -EFAULT;
46229diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46230index 1a48234..a555339 100644
46231--- a/drivers/net/usb/hso.c
46232+++ b/drivers/net/usb/hso.c
46233@@ -71,7 +71,7 @@
46234 #include <asm/byteorder.h>
46235 #include <linux/serial_core.h>
46236 #include <linux/serial.h>
46237-
46238+#include <asm/local.h>
46239
46240 #define MOD_AUTHOR "Option Wireless"
46241 #define MOD_DESCRIPTION "USB High Speed Option driver"
46242@@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46243 struct urb *urb;
46244
46245 urb = serial->rx_urb[0];
46246- if (serial->port.count > 0) {
46247+ if (atomic_read(&serial->port.count) > 0) {
46248 count = put_rxbuf_data(urb, serial);
46249 if (count == -1)
46250 return;
46251@@ -1215,7 +1215,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46252 DUMP1(urb->transfer_buffer, urb->actual_length);
46253
46254 /* Anyone listening? */
46255- if (serial->port.count == 0)
46256+ if (atomic_read(&serial->port.count) == 0)
46257 return;
46258
46259 if (status == 0) {
46260@@ -1297,8 +1297,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46261 tty_port_tty_set(&serial->port, tty);
46262
46263 /* check for port already opened, if not set the termios */
46264- serial->port.count++;
46265- if (serial->port.count == 1) {
46266+ if (atomic_inc_return(&serial->port.count) == 1) {
46267 serial->rx_state = RX_IDLE;
46268 /* Force default termio settings */
46269 _hso_serial_set_termios(tty, NULL);
46270@@ -1310,7 +1309,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46271 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46272 if (result) {
46273 hso_stop_serial_device(serial->parent);
46274- serial->port.count--;
46275+ atomic_dec(&serial->port.count);
46276 kref_put(&serial->parent->ref, hso_serial_ref_free);
46277 }
46278 } else {
46279@@ -1347,10 +1346,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46280
46281 /* reset the rts and dtr */
46282 /* do the actual close */
46283- serial->port.count--;
46284+ atomic_dec(&serial->port.count);
46285
46286- if (serial->port.count <= 0) {
46287- serial->port.count = 0;
46288+ if (atomic_read(&serial->port.count) <= 0) {
46289+ atomic_set(&serial->port.count, 0);
46290 tty_port_tty_set(&serial->port, NULL);
46291 if (!usb_gone)
46292 hso_stop_serial_device(serial->parent);
46293@@ -1426,7 +1425,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46294
46295 /* the actual setup */
46296 spin_lock_irqsave(&serial->serial_lock, flags);
46297- if (serial->port.count)
46298+ if (atomic_read(&serial->port.count))
46299 _hso_serial_set_termios(tty, old);
46300 else
46301 tty->termios = *old;
46302@@ -1895,7 +1894,7 @@ static void intr_callback(struct urb *urb)
46303 D1("Pending read interrupt on port %d\n", i);
46304 spin_lock(&serial->serial_lock);
46305 if (serial->rx_state == RX_IDLE &&
46306- serial->port.count > 0) {
46307+ atomic_read(&serial->port.count) > 0) {
46308 /* Setup and send a ctrl req read on
46309 * port i */
46310 if (!serial->rx_urb_filled[0]) {
46311@@ -3071,7 +3070,7 @@ static int hso_resume(struct usb_interface *iface)
46312 /* Start all serial ports */
46313 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46314 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46315- if (dev2ser(serial_table[i])->port.count) {
46316+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46317 result =
46318 hso_start_serial_device(serial_table[i], GFP_NOIO);
46319 hso_kick_transmit(dev2ser(serial_table[i]));
46320diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46321index a79e9d3..78cd4fa 100644
46322--- a/drivers/net/usb/sierra_net.c
46323+++ b/drivers/net/usb/sierra_net.c
46324@@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
46325 /* atomic counter partially included in MAC address to make sure 2 devices
46326 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46327 */
46328-static atomic_t iface_counter = ATOMIC_INIT(0);
46329+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46330
46331 /*
46332 * SYNC Timer Delay definition used to set the expiry time
46333@@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46334 dev->net->netdev_ops = &sierra_net_device_ops;
46335
46336 /* change MAC addr to include, ifacenum, and to be unique */
46337- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46338+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46339 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46340
46341 /* we will have to manufacture ethernet headers, prepare template */
46342diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46343index 0247973..088193a 100644
46344--- a/drivers/net/vxlan.c
46345+++ b/drivers/net/vxlan.c
46346@@ -2615,7 +2615,7 @@ nla_put_failure:
46347 return -EMSGSIZE;
46348 }
46349
46350-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46351+static struct rtnl_link_ops vxlan_link_ops = {
46352 .kind = "vxlan",
46353 .maxtype = IFLA_VXLAN_MAX,
46354 .policy = vxlan_policy,
46355diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46356index 5920c99..ff2e4a5 100644
46357--- a/drivers/net/wan/lmc/lmc_media.c
46358+++ b/drivers/net/wan/lmc/lmc_media.c
46359@@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46360 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46361
46362 lmc_media_t lmc_ds3_media = {
46363- lmc_ds3_init, /* special media init stuff */
46364- lmc_ds3_default, /* reset to default state */
46365- lmc_ds3_set_status, /* reset status to state provided */
46366- lmc_dummy_set_1, /* set clock source */
46367- lmc_dummy_set2_1, /* set line speed */
46368- lmc_ds3_set_100ft, /* set cable length */
46369- lmc_ds3_set_scram, /* set scrambler */
46370- lmc_ds3_get_link_status, /* get link status */
46371- lmc_dummy_set_1, /* set link status */
46372- lmc_ds3_set_crc_length, /* set CRC length */
46373- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46374- lmc_ds3_watchdog
46375+ .init = lmc_ds3_init, /* special media init stuff */
46376+ .defaults = lmc_ds3_default, /* reset to default state */
46377+ .set_status = lmc_ds3_set_status, /* reset status to state provided */
46378+ .set_clock_source = lmc_dummy_set_1, /* set clock source */
46379+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46380+ .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46381+ .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46382+ .get_link_status = lmc_ds3_get_link_status, /* get link status */
46383+ .set_link_status = lmc_dummy_set_1, /* set link status */
46384+ .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46385+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46386+ .watchdog = lmc_ds3_watchdog
46387 };
46388
46389 lmc_media_t lmc_hssi_media = {
46390- lmc_hssi_init, /* special media init stuff */
46391- lmc_hssi_default, /* reset to default state */
46392- lmc_hssi_set_status, /* reset status to state provided */
46393- lmc_hssi_set_clock, /* set clock source */
46394- lmc_dummy_set2_1, /* set line speed */
46395- lmc_dummy_set_1, /* set cable length */
46396- lmc_dummy_set_1, /* set scrambler */
46397- lmc_hssi_get_link_status, /* get link status */
46398- lmc_hssi_set_link_status, /* set link status */
46399- lmc_hssi_set_crc_length, /* set CRC length */
46400- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46401- lmc_hssi_watchdog
46402+ .init = lmc_hssi_init, /* special media init stuff */
46403+ .defaults = lmc_hssi_default, /* reset to default state */
46404+ .set_status = lmc_hssi_set_status, /* reset status to state provided */
46405+ .set_clock_source = lmc_hssi_set_clock, /* set clock source */
46406+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46407+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46408+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46409+ .get_link_status = lmc_hssi_get_link_status, /* get link status */
46410+ .set_link_status = lmc_hssi_set_link_status, /* set link status */
46411+ .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
46412+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46413+ .watchdog = lmc_hssi_watchdog
46414 };
46415
46416-lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
46417- lmc_ssi_default, /* reset to default state */
46418- lmc_ssi_set_status, /* reset status to state provided */
46419- lmc_ssi_set_clock, /* set clock source */
46420- lmc_ssi_set_speed, /* set line speed */
46421- lmc_dummy_set_1, /* set cable length */
46422- lmc_dummy_set_1, /* set scrambler */
46423- lmc_ssi_get_link_status, /* get link status */
46424- lmc_ssi_set_link_status, /* set link status */
46425- lmc_ssi_set_crc_length, /* set CRC length */
46426- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46427- lmc_ssi_watchdog
46428+lmc_media_t lmc_ssi_media = {
46429+ .init = lmc_ssi_init, /* special media init stuff */
46430+ .defaults = lmc_ssi_default, /* reset to default state */
46431+ .set_status = lmc_ssi_set_status, /* reset status to state provided */
46432+ .set_clock_source = lmc_ssi_set_clock, /* set clock source */
46433+ .set_speed = lmc_ssi_set_speed, /* set line speed */
46434+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46435+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46436+ .get_link_status = lmc_ssi_get_link_status, /* get link status */
46437+ .set_link_status = lmc_ssi_set_link_status, /* set link status */
46438+ .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
46439+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46440+ .watchdog = lmc_ssi_watchdog
46441 };
46442
46443 lmc_media_t lmc_t1_media = {
46444- lmc_t1_init, /* special media init stuff */
46445- lmc_t1_default, /* reset to default state */
46446- lmc_t1_set_status, /* reset status to state provided */
46447- lmc_t1_set_clock, /* set clock source */
46448- lmc_dummy_set2_1, /* set line speed */
46449- lmc_dummy_set_1, /* set cable length */
46450- lmc_dummy_set_1, /* set scrambler */
46451- lmc_t1_get_link_status, /* get link status */
46452- lmc_dummy_set_1, /* set link status */
46453- lmc_t1_set_crc_length, /* set CRC length */
46454- lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46455- lmc_t1_watchdog
46456+ .init = lmc_t1_init, /* special media init stuff */
46457+ .defaults = lmc_t1_default, /* reset to default state */
46458+ .set_status = lmc_t1_set_status, /* reset status to state provided */
46459+ .set_clock_source = lmc_t1_set_clock, /* set clock source */
46460+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46461+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46462+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46463+ .get_link_status = lmc_t1_get_link_status, /* get link status */
46464+ .set_link_status = lmc_dummy_set_1, /* set link status */
46465+ .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
46466+ .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46467+ .watchdog = lmc_t1_watchdog
46468 };
46469
46470 static void
46471diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
46472index feacc3b..5bac0de 100644
46473--- a/drivers/net/wan/z85230.c
46474+++ b/drivers/net/wan/z85230.c
46475@@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
46476
46477 struct z8530_irqhandler z8530_sync =
46478 {
46479- z8530_rx,
46480- z8530_tx,
46481- z8530_status
46482+ .rx = z8530_rx,
46483+ .tx = z8530_tx,
46484+ .status = z8530_status
46485 };
46486
46487 EXPORT_SYMBOL(z8530_sync);
46488@@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
46489 }
46490
46491 static struct z8530_irqhandler z8530_dma_sync = {
46492- z8530_dma_rx,
46493- z8530_dma_tx,
46494- z8530_dma_status
46495+ .rx = z8530_dma_rx,
46496+ .tx = z8530_dma_tx,
46497+ .status = z8530_dma_status
46498 };
46499
46500 static struct z8530_irqhandler z8530_txdma_sync = {
46501- z8530_rx,
46502- z8530_dma_tx,
46503- z8530_dma_status
46504+ .rx = z8530_rx,
46505+ .tx = z8530_dma_tx,
46506+ .status = z8530_dma_status
46507 };
46508
46509 /**
46510@@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
46511
46512 struct z8530_irqhandler z8530_nop=
46513 {
46514- z8530_rx_clear,
46515- z8530_tx_clear,
46516- z8530_status_clear
46517+ .rx = z8530_rx_clear,
46518+ .tx = z8530_tx_clear,
46519+ .status = z8530_status_clear
46520 };
46521
46522
46523diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
46524index 0b60295..b8bfa5b 100644
46525--- a/drivers/net/wimax/i2400m/rx.c
46526+++ b/drivers/net/wimax/i2400m/rx.c
46527@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
46528 if (i2400m->rx_roq == NULL)
46529 goto error_roq_alloc;
46530
46531- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
46532+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
46533 GFP_KERNEL);
46534 if (rd == NULL) {
46535 result = -ENOMEM;
46536diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
46537index edf4b57..68b51c0 100644
46538--- a/drivers/net/wireless/airo.c
46539+++ b/drivers/net/wireless/airo.c
46540@@ -7843,7 +7843,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
46541 struct airo_info *ai = dev->ml_priv;
46542 int ridcode;
46543 int enabled;
46544- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46545+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46546 unsigned char *iobuf;
46547
46548 /* Only super-user can write RIDs */
46549diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
46550index 34c8a33..3261fdc 100644
46551--- a/drivers/net/wireless/at76c50x-usb.c
46552+++ b/drivers/net/wireless/at76c50x-usb.c
46553@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
46554 }
46555
46556 /* Convert timeout from the DFU status to jiffies */
46557-static inline unsigned long at76_get_timeout(struct dfu_status *s)
46558+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
46559 {
46560 return msecs_to_jiffies((s->poll_timeout[2] << 16)
46561 | (s->poll_timeout[1] << 8)
46562diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
46563index edae50b..b24278c 100644
46564--- a/drivers/net/wireless/ath/ath10k/htc.c
46565+++ b/drivers/net/wireless/ath/ath10k/htc.c
46566@@ -842,7 +842,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
46567 /* registered target arrival callback from the HIF layer */
46568 int ath10k_htc_init(struct ath10k *ar)
46569 {
46570- struct ath10k_hif_cb htc_callbacks;
46571+ static struct ath10k_hif_cb htc_callbacks = {
46572+ .rx_completion = ath10k_htc_rx_completion_handler,
46573+ .tx_completion = ath10k_htc_tx_completion_handler,
46574+ };
46575 struct ath10k_htc_ep *ep = NULL;
46576 struct ath10k_htc *htc = &ar->htc;
46577
46578@@ -852,8 +855,6 @@ int ath10k_htc_init(struct ath10k *ar)
46579 ath10k_htc_reset_endpoint_states(htc);
46580
46581 /* setup HIF layer callbacks */
46582- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
46583- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
46584 htc->ar = ar;
46585
46586 /* Get HIF default pipe for HTC message exchange */
46587diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
46588index 4716d33..a688310 100644
46589--- a/drivers/net/wireless/ath/ath10k/htc.h
46590+++ b/drivers/net/wireless/ath/ath10k/htc.h
46591@@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
46592
46593 struct ath10k_htc_ops {
46594 void (*target_send_suspend_complete)(struct ath10k *ar);
46595-};
46596+} __no_const;
46597
46598 struct ath10k_htc_ep_ops {
46599 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
46600 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
46601 void (*ep_tx_credits)(struct ath10k *);
46602-};
46603+} __no_const;
46604
46605 /* service connection information */
46606 struct ath10k_htc_svc_conn_req {
46607diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46608index a366d6b..b6f28f8 100644
46609--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46610+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46611@@ -218,8 +218,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46612 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
46613 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
46614
46615- ACCESS_ONCE(ads->ds_link) = i->link;
46616- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
46617+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
46618+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
46619
46620 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
46621 ctl6 = SM(i->keytype, AR_EncrType);
46622@@ -233,26 +233,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46623
46624 if ((i->is_first || i->is_last) &&
46625 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
46626- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
46627+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
46628 | set11nTries(i->rates, 1)
46629 | set11nTries(i->rates, 2)
46630 | set11nTries(i->rates, 3)
46631 | (i->dur_update ? AR_DurUpdateEna : 0)
46632 | SM(0, AR_BurstDur);
46633
46634- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
46635+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
46636 | set11nRate(i->rates, 1)
46637 | set11nRate(i->rates, 2)
46638 | set11nRate(i->rates, 3);
46639 } else {
46640- ACCESS_ONCE(ads->ds_ctl2) = 0;
46641- ACCESS_ONCE(ads->ds_ctl3) = 0;
46642+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
46643+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
46644 }
46645
46646 if (!i->is_first) {
46647- ACCESS_ONCE(ads->ds_ctl0) = 0;
46648- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46649- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46650+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
46651+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46652+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46653 return;
46654 }
46655
46656@@ -277,7 +277,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46657 break;
46658 }
46659
46660- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46661+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46662 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46663 | SM(i->txpower, AR_XmitPower)
46664 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46665@@ -287,19 +287,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46666 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
46667 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
46668
46669- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46670- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46671+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46672+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46673
46674 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
46675 return;
46676
46677- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46678+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46679 | set11nPktDurRTSCTS(i->rates, 1);
46680
46681- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46682+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46683 | set11nPktDurRTSCTS(i->rates, 3);
46684
46685- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46686+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46687 | set11nRateFlags(i->rates, 1)
46688 | set11nRateFlags(i->rates, 2)
46689 | set11nRateFlags(i->rates, 3)
46690diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46691index f6c5c1b..6058354 100644
46692--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46693+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46694@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46695 (i->qcu << AR_TxQcuNum_S) | desc_len;
46696
46697 checksum += val;
46698- ACCESS_ONCE(ads->info) = val;
46699+ ACCESS_ONCE_RW(ads->info) = val;
46700
46701 checksum += i->link;
46702- ACCESS_ONCE(ads->link) = i->link;
46703+ ACCESS_ONCE_RW(ads->link) = i->link;
46704
46705 checksum += i->buf_addr[0];
46706- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
46707+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
46708 checksum += i->buf_addr[1];
46709- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
46710+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
46711 checksum += i->buf_addr[2];
46712- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
46713+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
46714 checksum += i->buf_addr[3];
46715- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
46716+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
46717
46718 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
46719- ACCESS_ONCE(ads->ctl3) = val;
46720+ ACCESS_ONCE_RW(ads->ctl3) = val;
46721 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
46722- ACCESS_ONCE(ads->ctl5) = val;
46723+ ACCESS_ONCE_RW(ads->ctl5) = val;
46724 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
46725- ACCESS_ONCE(ads->ctl7) = val;
46726+ ACCESS_ONCE_RW(ads->ctl7) = val;
46727 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
46728- ACCESS_ONCE(ads->ctl9) = val;
46729+ ACCESS_ONCE_RW(ads->ctl9) = val;
46730
46731 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
46732- ACCESS_ONCE(ads->ctl10) = checksum;
46733+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
46734
46735 if (i->is_first || i->is_last) {
46736- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
46737+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
46738 | set11nTries(i->rates, 1)
46739 | set11nTries(i->rates, 2)
46740 | set11nTries(i->rates, 3)
46741 | (i->dur_update ? AR_DurUpdateEna : 0)
46742 | SM(0, AR_BurstDur);
46743
46744- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
46745+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
46746 | set11nRate(i->rates, 1)
46747 | set11nRate(i->rates, 2)
46748 | set11nRate(i->rates, 3);
46749 } else {
46750- ACCESS_ONCE(ads->ctl13) = 0;
46751- ACCESS_ONCE(ads->ctl14) = 0;
46752+ ACCESS_ONCE_RW(ads->ctl13) = 0;
46753+ ACCESS_ONCE_RW(ads->ctl14) = 0;
46754 }
46755
46756 ads->ctl20 = 0;
46757@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46758
46759 ctl17 = SM(i->keytype, AR_EncrType);
46760 if (!i->is_first) {
46761- ACCESS_ONCE(ads->ctl11) = 0;
46762- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46763- ACCESS_ONCE(ads->ctl15) = 0;
46764- ACCESS_ONCE(ads->ctl16) = 0;
46765- ACCESS_ONCE(ads->ctl17) = ctl17;
46766- ACCESS_ONCE(ads->ctl18) = 0;
46767- ACCESS_ONCE(ads->ctl19) = 0;
46768+ ACCESS_ONCE_RW(ads->ctl11) = 0;
46769+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46770+ ACCESS_ONCE_RW(ads->ctl15) = 0;
46771+ ACCESS_ONCE_RW(ads->ctl16) = 0;
46772+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46773+ ACCESS_ONCE_RW(ads->ctl18) = 0;
46774+ ACCESS_ONCE_RW(ads->ctl19) = 0;
46775 return;
46776 }
46777
46778- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46779+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46780 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46781 | SM(i->txpower, AR_XmitPower)
46782 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46783@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46784 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
46785 ctl12 |= SM(val, AR_PAPRDChainMask);
46786
46787- ACCESS_ONCE(ads->ctl12) = ctl12;
46788- ACCESS_ONCE(ads->ctl17) = ctl17;
46789+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
46790+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46791
46792- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46793+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46794 | set11nPktDurRTSCTS(i->rates, 1);
46795
46796- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46797+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46798 | set11nPktDurRTSCTS(i->rates, 3);
46799
46800- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
46801+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
46802 | set11nRateFlags(i->rates, 1)
46803 | set11nRateFlags(i->rates, 2)
46804 | set11nRateFlags(i->rates, 3)
46805 | SM(i->rtscts_rate, AR_RTSCTSRate);
46806
46807- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
46808+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
46809 }
46810
46811 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
46812diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
46813index a2c9a5d..b52273e 100644
46814--- a/drivers/net/wireless/ath/ath9k/hw.h
46815+++ b/drivers/net/wireless/ath/ath9k/hw.h
46816@@ -635,7 +635,7 @@ struct ath_hw_private_ops {
46817
46818 /* ANI */
46819 void (*ani_cache_ini_regs)(struct ath_hw *ah);
46820-};
46821+} __no_const;
46822
46823 /**
46824 * struct ath_spec_scan - parameters for Atheros spectral scan
46825@@ -711,7 +711,7 @@ struct ath_hw_ops {
46826 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
46827 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
46828 #endif
46829-};
46830+} __no_const;
46831
46832 struct ath_nf_limits {
46833 s16 max;
46834diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
46835index 92190da..f3a4c4c 100644
46836--- a/drivers/net/wireless/b43/phy_lp.c
46837+++ b/drivers/net/wireless/b43/phy_lp.c
46838@@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
46839 {
46840 struct ssb_bus *bus = dev->dev->sdev->bus;
46841
46842- static const struct b206x_channel *chandata = NULL;
46843+ const struct b206x_channel *chandata = NULL;
46844 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
46845 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
46846 u16 old_comm15, scale;
46847diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
46848index dea3b50..543db99 100644
46849--- a/drivers/net/wireless/iwlegacy/3945-mac.c
46850+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
46851@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
46852 */
46853 if (il3945_mod_params.disable_hw_scan) {
46854 D_INFO("Disabling hw_scan\n");
46855- il3945_mac_ops.hw_scan = NULL;
46856+ pax_open_kernel();
46857+ *(void **)&il3945_mac_ops.hw_scan = NULL;
46858+ pax_close_kernel();
46859 }
46860
46861 D_INFO("*** LOAD DRIVER ***\n");
46862diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46863index d94f8ab..5b568c8 100644
46864--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46865+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46866@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
46867 {
46868 struct iwl_priv *priv = file->private_data;
46869 char buf[64];
46870- int buf_size;
46871+ size_t buf_size;
46872 u32 offset, len;
46873
46874 memset(buf, 0, sizeof(buf));
46875@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
46876 struct iwl_priv *priv = file->private_data;
46877
46878 char buf[8];
46879- int buf_size;
46880+ size_t buf_size;
46881 u32 reset_flag;
46882
46883 memset(buf, 0, sizeof(buf));
46884@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
46885 {
46886 struct iwl_priv *priv = file->private_data;
46887 char buf[8];
46888- int buf_size;
46889+ size_t buf_size;
46890 int ht40;
46891
46892 memset(buf, 0, sizeof(buf));
46893@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
46894 {
46895 struct iwl_priv *priv = file->private_data;
46896 char buf[8];
46897- int buf_size;
46898+ size_t buf_size;
46899 int value;
46900
46901 memset(buf, 0, sizeof(buf));
46902@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
46903 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
46904 DEBUGFS_READ_FILE_OPS(current_sleep_command);
46905
46906-static const char *fmt_value = " %-30s %10u\n";
46907-static const char *fmt_hex = " %-30s 0x%02X\n";
46908-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
46909-static const char *fmt_header =
46910+static const char fmt_value[] = " %-30s %10u\n";
46911+static const char fmt_hex[] = " %-30s 0x%02X\n";
46912+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
46913+static const char fmt_header[] =
46914 "%-32s current cumulative delta max\n";
46915
46916 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
46917@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
46918 {
46919 struct iwl_priv *priv = file->private_data;
46920 char buf[8];
46921- int buf_size;
46922+ size_t buf_size;
46923 int clear;
46924
46925 memset(buf, 0, sizeof(buf));
46926@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
46927 {
46928 struct iwl_priv *priv = file->private_data;
46929 char buf[8];
46930- int buf_size;
46931+ size_t buf_size;
46932 int trace;
46933
46934 memset(buf, 0, sizeof(buf));
46935@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
46936 {
46937 struct iwl_priv *priv = file->private_data;
46938 char buf[8];
46939- int buf_size;
46940+ size_t buf_size;
46941 int missed;
46942
46943 memset(buf, 0, sizeof(buf));
46944@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
46945
46946 struct iwl_priv *priv = file->private_data;
46947 char buf[8];
46948- int buf_size;
46949+ size_t buf_size;
46950 int plcp;
46951
46952 memset(buf, 0, sizeof(buf));
46953@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
46954
46955 struct iwl_priv *priv = file->private_data;
46956 char buf[8];
46957- int buf_size;
46958+ size_t buf_size;
46959 int flush;
46960
46961 memset(buf, 0, sizeof(buf));
46962@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
46963
46964 struct iwl_priv *priv = file->private_data;
46965 char buf[8];
46966- int buf_size;
46967+ size_t buf_size;
46968 int rts;
46969
46970 if (!priv->cfg->ht_params)
46971@@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
46972 {
46973 struct iwl_priv *priv = file->private_data;
46974 char buf[8];
46975- int buf_size;
46976+ size_t buf_size;
46977
46978 memset(buf, 0, sizeof(buf));
46979 buf_size = min(count, sizeof(buf) - 1);
46980@@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
46981 struct iwl_priv *priv = file->private_data;
46982 u32 event_log_flag;
46983 char buf[8];
46984- int buf_size;
46985+ size_t buf_size;
46986
46987 /* check that the interface is up */
46988 if (!iwl_is_ready(priv))
46989@@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
46990 struct iwl_priv *priv = file->private_data;
46991 char buf[8];
46992 u32 calib_disabled;
46993- int buf_size;
46994+ size_t buf_size;
46995
46996 memset(buf, 0, sizeof(buf));
46997 buf_size = min(count, sizeof(buf) - 1);
46998diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
46999index 7aad766..06addb4 100644
47000--- a/drivers/net/wireless/iwlwifi/dvm/main.c
47001+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
47002@@ -1123,7 +1123,7 @@ static void iwl_option_config(struct iwl_priv *priv)
47003 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47004 {
47005 struct iwl_nvm_data *data = priv->nvm_data;
47006- char *debug_msg;
47007+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47008
47009 if (data->sku_cap_11n_enable &&
47010 !priv->cfg->ht_params) {
47011@@ -1137,7 +1137,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47012 return -EINVAL;
47013 }
47014
47015- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47016 IWL_DEBUG_INFO(priv, debug_msg,
47017 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
47018 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
47019diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
47020index f53ef83..5e34bcb 100644
47021--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
47022+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
47023@@ -1390,7 +1390,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
47024 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
47025
47026 char buf[8];
47027- int buf_size;
47028+ size_t buf_size;
47029 u32 reset_flag;
47030
47031 memset(buf, 0, sizeof(buf));
47032@@ -1411,7 +1411,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
47033 {
47034 struct iwl_trans *trans = file->private_data;
47035 char buf[8];
47036- int buf_size;
47037+ size_t buf_size;
47038 int csr;
47039
47040 memset(buf, 0, sizeof(buf));
47041diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
47042index a1b32ee..94b3c3d 100644
47043--- a/drivers/net/wireless/mac80211_hwsim.c
47044+++ b/drivers/net/wireless/mac80211_hwsim.c
47045@@ -2224,25 +2224,19 @@ static int __init init_mac80211_hwsim(void)
47046
47047 if (channels > 1) {
47048 hwsim_if_comb.num_different_channels = channels;
47049- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
47050- mac80211_hwsim_ops.cancel_hw_scan =
47051- mac80211_hwsim_cancel_hw_scan;
47052- mac80211_hwsim_ops.sw_scan_start = NULL;
47053- mac80211_hwsim_ops.sw_scan_complete = NULL;
47054- mac80211_hwsim_ops.remain_on_channel =
47055- mac80211_hwsim_roc;
47056- mac80211_hwsim_ops.cancel_remain_on_channel =
47057- mac80211_hwsim_croc;
47058- mac80211_hwsim_ops.add_chanctx =
47059- mac80211_hwsim_add_chanctx;
47060- mac80211_hwsim_ops.remove_chanctx =
47061- mac80211_hwsim_remove_chanctx;
47062- mac80211_hwsim_ops.change_chanctx =
47063- mac80211_hwsim_change_chanctx;
47064- mac80211_hwsim_ops.assign_vif_chanctx =
47065- mac80211_hwsim_assign_vif_chanctx;
47066- mac80211_hwsim_ops.unassign_vif_chanctx =
47067- mac80211_hwsim_unassign_vif_chanctx;
47068+ pax_open_kernel();
47069+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
47070+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47071+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
47072+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
47073+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
47074+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47075+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47076+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47077+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47078+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47079+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47080+ pax_close_kernel();
47081 }
47082
47083 spin_lock_init(&hwsim_radio_lock);
47084diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47085index 8169a85..7fa3b47 100644
47086--- a/drivers/net/wireless/rndis_wlan.c
47087+++ b/drivers/net/wireless/rndis_wlan.c
47088@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47089
47090 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47091
47092- if (rts_threshold < 0 || rts_threshold > 2347)
47093+ if (rts_threshold > 2347)
47094 rts_threshold = 2347;
47095
47096 tmp = cpu_to_le32(rts_threshold);
47097diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47098index e4ba2ce..63d7417 100644
47099--- a/drivers/net/wireless/rt2x00/rt2x00.h
47100+++ b/drivers/net/wireless/rt2x00/rt2x00.h
47101@@ -377,7 +377,7 @@ struct rt2x00_intf {
47102 * for hardware which doesn't support hardware
47103 * sequence counting.
47104 */
47105- atomic_t seqno;
47106+ atomic_unchecked_t seqno;
47107 };
47108
47109 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47110diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47111index a5d38e8..d3c24ea 100644
47112--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47113+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47114@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47115 * sequence counter given by mac80211.
47116 */
47117 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47118- seqno = atomic_add_return(0x10, &intf->seqno);
47119+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47120 else
47121- seqno = atomic_read(&intf->seqno);
47122+ seqno = atomic_read_unchecked(&intf->seqno);
47123
47124 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47125 hdr->seq_ctrl |= cpu_to_le16(seqno);
47126diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47127index e2b3d9c..67a5184 100644
47128--- a/drivers/net/wireless/ti/wl1251/sdio.c
47129+++ b/drivers/net/wireless/ti/wl1251/sdio.c
47130@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47131
47132 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47133
47134- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47135- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47136+ pax_open_kernel();
47137+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47138+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47139+ pax_close_kernel();
47140
47141 wl1251_info("using dedicated interrupt line");
47142 } else {
47143- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47144- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47145+ pax_open_kernel();
47146+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47147+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47148+ pax_close_kernel();
47149
47150 wl1251_info("using SDIO interrupt");
47151 }
47152diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47153index be7129b..4161356 100644
47154--- a/drivers/net/wireless/ti/wl12xx/main.c
47155+++ b/drivers/net/wireless/ti/wl12xx/main.c
47156@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47157 sizeof(wl->conf.mem));
47158
47159 /* read data preparation is only needed by wl127x */
47160- wl->ops->prepare_read = wl127x_prepare_read;
47161+ pax_open_kernel();
47162+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47163+ pax_close_kernel();
47164
47165 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47166 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47167@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47168 sizeof(wl->conf.mem));
47169
47170 /* read data preparation is only needed by wl127x */
47171- wl->ops->prepare_read = wl127x_prepare_read;
47172+ pax_open_kernel();
47173+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47174+ pax_close_kernel();
47175
47176 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47177 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47178diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47179index ec37b16..7e34d66 100644
47180--- a/drivers/net/wireless/ti/wl18xx/main.c
47181+++ b/drivers/net/wireless/ti/wl18xx/main.c
47182@@ -1823,8 +1823,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47183 }
47184
47185 if (!checksum_param) {
47186- wl18xx_ops.set_rx_csum = NULL;
47187- wl18xx_ops.init_vif = NULL;
47188+ pax_open_kernel();
47189+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
47190+ *(void **)&wl18xx_ops.init_vif = NULL;
47191+ pax_close_kernel();
47192 }
47193
47194 /* Enable 11a Band only if we have 5G antennas */
47195diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47196index 84d94f5..bd6c61c 100644
47197--- a/drivers/net/wireless/zd1211rw/zd_usb.c
47198+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47199@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
47200 {
47201 struct zd_usb *usb = urb->context;
47202 struct zd_usb_interrupt *intr = &usb->intr;
47203- int len;
47204+ unsigned int len;
47205 u16 int_num;
47206
47207 ZD_ASSERT(in_interrupt());
47208diff --git a/drivers/net/xen-netback/common.h b/drivers/net/xen-netback/common.h
47209index c47794b..6668d03 100644
47210--- a/drivers/net/xen-netback/common.h
47211+++ b/drivers/net/xen-netback/common.h
47212@@ -113,6 +113,11 @@ struct xenvif {
47213 domid_t domid;
47214 unsigned int handle;
47215
47216+ /* Is this interface disabled? True when backend discovers
47217+ * frontend is rogue.
47218+ */
47219+ bool disabled;
47220+
47221 /* Use NAPI for guest TX */
47222 struct napi_struct napi;
47223 /* When feature-split-event-channels = 0, tx_irq = rx_irq. */
47224diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c
47225index fff8cddf..a2ef2e6 100644
47226--- a/drivers/net/xen-netback/interface.c
47227+++ b/drivers/net/xen-netback/interface.c
47228@@ -67,6 +67,15 @@ static int xenvif_poll(struct napi_struct *napi, int budget)
47229 struct xenvif *vif = container_of(napi, struct xenvif, napi);
47230 int work_done;
47231
47232+ /* This vif is rogue, we pretend we've there is nothing to do
47233+ * for this vif to deschedule it from NAPI. But this interface
47234+ * will be turned off in thread context later.
47235+ */
47236+ if (unlikely(vif->disabled)) {
47237+ napi_complete(napi);
47238+ return 0;
47239+ }
47240+
47241 work_done = xenvif_tx_action(vif, budget);
47242
47243 if (work_done < budget) {
47244@@ -323,6 +332,8 @@ struct xenvif *xenvif_alloc(struct device *parent, domid_t domid,
47245 vif->ip_csum = 1;
47246 vif->dev = dev;
47247
47248+ vif->disabled = false;
47249+
47250 vif->credit_bytes = vif->remaining_credit = ~0UL;
47251 vif->credit_usec = 0UL;
47252 init_timer(&vif->credit_timeout);
47253diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
47254index 7842555..c69d1ad 100644
47255--- a/drivers/net/xen-netback/netback.c
47256+++ b/drivers/net/xen-netback/netback.c
47257@@ -756,7 +756,8 @@ static void xenvif_tx_err(struct xenvif *vif,
47258 static void xenvif_fatal_tx_err(struct xenvif *vif)
47259 {
47260 netdev_err(vif->dev, "fatal error; disabling device\n");
47261- xenvif_carrier_off(vif);
47262+ vif->disabled = true;
47263+ xenvif_kick_thread(vif);
47264 }
47265
47266 static int xenvif_count_requests(struct xenvif *vif,
47267@@ -1483,7 +1484,7 @@ static unsigned xenvif_tx_build_gops(struct xenvif *vif, int budget)
47268 vif->tx.sring->req_prod, vif->tx.req_cons,
47269 XEN_NETIF_TX_RING_SIZE);
47270 xenvif_fatal_tx_err(vif);
47271- continue;
47272+ break;
47273 }
47274
47275 work_to_do = RING_HAS_UNCONSUMED_REQUESTS(&vif->tx);
47276@@ -1877,7 +1878,18 @@ int xenvif_kthread(void *data)
47277 while (!kthread_should_stop()) {
47278 wait_event_interruptible(vif->wq,
47279 rx_work_todo(vif) ||
47280+ vif->disabled ||
47281 kthread_should_stop());
47282+
47283+ /* This frontend is found to be rogue, disable it in
47284+ * kthread context. Currently this is only set when
47285+ * netback finds out frontend sends malformed packet,
47286+ * but we cannot disable the interface in softirq
47287+ * context so we defer it here.
47288+ */
47289+ if (unlikely(vif->disabled && netif_carrier_ok(vif->dev)))
47290+ xenvif_carrier_off(vif);
47291+
47292 if (kthread_should_stop())
47293 break;
47294
47295diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47296index 7130864..00e64de 100644
47297--- a/drivers/nfc/nfcwilink.c
47298+++ b/drivers/nfc/nfcwilink.c
47299@@ -498,7 +498,7 @@ static struct nci_ops nfcwilink_ops = {
47300
47301 static int nfcwilink_probe(struct platform_device *pdev)
47302 {
47303- static struct nfcwilink *drv;
47304+ struct nfcwilink *drv;
47305 int rc;
47306 __u32 protocols;
47307
47308diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47309index d93b2b6..ae50401 100644
47310--- a/drivers/oprofile/buffer_sync.c
47311+++ b/drivers/oprofile/buffer_sync.c
47312@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47313 if (cookie == NO_COOKIE)
47314 offset = pc;
47315 if (cookie == INVALID_COOKIE) {
47316- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47317+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47318 offset = pc;
47319 }
47320 if (cookie != last_cookie) {
47321@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47322 /* add userspace sample */
47323
47324 if (!mm) {
47325- atomic_inc(&oprofile_stats.sample_lost_no_mm);
47326+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47327 return 0;
47328 }
47329
47330 cookie = lookup_dcookie(mm, s->eip, &offset);
47331
47332 if (cookie == INVALID_COOKIE) {
47333- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47334+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47335 return 0;
47336 }
47337
47338@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47339 /* ignore backtraces if failed to add a sample */
47340 if (state == sb_bt_start) {
47341 state = sb_bt_ignore;
47342- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47343+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47344 }
47345 }
47346 release_mm(mm);
47347diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47348index c0cc4e7..44d4e54 100644
47349--- a/drivers/oprofile/event_buffer.c
47350+++ b/drivers/oprofile/event_buffer.c
47351@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47352 }
47353
47354 if (buffer_pos == buffer_size) {
47355- atomic_inc(&oprofile_stats.event_lost_overflow);
47356+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47357 return;
47358 }
47359
47360diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47361index ed2c3ec..deda85a 100644
47362--- a/drivers/oprofile/oprof.c
47363+++ b/drivers/oprofile/oprof.c
47364@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47365 if (oprofile_ops.switch_events())
47366 return;
47367
47368- atomic_inc(&oprofile_stats.multiplex_counter);
47369+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47370 start_switch_worker();
47371 }
47372
47373diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47374index ee2cfce..7f8f699 100644
47375--- a/drivers/oprofile/oprofile_files.c
47376+++ b/drivers/oprofile/oprofile_files.c
47377@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47378
47379 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47380
47381-static ssize_t timeout_read(struct file *file, char __user *buf,
47382+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47383 size_t count, loff_t *offset)
47384 {
47385 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47386diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47387index 59659ce..6c860a0 100644
47388--- a/drivers/oprofile/oprofile_stats.c
47389+++ b/drivers/oprofile/oprofile_stats.c
47390@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47391 cpu_buf->sample_invalid_eip = 0;
47392 }
47393
47394- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47395- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47396- atomic_set(&oprofile_stats.event_lost_overflow, 0);
47397- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47398- atomic_set(&oprofile_stats.multiplex_counter, 0);
47399+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47400+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47401+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47402+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47403+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47404 }
47405
47406
47407diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47408index 1fc622b..8c48fc3 100644
47409--- a/drivers/oprofile/oprofile_stats.h
47410+++ b/drivers/oprofile/oprofile_stats.h
47411@@ -13,11 +13,11 @@
47412 #include <linux/atomic.h>
47413
47414 struct oprofile_stat_struct {
47415- atomic_t sample_lost_no_mm;
47416- atomic_t sample_lost_no_mapping;
47417- atomic_t bt_lost_no_mapping;
47418- atomic_t event_lost_overflow;
47419- atomic_t multiplex_counter;
47420+ atomic_unchecked_t sample_lost_no_mm;
47421+ atomic_unchecked_t sample_lost_no_mapping;
47422+ atomic_unchecked_t bt_lost_no_mapping;
47423+ atomic_unchecked_t event_lost_overflow;
47424+ atomic_unchecked_t multiplex_counter;
47425 };
47426
47427 extern struct oprofile_stat_struct oprofile_stats;
47428diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47429index 3f49345..c750d0b 100644
47430--- a/drivers/oprofile/oprofilefs.c
47431+++ b/drivers/oprofile/oprofilefs.c
47432@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47433
47434 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47435 {
47436- atomic_t *val = file->private_data;
47437- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47438+ atomic_unchecked_t *val = file->private_data;
47439+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47440 }
47441
47442
47443@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47444
47445
47446 int oprofilefs_create_ro_atomic(struct dentry *root,
47447- char const *name, atomic_t *val)
47448+ char const *name, atomic_unchecked_t *val)
47449 {
47450 return __oprofilefs_create_file(root, name,
47451 &atomic_ro_fops, 0444, val);
47452diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47453index 61be1d9..dec05d7 100644
47454--- a/drivers/oprofile/timer_int.c
47455+++ b/drivers/oprofile/timer_int.c
47456@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47457 return NOTIFY_OK;
47458 }
47459
47460-static struct notifier_block __refdata oprofile_cpu_notifier = {
47461+static struct notifier_block oprofile_cpu_notifier = {
47462 .notifier_call = oprofile_cpu_notify,
47463 };
47464
47465diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47466index 92ed045..62d39bd7 100644
47467--- a/drivers/parport/procfs.c
47468+++ b/drivers/parport/procfs.c
47469@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47470
47471 *ppos += len;
47472
47473- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47474+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47475 }
47476
47477 #ifdef CONFIG_PARPORT_1284
47478@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47479
47480 *ppos += len;
47481
47482- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47483+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47484 }
47485 #endif /* IEEE1284.3 support. */
47486
47487diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
47488index ecfac7e..41be7028 100644
47489--- a/drivers/pci/hotplug/acpiphp_ibm.c
47490+++ b/drivers/pci/hotplug/acpiphp_ibm.c
47491@@ -453,7 +453,9 @@ static int __init ibm_acpiphp_init(void)
47492 goto init_cleanup;
47493 }
47494
47495- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47496+ pax_open_kernel();
47497+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47498+ pax_close_kernel();
47499 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
47500
47501 return retval;
47502diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
47503index 7536eef..52dc8fa 100644
47504--- a/drivers/pci/hotplug/cpcihp_generic.c
47505+++ b/drivers/pci/hotplug/cpcihp_generic.c
47506@@ -73,7 +73,6 @@ static u16 port;
47507 static unsigned int enum_bit;
47508 static u8 enum_mask;
47509
47510-static struct cpci_hp_controller_ops generic_hpc_ops;
47511 static struct cpci_hp_controller generic_hpc;
47512
47513 static int __init validate_parameters(void)
47514@@ -139,6 +138,10 @@ static int query_enum(void)
47515 return ((value & enum_mask) == enum_mask);
47516 }
47517
47518+static struct cpci_hp_controller_ops generic_hpc_ops = {
47519+ .query_enum = query_enum,
47520+};
47521+
47522 static int __init cpcihp_generic_init(void)
47523 {
47524 int status;
47525@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
47526 pci_dev_put(dev);
47527
47528 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
47529- generic_hpc_ops.query_enum = query_enum;
47530 generic_hpc.ops = &generic_hpc_ops;
47531
47532 status = cpci_hp_register_controller(&generic_hpc);
47533diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
47534index e8c4a7c..7046f5c 100644
47535--- a/drivers/pci/hotplug/cpcihp_zt5550.c
47536+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
47537@@ -59,7 +59,6 @@
47538 /* local variables */
47539 static bool debug;
47540 static bool poll;
47541-static struct cpci_hp_controller_ops zt5550_hpc_ops;
47542 static struct cpci_hp_controller zt5550_hpc;
47543
47544 /* Primary cPCI bus bridge device */
47545@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
47546 return 0;
47547 }
47548
47549+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
47550+ .query_enum = zt5550_hc_query_enum,
47551+};
47552+
47553 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
47554 {
47555 int status;
47556@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
47557 dbg("returned from zt5550_hc_config");
47558
47559 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
47560- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
47561 zt5550_hpc.ops = &zt5550_hpc_ops;
47562 if(!poll) {
47563 zt5550_hpc.irq = hc_dev->irq;
47564 zt5550_hpc.irq_flags = IRQF_SHARED;
47565 zt5550_hpc.dev_id = hc_dev;
47566
47567- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47568- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47569- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47570+ pax_open_kernel();
47571+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47572+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47573+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47574+ pax_open_kernel();
47575 } else {
47576 info("using ENUM# polling mode");
47577 }
47578diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
47579index 76ba8a1..20ca857 100644
47580--- a/drivers/pci/hotplug/cpqphp_nvram.c
47581+++ b/drivers/pci/hotplug/cpqphp_nvram.c
47582@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
47583
47584 void compaq_nvram_init (void __iomem *rom_start)
47585 {
47586+
47587+#ifndef CONFIG_PAX_KERNEXEC
47588 if (rom_start) {
47589 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
47590 }
47591+#endif
47592+
47593 dbg("int15 entry = %p\n", compaq_int15_entry_point);
47594
47595 /* initialize our int15 lock */
47596diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
47597index cfa92a9..29539c5 100644
47598--- a/drivers/pci/hotplug/pci_hotplug_core.c
47599+++ b/drivers/pci/hotplug/pci_hotplug_core.c
47600@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
47601 return -EINVAL;
47602 }
47603
47604- slot->ops->owner = owner;
47605- slot->ops->mod_name = mod_name;
47606+ pax_open_kernel();
47607+ *(struct module **)&slot->ops->owner = owner;
47608+ *(const char **)&slot->ops->mod_name = mod_name;
47609+ pax_close_kernel();
47610
47611 mutex_lock(&pci_hp_mutex);
47612 /*
47613diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
47614index bbd48bb..6907ef4 100644
47615--- a/drivers/pci/hotplug/pciehp_core.c
47616+++ b/drivers/pci/hotplug/pciehp_core.c
47617@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
47618 struct slot *slot = ctrl->slot;
47619 struct hotplug_slot *hotplug = NULL;
47620 struct hotplug_slot_info *info = NULL;
47621- struct hotplug_slot_ops *ops = NULL;
47622+ hotplug_slot_ops_no_const *ops = NULL;
47623 char name[SLOT_NAME_SIZE];
47624 int retval = -ENOMEM;
47625
47626diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
47627index c91e6c1..5c723ef 100644
47628--- a/drivers/pci/pci-sysfs.c
47629+++ b/drivers/pci/pci-sysfs.c
47630@@ -1117,7 +1117,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
47631 {
47632 /* allocate attribute structure, piggyback attribute name */
47633 int name_len = write_combine ? 13 : 10;
47634- struct bin_attribute *res_attr;
47635+ bin_attribute_no_const *res_attr;
47636 int retval;
47637
47638 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
47639@@ -1302,7 +1302,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
47640 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
47641 {
47642 int retval;
47643- struct bin_attribute *attr;
47644+ bin_attribute_no_const *attr;
47645
47646 /* If the device has VPD, try to expose it in sysfs. */
47647 if (dev->vpd) {
47648@@ -1349,7 +1349,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
47649 {
47650 int retval;
47651 int rom_size = 0;
47652- struct bin_attribute *attr;
47653+ bin_attribute_no_const *attr;
47654
47655 if (!sysfs_initialized)
47656 return -EACCES;
47657diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
47658index 9c91ecc..bda4796 100644
47659--- a/drivers/pci/pci.h
47660+++ b/drivers/pci/pci.h
47661@@ -95,7 +95,7 @@ struct pci_vpd_ops {
47662 struct pci_vpd {
47663 unsigned int len;
47664 const struct pci_vpd_ops *ops;
47665- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
47666+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
47667 };
47668
47669 int pci_vpd_pci22_init(struct pci_dev *dev);
47670diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
47671index f1272dc..e92a1ac 100644
47672--- a/drivers/pci/pcie/aspm.c
47673+++ b/drivers/pci/pcie/aspm.c
47674@@ -27,9 +27,9 @@
47675 #define MODULE_PARAM_PREFIX "pcie_aspm."
47676
47677 /* Note: those are not register definitions */
47678-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
47679-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
47680-#define ASPM_STATE_L1 (4) /* L1 state */
47681+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
47682+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
47683+#define ASPM_STATE_L1 (4U) /* L1 state */
47684 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
47685 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
47686
47687diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
47688index 38e403d..a2ce55a 100644
47689--- a/drivers/pci/probe.c
47690+++ b/drivers/pci/probe.c
47691@@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
47692 struct pci_bus_region region, inverted_region;
47693 bool bar_too_big = false, bar_disabled = false;
47694
47695- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
47696+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
47697
47698 /* No printks while decoding is disabled! */
47699 if (!dev->mmio_always_on) {
47700diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
47701index 46d1378..30e452b 100644
47702--- a/drivers/pci/proc.c
47703+++ b/drivers/pci/proc.c
47704@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
47705 static int __init pci_proc_init(void)
47706 {
47707 struct pci_dev *dev = NULL;
47708+
47709+#ifdef CONFIG_GRKERNSEC_PROC_ADD
47710+#ifdef CONFIG_GRKERNSEC_PROC_USER
47711+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
47712+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47713+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
47714+#endif
47715+#else
47716 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
47717+#endif
47718 proc_create("devices", 0, proc_bus_pci_dir,
47719 &proc_bus_pci_dev_operations);
47720 proc_initialized = 1;
47721diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
47722index 3e5b4497..dcdfb70 100644
47723--- a/drivers/platform/chrome/chromeos_laptop.c
47724+++ b/drivers/platform/chrome/chromeos_laptop.c
47725@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
47726 return 0;
47727 }
47728
47729-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
47730+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
47731 {
47732 .ident = "Samsung Series 5 550 - Touchpad",
47733 .matches = {
47734diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
47735index 19c313b..ed28b38 100644
47736--- a/drivers/platform/x86/asus-wmi.c
47737+++ b/drivers/platform/x86/asus-wmi.c
47738@@ -1618,6 +1618,10 @@ static int show_dsts(struct seq_file *m, void *data)
47739 int err;
47740 u32 retval = -1;
47741
47742+#ifdef CONFIG_GRKERNSEC_KMEM
47743+ return -EPERM;
47744+#endif
47745+
47746 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
47747
47748 if (err < 0)
47749@@ -1634,6 +1638,10 @@ static int show_devs(struct seq_file *m, void *data)
47750 int err;
47751 u32 retval = -1;
47752
47753+#ifdef CONFIG_GRKERNSEC_KMEM
47754+ return -EPERM;
47755+#endif
47756+
47757 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
47758 &retval);
47759
47760@@ -1658,6 +1666,10 @@ static int show_call(struct seq_file *m, void *data)
47761 union acpi_object *obj;
47762 acpi_status status;
47763
47764+#ifdef CONFIG_GRKERNSEC_KMEM
47765+ return -EPERM;
47766+#endif
47767+
47768 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
47769 1, asus->debug.method_id,
47770 &input, &output);
47771diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
47772index 62f8030..c7f2a45 100644
47773--- a/drivers/platform/x86/msi-laptop.c
47774+++ b/drivers/platform/x86/msi-laptop.c
47775@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
47776
47777 if (!quirks->ec_read_only) {
47778 /* allow userland write sysfs file */
47779- dev_attr_bluetooth.store = store_bluetooth;
47780- dev_attr_wlan.store = store_wlan;
47781- dev_attr_threeg.store = store_threeg;
47782- dev_attr_bluetooth.attr.mode |= S_IWUSR;
47783- dev_attr_wlan.attr.mode |= S_IWUSR;
47784- dev_attr_threeg.attr.mode |= S_IWUSR;
47785+ pax_open_kernel();
47786+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
47787+ *(void **)&dev_attr_wlan.store = store_wlan;
47788+ *(void **)&dev_attr_threeg.store = store_threeg;
47789+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
47790+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
47791+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
47792+ pax_close_kernel();
47793 }
47794
47795 /* disable hardware control by fn key */
47796diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
47797index 70222f2..8c8ce66 100644
47798--- a/drivers/platform/x86/msi-wmi.c
47799+++ b/drivers/platform/x86/msi-wmi.c
47800@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
47801 static void msi_wmi_notify(u32 value, void *context)
47802 {
47803 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
47804- static struct key_entry *key;
47805+ struct key_entry *key;
47806 union acpi_object *obj;
47807 acpi_status status;
47808
47809diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
47810index fb233ae..23a325c 100644
47811--- a/drivers/platform/x86/sony-laptop.c
47812+++ b/drivers/platform/x86/sony-laptop.c
47813@@ -2453,7 +2453,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
47814 }
47815
47816 /* High speed charging function */
47817-static struct device_attribute *hsc_handle;
47818+static device_attribute_no_const *hsc_handle;
47819
47820 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
47821 struct device_attribute *attr,
47822diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
47823index 58b0274..6704626 100644
47824--- a/drivers/platform/x86/thinkpad_acpi.c
47825+++ b/drivers/platform/x86/thinkpad_acpi.c
47826@@ -2100,7 +2100,7 @@ static int hotkey_mask_get(void)
47827 return 0;
47828 }
47829
47830-void static hotkey_mask_warn_incomplete_mask(void)
47831+static void hotkey_mask_warn_incomplete_mask(void)
47832 {
47833 /* log only what the user can fix... */
47834 const u32 wantedmask = hotkey_driver_mask &
47835@@ -2327,11 +2327,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
47836 }
47837 }
47838
47839-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47840- struct tp_nvram_state *newn,
47841- const u32 event_mask)
47842-{
47843-
47844 #define TPACPI_COMPARE_KEY(__scancode, __member) \
47845 do { \
47846 if ((event_mask & (1 << __scancode)) && \
47847@@ -2345,36 +2340,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47848 tpacpi_hotkey_send_key(__scancode); \
47849 } while (0)
47850
47851- void issue_volchange(const unsigned int oldvol,
47852- const unsigned int newvol)
47853- {
47854- unsigned int i = oldvol;
47855+static void issue_volchange(const unsigned int oldvol,
47856+ const unsigned int newvol,
47857+ const u32 event_mask)
47858+{
47859+ unsigned int i = oldvol;
47860
47861- while (i > newvol) {
47862- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47863- i--;
47864- }
47865- while (i < newvol) {
47866- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47867- i++;
47868- }
47869+ while (i > newvol) {
47870+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47871+ i--;
47872 }
47873+ while (i < newvol) {
47874+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47875+ i++;
47876+ }
47877+}
47878
47879- void issue_brightnesschange(const unsigned int oldbrt,
47880- const unsigned int newbrt)
47881- {
47882- unsigned int i = oldbrt;
47883+static void issue_brightnesschange(const unsigned int oldbrt,
47884+ const unsigned int newbrt,
47885+ const u32 event_mask)
47886+{
47887+ unsigned int i = oldbrt;
47888
47889- while (i > newbrt) {
47890- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47891- i--;
47892- }
47893- while (i < newbrt) {
47894- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47895- i++;
47896- }
47897+ while (i > newbrt) {
47898+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47899+ i--;
47900+ }
47901+ while (i < newbrt) {
47902+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47903+ i++;
47904 }
47905+}
47906
47907+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47908+ struct tp_nvram_state *newn,
47909+ const u32 event_mask)
47910+{
47911 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
47912 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
47913 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
47914@@ -2408,7 +2409,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47915 oldn->volume_level != newn->volume_level) {
47916 /* recently muted, or repeated mute keypress, or
47917 * multiple presses ending in mute */
47918- issue_volchange(oldn->volume_level, newn->volume_level);
47919+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47920 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
47921 }
47922 } else {
47923@@ -2418,7 +2419,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47924 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47925 }
47926 if (oldn->volume_level != newn->volume_level) {
47927- issue_volchange(oldn->volume_level, newn->volume_level);
47928+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47929 } else if (oldn->volume_toggle != newn->volume_toggle) {
47930 /* repeated vol up/down keypress at end of scale ? */
47931 if (newn->volume_level == 0)
47932@@ -2431,7 +2432,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47933 /* handle brightness */
47934 if (oldn->brightness_level != newn->brightness_level) {
47935 issue_brightnesschange(oldn->brightness_level,
47936- newn->brightness_level);
47937+ newn->brightness_level,
47938+ event_mask);
47939 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
47940 /* repeated key presses that didn't change state */
47941 if (newn->brightness_level == 0)
47942@@ -2440,10 +2442,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47943 && !tp_features.bright_unkfw)
47944 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47945 }
47946+}
47947
47948 #undef TPACPI_COMPARE_KEY
47949 #undef TPACPI_MAY_SEND_KEY
47950-}
47951
47952 /*
47953 * Polling driver
47954diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
47955index 769d265..a3a05ca 100644
47956--- a/drivers/pnp/pnpbios/bioscalls.c
47957+++ b/drivers/pnp/pnpbios/bioscalls.c
47958@@ -58,7 +58,7 @@ do { \
47959 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
47960 } while(0)
47961
47962-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
47963+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
47964 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
47965
47966 /*
47967@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47968
47969 cpu = get_cpu();
47970 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
47971+
47972+ pax_open_kernel();
47973 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
47974+ pax_close_kernel();
47975
47976 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
47977 spin_lock_irqsave(&pnp_bios_lock, flags);
47978@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47979 :"memory");
47980 spin_unlock_irqrestore(&pnp_bios_lock, flags);
47981
47982+ pax_open_kernel();
47983 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
47984+ pax_close_kernel();
47985+
47986 put_cpu();
47987
47988 /* If we get here and this is set then the PnP BIOS faulted on us. */
47989@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
47990 return status;
47991 }
47992
47993-void pnpbios_calls_init(union pnp_bios_install_struct *header)
47994+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
47995 {
47996 int i;
47997
47998@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47999 pnp_bios_callpoint.offset = header->fields.pm16offset;
48000 pnp_bios_callpoint.segment = PNP_CS16;
48001
48002+ pax_open_kernel();
48003+
48004 for_each_possible_cpu(i) {
48005 struct desc_struct *gdt = get_cpu_gdt_table(i);
48006 if (!gdt)
48007@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48008 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
48009 (unsigned long)__va(header->fields.pm16dseg));
48010 }
48011+
48012+ pax_close_kernel();
48013 }
48014diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
48015index d95e101..67f0c3f 100644
48016--- a/drivers/pnp/resource.c
48017+++ b/drivers/pnp/resource.c
48018@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
48019 return 1;
48020
48021 /* check if the resource is valid */
48022- if (*irq < 0 || *irq > 15)
48023+ if (*irq > 15)
48024 return 0;
48025
48026 /* check if the resource is reserved */
48027@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
48028 return 1;
48029
48030 /* check if the resource is valid */
48031- if (*dma < 0 || *dma == 4 || *dma > 7)
48032+ if (*dma == 4 || *dma > 7)
48033 return 0;
48034
48035 /* check if the resource is reserved */
48036diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
48037index 0c52e2a..3421ab7 100644
48038--- a/drivers/power/pda_power.c
48039+++ b/drivers/power/pda_power.c
48040@@ -37,7 +37,11 @@ static int polling;
48041
48042 #if IS_ENABLED(CONFIG_USB_PHY)
48043 static struct usb_phy *transceiver;
48044-static struct notifier_block otg_nb;
48045+static int otg_handle_notification(struct notifier_block *nb,
48046+ unsigned long event, void *unused);
48047+static struct notifier_block otg_nb = {
48048+ .notifier_call = otg_handle_notification
48049+};
48050 #endif
48051
48052 static struct regulator *ac_draw;
48053@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
48054
48055 #if IS_ENABLED(CONFIG_USB_PHY)
48056 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
48057- otg_nb.notifier_call = otg_handle_notification;
48058 ret = usb_register_notifier(transceiver, &otg_nb);
48059 if (ret) {
48060 dev_err(dev, "failure to register otg notifier\n");
48061diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
48062index cc439fd..8fa30df 100644
48063--- a/drivers/power/power_supply.h
48064+++ b/drivers/power/power_supply.h
48065@@ -16,12 +16,12 @@ struct power_supply;
48066
48067 #ifdef CONFIG_SYSFS
48068
48069-extern void power_supply_init_attrs(struct device_type *dev_type);
48070+extern void power_supply_init_attrs(void);
48071 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
48072
48073 #else
48074
48075-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
48076+static inline void power_supply_init_attrs(void) {}
48077 #define power_supply_uevent NULL
48078
48079 #endif /* CONFIG_SYSFS */
48080diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
48081index 557af94..84dc1fe 100644
48082--- a/drivers/power/power_supply_core.c
48083+++ b/drivers/power/power_supply_core.c
48084@@ -24,7 +24,10 @@
48085 struct class *power_supply_class;
48086 EXPORT_SYMBOL_GPL(power_supply_class);
48087
48088-static struct device_type power_supply_dev_type;
48089+extern const struct attribute_group *power_supply_attr_groups[];
48090+static struct device_type power_supply_dev_type = {
48091+ .groups = power_supply_attr_groups,
48092+};
48093
48094 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
48095 struct power_supply *supply)
48096@@ -584,7 +587,7 @@ static int __init power_supply_class_init(void)
48097 return PTR_ERR(power_supply_class);
48098
48099 power_supply_class->dev_uevent = power_supply_uevent;
48100- power_supply_init_attrs(&power_supply_dev_type);
48101+ power_supply_init_attrs();
48102
48103 return 0;
48104 }
48105diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
48106index 44420d1..967126e 100644
48107--- a/drivers/power/power_supply_sysfs.c
48108+++ b/drivers/power/power_supply_sysfs.c
48109@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
48110 .is_visible = power_supply_attr_is_visible,
48111 };
48112
48113-static const struct attribute_group *power_supply_attr_groups[] = {
48114+const struct attribute_group *power_supply_attr_groups[] = {
48115 &power_supply_attr_group,
48116 NULL,
48117 };
48118
48119-void power_supply_init_attrs(struct device_type *dev_type)
48120+void power_supply_init_attrs(void)
48121 {
48122 int i;
48123
48124- dev_type->groups = power_supply_attr_groups;
48125-
48126 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48127 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48128 }
48129diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48130index 84419af..268ede8 100644
48131--- a/drivers/powercap/powercap_sys.c
48132+++ b/drivers/powercap/powercap_sys.c
48133@@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48134 struct device_attribute name_attr;
48135 };
48136
48137+static ssize_t show_constraint_name(struct device *dev,
48138+ struct device_attribute *dev_attr,
48139+ char *buf);
48140+
48141 static struct powercap_constraint_attr
48142- constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48143+ constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48144+ [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48145+ .power_limit_attr = {
48146+ .attr = {
48147+ .name = NULL,
48148+ .mode = S_IWUSR | S_IRUGO
48149+ },
48150+ .show = show_constraint_power_limit_uw,
48151+ .store = store_constraint_power_limit_uw
48152+ },
48153+
48154+ .time_window_attr = {
48155+ .attr = {
48156+ .name = NULL,
48157+ .mode = S_IWUSR | S_IRUGO
48158+ },
48159+ .show = show_constraint_time_window_us,
48160+ .store = store_constraint_time_window_us
48161+ },
48162+
48163+ .max_power_attr = {
48164+ .attr = {
48165+ .name = NULL,
48166+ .mode = S_IRUGO
48167+ },
48168+ .show = show_constraint_max_power_uw,
48169+ .store = NULL
48170+ },
48171+
48172+ .min_power_attr = {
48173+ .attr = {
48174+ .name = NULL,
48175+ .mode = S_IRUGO
48176+ },
48177+ .show = show_constraint_min_power_uw,
48178+ .store = NULL
48179+ },
48180+
48181+ .max_time_window_attr = {
48182+ .attr = {
48183+ .name = NULL,
48184+ .mode = S_IRUGO
48185+ },
48186+ .show = show_constraint_max_time_window_us,
48187+ .store = NULL
48188+ },
48189+
48190+ .min_time_window_attr = {
48191+ .attr = {
48192+ .name = NULL,
48193+ .mode = S_IRUGO
48194+ },
48195+ .show = show_constraint_min_time_window_us,
48196+ .store = NULL
48197+ },
48198+
48199+ .name_attr = {
48200+ .attr = {
48201+ .name = NULL,
48202+ .mode = S_IRUGO
48203+ },
48204+ .show = show_constraint_name,
48205+ .store = NULL
48206+ }
48207+ }
48208+};
48209
48210 /* A list of powercap control_types */
48211 static LIST_HEAD(powercap_cntrl_list);
48212@@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48213 }
48214
48215 static int create_constraint_attribute(int id, const char *name,
48216- int mode,
48217- struct device_attribute *dev_attr,
48218- ssize_t (*show)(struct device *,
48219- struct device_attribute *, char *),
48220- ssize_t (*store)(struct device *,
48221- struct device_attribute *,
48222- const char *, size_t)
48223- )
48224+ struct device_attribute *dev_attr)
48225 {
48226+ name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48227
48228- dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48229- id, name);
48230- if (!dev_attr->attr.name)
48231+ if (!name)
48232 return -ENOMEM;
48233- dev_attr->attr.mode = mode;
48234- dev_attr->show = show;
48235- dev_attr->store = store;
48236+
48237+ pax_open_kernel();
48238+ *(const char **)&dev_attr->attr.name = name;
48239+ pax_close_kernel();
48240
48241 return 0;
48242 }
48243@@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48244
48245 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48246 ret = create_constraint_attribute(i, "power_limit_uw",
48247- S_IWUSR | S_IRUGO,
48248- &constraint_attrs[i].power_limit_attr,
48249- show_constraint_power_limit_uw,
48250- store_constraint_power_limit_uw);
48251+ &constraint_attrs[i].power_limit_attr);
48252 if (ret)
48253 goto err_alloc;
48254 ret = create_constraint_attribute(i, "time_window_us",
48255- S_IWUSR | S_IRUGO,
48256- &constraint_attrs[i].time_window_attr,
48257- show_constraint_time_window_us,
48258- store_constraint_time_window_us);
48259+ &constraint_attrs[i].time_window_attr);
48260 if (ret)
48261 goto err_alloc;
48262- ret = create_constraint_attribute(i, "name", S_IRUGO,
48263- &constraint_attrs[i].name_attr,
48264- show_constraint_name,
48265- NULL);
48266+ ret = create_constraint_attribute(i, "name",
48267+ &constraint_attrs[i].name_attr);
48268 if (ret)
48269 goto err_alloc;
48270- ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48271- &constraint_attrs[i].max_power_attr,
48272- show_constraint_max_power_uw,
48273- NULL);
48274+ ret = create_constraint_attribute(i, "max_power_uw",
48275+ &constraint_attrs[i].max_power_attr);
48276 if (ret)
48277 goto err_alloc;
48278- ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48279- &constraint_attrs[i].min_power_attr,
48280- show_constraint_min_power_uw,
48281- NULL);
48282+ ret = create_constraint_attribute(i, "min_power_uw",
48283+ &constraint_attrs[i].min_power_attr);
48284 if (ret)
48285 goto err_alloc;
48286 ret = create_constraint_attribute(i, "max_time_window_us",
48287- S_IRUGO,
48288- &constraint_attrs[i].max_time_window_attr,
48289- show_constraint_max_time_window_us,
48290- NULL);
48291+ &constraint_attrs[i].max_time_window_attr);
48292 if (ret)
48293 goto err_alloc;
48294 ret = create_constraint_attribute(i, "min_time_window_us",
48295- S_IRUGO,
48296- &constraint_attrs[i].min_time_window_attr,
48297- show_constraint_min_time_window_us,
48298- NULL);
48299+ &constraint_attrs[i].min_time_window_attr);
48300 if (ret)
48301 goto err_alloc;
48302
48303@@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48304 power_zone->zone_dev_attrs[count++] =
48305 &dev_attr_max_energy_range_uj.attr;
48306 if (power_zone->ops->get_energy_uj) {
48307+ pax_open_kernel();
48308 if (power_zone->ops->reset_energy_uj)
48309- dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48310+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48311 else
48312- dev_attr_energy_uj.attr.mode = S_IRUGO;
48313+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48314+ pax_close_kernel();
48315 power_zone->zone_dev_attrs[count++] =
48316 &dev_attr_energy_uj.attr;
48317 }
48318diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48319index 7271299..20217a5 100644
48320--- a/drivers/regulator/core.c
48321+++ b/drivers/regulator/core.c
48322@@ -3366,7 +3366,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48323 {
48324 const struct regulation_constraints *constraints = NULL;
48325 const struct regulator_init_data *init_data;
48326- static atomic_t regulator_no = ATOMIC_INIT(0);
48327+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48328 struct regulator_dev *rdev;
48329 struct device *dev;
48330 int ret, i;
48331@@ -3436,7 +3436,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48332 rdev->dev.of_node = config->of_node;
48333 rdev->dev.parent = dev;
48334 dev_set_name(&rdev->dev, "regulator.%d",
48335- atomic_inc_return(&regulator_no) - 1);
48336+ atomic_inc_return_unchecked(&regulator_no) - 1);
48337 ret = device_register(&rdev->dev);
48338 if (ret != 0) {
48339 put_device(&rdev->dev);
48340diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48341index 8d94d3d..653b623 100644
48342--- a/drivers/regulator/max8660.c
48343+++ b/drivers/regulator/max8660.c
48344@@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
48345 max8660->shadow_regs[MAX8660_OVER1] = 5;
48346 } else {
48347 /* Otherwise devices can be toggled via software */
48348- max8660_dcdc_ops.enable = max8660_dcdc_enable;
48349- max8660_dcdc_ops.disable = max8660_dcdc_disable;
48350+ pax_open_kernel();
48351+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48352+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48353+ pax_close_kernel();
48354 }
48355
48356 /*
48357diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48358index 892aa1e..ebd1b9c 100644
48359--- a/drivers/regulator/max8973-regulator.c
48360+++ b/drivers/regulator/max8973-regulator.c
48361@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
48362 if (!pdata || !pdata->enable_ext_control) {
48363 max->desc.enable_reg = MAX8973_VOUT;
48364 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48365- max->ops.enable = regulator_enable_regmap;
48366- max->ops.disable = regulator_disable_regmap;
48367- max->ops.is_enabled = regulator_is_enabled_regmap;
48368+ pax_open_kernel();
48369+ *(void **)&max->ops.enable = regulator_enable_regmap;
48370+ *(void **)&max->ops.disable = regulator_disable_regmap;
48371+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48372+ pax_close_kernel();
48373 }
48374
48375 if (pdata) {
48376diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48377index 96c9f80..90974ca 100644
48378--- a/drivers/regulator/mc13892-regulator.c
48379+++ b/drivers/regulator/mc13892-regulator.c
48380@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48381 }
48382 mc13xxx_unlock(mc13892);
48383
48384- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48385+ pax_open_kernel();
48386+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48387 = mc13892_vcam_set_mode;
48388- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48389+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48390 = mc13892_vcam_get_mode;
48391+ pax_close_kernel();
48392
48393 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48394 ARRAY_SIZE(mc13892_regulators));
48395diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48396index a2325bc..04c549f 100644
48397--- a/drivers/rtc/rtc-cmos.c
48398+++ b/drivers/rtc/rtc-cmos.c
48399@@ -779,7 +779,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48400 hpet_rtc_timer_init();
48401
48402 /* export at least the first block of NVRAM */
48403- nvram.size = address_space - NVRAM_OFFSET;
48404+ pax_open_kernel();
48405+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48406+ pax_close_kernel();
48407 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48408 if (retval < 0) {
48409 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48410diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48411index d049393..bb20be0 100644
48412--- a/drivers/rtc/rtc-dev.c
48413+++ b/drivers/rtc/rtc-dev.c
48414@@ -16,6 +16,7 @@
48415 #include <linux/module.h>
48416 #include <linux/rtc.h>
48417 #include <linux/sched.h>
48418+#include <linux/grsecurity.h>
48419 #include "rtc-core.h"
48420
48421 static dev_t rtc_devt;
48422@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48423 if (copy_from_user(&tm, uarg, sizeof(tm)))
48424 return -EFAULT;
48425
48426+ gr_log_timechange();
48427+
48428 return rtc_set_time(rtc, &tm);
48429
48430 case RTC_PIE_ON:
48431diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48432index 4e75345..09f8663 100644
48433--- a/drivers/rtc/rtc-ds1307.c
48434+++ b/drivers/rtc/rtc-ds1307.c
48435@@ -107,7 +107,7 @@ struct ds1307 {
48436 u8 offset; /* register's offset */
48437 u8 regs[11];
48438 u16 nvram_offset;
48439- struct bin_attribute *nvram;
48440+ bin_attribute_no_const *nvram;
48441 enum ds_type type;
48442 unsigned long flags;
48443 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48444diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48445index 11880c1..b823aa4 100644
48446--- a/drivers/rtc/rtc-m48t59.c
48447+++ b/drivers/rtc/rtc-m48t59.c
48448@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48449 if (IS_ERR(m48t59->rtc))
48450 return PTR_ERR(m48t59->rtc);
48451
48452- m48t59_nvram_attr.size = pdata->offset;
48453+ pax_open_kernel();
48454+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48455+ pax_close_kernel();
48456
48457 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48458 if (ret)
48459diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48460index 14b5f8d..cc9bd26 100644
48461--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
48462+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
48463@@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
48464 for (bit = 0; bit < 8; bit++) {
48465
48466 if ((pci_status[i] & (0x1 << bit)) != 0) {
48467- static const char *s;
48468+ const char *s;
48469
48470 s = pci_status_strings[bit];
48471 if (i == 7/*TARG*/ && bit == 3)
48472@@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
48473
48474 for (bit = 0; bit < 8; bit++) {
48475
48476- if ((split_status[i] & (0x1 << bit)) != 0) {
48477- static const char *s;
48478-
48479- s = split_status_strings[bit];
48480- printk(s, ahd_name(ahd),
48481+ if ((split_status[i] & (0x1 << bit)) != 0)
48482+ printk(split_status_strings[bit], ahd_name(ahd),
48483 split_status_source[i]);
48484- }
48485
48486 if (i > 1)
48487 continue;
48488
48489- if ((sg_split_status[i] & (0x1 << bit)) != 0) {
48490- static const char *s;
48491-
48492- s = split_status_strings[bit];
48493- printk(s, ahd_name(ahd), "SG");
48494- }
48495+ if ((sg_split_status[i] & (0x1 << bit)) != 0)
48496+ printk(split_status_strings[bit], ahd_name(ahd), "SG");
48497 }
48498 }
48499 /*
48500diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
48501index e693af6..2e525b6 100644
48502--- a/drivers/scsi/bfa/bfa_fcpim.h
48503+++ b/drivers/scsi/bfa/bfa_fcpim.h
48504@@ -36,7 +36,7 @@ struct bfa_iotag_s {
48505
48506 struct bfa_itn_s {
48507 bfa_isr_func_t isr;
48508-};
48509+} __no_const;
48510
48511 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
48512 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
48513diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
48514index a3ab5cc..8143622 100644
48515--- a/drivers/scsi/bfa/bfa_fcs.c
48516+++ b/drivers/scsi/bfa/bfa_fcs.c
48517@@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
48518 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
48519
48520 static struct bfa_fcs_mod_s fcs_modules[] = {
48521- { bfa_fcs_port_attach, NULL, NULL },
48522- { bfa_fcs_uf_attach, NULL, NULL },
48523- { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
48524- bfa_fcs_fabric_modexit },
48525+ {
48526+ .attach = bfa_fcs_port_attach,
48527+ .modinit = NULL,
48528+ .modexit = NULL
48529+ },
48530+ {
48531+ .attach = bfa_fcs_uf_attach,
48532+ .modinit = NULL,
48533+ .modexit = NULL
48534+ },
48535+ {
48536+ .attach = bfa_fcs_fabric_attach,
48537+ .modinit = bfa_fcs_fabric_modinit,
48538+ .modexit = bfa_fcs_fabric_modexit
48539+ },
48540 };
48541
48542 /*
48543diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
48544index f5e4e61..a0acaf6 100644
48545--- a/drivers/scsi/bfa/bfa_fcs_lport.c
48546+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
48547@@ -89,15 +89,26 @@ static struct {
48548 void (*offline) (struct bfa_fcs_lport_s *port);
48549 } __port_action[] = {
48550 {
48551- bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
48552- bfa_fcs_lport_unknown_offline}, {
48553- bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
48554- bfa_fcs_lport_fab_offline}, {
48555- bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
48556- bfa_fcs_lport_n2n_offline}, {
48557- bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
48558- bfa_fcs_lport_loop_offline},
48559- };
48560+ .init = bfa_fcs_lport_unknown_init,
48561+ .online = bfa_fcs_lport_unknown_online,
48562+ .offline = bfa_fcs_lport_unknown_offline
48563+ },
48564+ {
48565+ .init = bfa_fcs_lport_fab_init,
48566+ .online = bfa_fcs_lport_fab_online,
48567+ .offline = bfa_fcs_lport_fab_offline
48568+ },
48569+ {
48570+ .init = bfa_fcs_lport_n2n_init,
48571+ .online = bfa_fcs_lport_n2n_online,
48572+ .offline = bfa_fcs_lport_n2n_offline
48573+ },
48574+ {
48575+ .init = bfa_fcs_lport_loop_init,
48576+ .online = bfa_fcs_lport_loop_online,
48577+ .offline = bfa_fcs_lport_loop_offline
48578+ },
48579+};
48580
48581 /*
48582 * fcs_port_sm FCS logical port state machine
48583diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
48584index 90814fe..4384138 100644
48585--- a/drivers/scsi/bfa/bfa_ioc.h
48586+++ b/drivers/scsi/bfa/bfa_ioc.h
48587@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
48588 bfa_ioc_disable_cbfn_t disable_cbfn;
48589 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
48590 bfa_ioc_reset_cbfn_t reset_cbfn;
48591-};
48592+} __no_const;
48593
48594 /*
48595 * IOC event notification mechanism.
48596@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
48597 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
48598 enum bfi_ioc_state fwstate);
48599 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
48600-};
48601+} __no_const;
48602
48603 /*
48604 * Queue element to wait for room in request queue. FIFO order is
48605diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
48606index a14c784..6de6790 100644
48607--- a/drivers/scsi/bfa/bfa_modules.h
48608+++ b/drivers/scsi/bfa/bfa_modules.h
48609@@ -78,12 +78,12 @@ enum {
48610 \
48611 extern struct bfa_module_s hal_mod_ ## __mod; \
48612 struct bfa_module_s hal_mod_ ## __mod = { \
48613- bfa_ ## __mod ## _meminfo, \
48614- bfa_ ## __mod ## _attach, \
48615- bfa_ ## __mod ## _detach, \
48616- bfa_ ## __mod ## _start, \
48617- bfa_ ## __mod ## _stop, \
48618- bfa_ ## __mod ## _iocdisable, \
48619+ .meminfo = bfa_ ## __mod ## _meminfo, \
48620+ .attach = bfa_ ## __mod ## _attach, \
48621+ .detach = bfa_ ## __mod ## _detach, \
48622+ .start = bfa_ ## __mod ## _start, \
48623+ .stop = bfa_ ## __mod ## _stop, \
48624+ .iocdisable = bfa_ ## __mod ## _iocdisable, \
48625 }
48626
48627 #define BFA_CACHELINE_SZ (256)
48628diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
48629index 045c4e1..13de803 100644
48630--- a/drivers/scsi/fcoe/fcoe_sysfs.c
48631+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
48632@@ -33,8 +33,8 @@
48633 */
48634 #include "libfcoe.h"
48635
48636-static atomic_t ctlr_num;
48637-static atomic_t fcf_num;
48638+static atomic_unchecked_t ctlr_num;
48639+static atomic_unchecked_t fcf_num;
48640
48641 /*
48642 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
48643@@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
48644 if (!ctlr)
48645 goto out;
48646
48647- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
48648+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
48649 ctlr->f = f;
48650 ctlr->mode = FIP_CONN_TYPE_FABRIC;
48651 INIT_LIST_HEAD(&ctlr->fcfs);
48652@@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
48653 fcf->dev.parent = &ctlr->dev;
48654 fcf->dev.bus = &fcoe_bus_type;
48655 fcf->dev.type = &fcoe_fcf_device_type;
48656- fcf->id = atomic_inc_return(&fcf_num) - 1;
48657+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
48658 fcf->state = FCOE_FCF_STATE_UNKNOWN;
48659
48660 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
48661@@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
48662 {
48663 int error;
48664
48665- atomic_set(&ctlr_num, 0);
48666- atomic_set(&fcf_num, 0);
48667+ atomic_set_unchecked(&ctlr_num, 0);
48668+ atomic_set_unchecked(&fcf_num, 0);
48669
48670 error = bus_register(&fcoe_bus_type);
48671 if (error)
48672diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
48673index f2c5005..db36c02 100644
48674--- a/drivers/scsi/hosts.c
48675+++ b/drivers/scsi/hosts.c
48676@@ -42,7 +42,7 @@
48677 #include "scsi_logging.h"
48678
48679
48680-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48681+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48682
48683
48684 static void scsi_host_cls_release(struct device *dev)
48685@@ -367,7 +367,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
48686 * subtract one because we increment first then return, but we need to
48687 * know what the next host number was before increment
48688 */
48689- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
48690+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
48691 shost->dma_channel = 0xff;
48692
48693 /* These three are default values which can be overridden */
48694diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
48695index 20a5e6e..8b23cea 100644
48696--- a/drivers/scsi/hpsa.c
48697+++ b/drivers/scsi/hpsa.c
48698@@ -578,7 +578,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
48699 unsigned long flags;
48700
48701 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
48702- return h->access.command_completed(h, q);
48703+ return h->access->command_completed(h, q);
48704
48705 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
48706 a = rq->head[rq->current_entry];
48707@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
48708 while (!list_empty(&h->reqQ)) {
48709 c = list_entry(h->reqQ.next, struct CommandList, list);
48710 /* can't do anything if fifo is full */
48711- if ((h->access.fifo_full(h))) {
48712+ if ((h->access->fifo_full(h))) {
48713 dev_warn(&h->pdev->dev, "fifo full\n");
48714 break;
48715 }
48716@@ -3466,7 +3466,7 @@ static void start_io(struct ctlr_info *h)
48717
48718 /* Tell the controller execute command */
48719 spin_unlock_irqrestore(&h->lock, flags);
48720- h->access.submit_command(h, c);
48721+ h->access->submit_command(h, c);
48722 spin_lock_irqsave(&h->lock, flags);
48723 }
48724 spin_unlock_irqrestore(&h->lock, flags);
48725@@ -3474,17 +3474,17 @@ static void start_io(struct ctlr_info *h)
48726
48727 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
48728 {
48729- return h->access.command_completed(h, q);
48730+ return h->access->command_completed(h, q);
48731 }
48732
48733 static inline bool interrupt_pending(struct ctlr_info *h)
48734 {
48735- return h->access.intr_pending(h);
48736+ return h->access->intr_pending(h);
48737 }
48738
48739 static inline long interrupt_not_for_us(struct ctlr_info *h)
48740 {
48741- return (h->access.intr_pending(h) == 0) ||
48742+ return (h->access->intr_pending(h) == 0) ||
48743 (h->interrupts_enabled == 0);
48744 }
48745
48746@@ -4386,7 +4386,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
48747 if (prod_index < 0)
48748 return -ENODEV;
48749 h->product_name = products[prod_index].product_name;
48750- h->access = *(products[prod_index].access);
48751+ h->access = products[prod_index].access;
48752
48753 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
48754 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
48755@@ -4668,7 +4668,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
48756
48757 assert_spin_locked(&lockup_detector_lock);
48758 remove_ctlr_from_lockup_detector_list(h);
48759- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48760+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48761 spin_lock_irqsave(&h->lock, flags);
48762 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
48763 spin_unlock_irqrestore(&h->lock, flags);
48764@@ -4845,7 +4845,7 @@ reinit_after_soft_reset:
48765 }
48766
48767 /* make sure the board interrupts are off */
48768- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48769+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48770
48771 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
48772 goto clean2;
48773@@ -4879,7 +4879,7 @@ reinit_after_soft_reset:
48774 * fake ones to scoop up any residual completions.
48775 */
48776 spin_lock_irqsave(&h->lock, flags);
48777- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48778+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48779 spin_unlock_irqrestore(&h->lock, flags);
48780 free_irqs(h);
48781 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
48782@@ -4898,9 +4898,9 @@ reinit_after_soft_reset:
48783 dev_info(&h->pdev->dev, "Board READY.\n");
48784 dev_info(&h->pdev->dev,
48785 "Waiting for stale completions to drain.\n");
48786- h->access.set_intr_mask(h, HPSA_INTR_ON);
48787+ h->access->set_intr_mask(h, HPSA_INTR_ON);
48788 msleep(10000);
48789- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48790+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48791
48792 rc = controller_reset_failed(h->cfgtable);
48793 if (rc)
48794@@ -4921,7 +4921,7 @@ reinit_after_soft_reset:
48795 }
48796
48797 /* Turn the interrupts on so we can service requests */
48798- h->access.set_intr_mask(h, HPSA_INTR_ON);
48799+ h->access->set_intr_mask(h, HPSA_INTR_ON);
48800
48801 hpsa_hba_inquiry(h);
48802 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
48803@@ -4976,7 +4976,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
48804 * To write all data in the battery backed cache to disks
48805 */
48806 hpsa_flush_cache(h);
48807- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48808+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48809 hpsa_free_irqs_and_disable_msix(h);
48810 }
48811
48812@@ -5143,7 +5143,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
48813 return;
48814 }
48815 /* Change the access methods to the performant access methods */
48816- h->access = SA5_performant_access;
48817+ h->access = &SA5_performant_access;
48818 h->transMethod = CFGTBL_Trans_Performant;
48819 }
48820
48821diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
48822index bc85e72..d463049 100644
48823--- a/drivers/scsi/hpsa.h
48824+++ b/drivers/scsi/hpsa.h
48825@@ -79,7 +79,7 @@ struct ctlr_info {
48826 unsigned int msix_vector;
48827 unsigned int msi_vector;
48828 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
48829- struct access_method access;
48830+ struct access_method *access;
48831
48832 /* queue and queue Info */
48833 struct list_head reqQ;
48834@@ -381,19 +381,19 @@ static bool SA5_performant_intr_pending(struct ctlr_info *h)
48835 }
48836
48837 static struct access_method SA5_access = {
48838- SA5_submit_command,
48839- SA5_intr_mask,
48840- SA5_fifo_full,
48841- SA5_intr_pending,
48842- SA5_completed,
48843+ .submit_command = SA5_submit_command,
48844+ .set_intr_mask = SA5_intr_mask,
48845+ .fifo_full = SA5_fifo_full,
48846+ .intr_pending = SA5_intr_pending,
48847+ .command_completed = SA5_completed,
48848 };
48849
48850 static struct access_method SA5_performant_access = {
48851- SA5_submit_command,
48852- SA5_performant_intr_mask,
48853- SA5_fifo_full,
48854- SA5_performant_intr_pending,
48855- SA5_performant_completed,
48856+ .submit_command = SA5_submit_command,
48857+ .set_intr_mask = SA5_performant_intr_mask,
48858+ .fifo_full = SA5_fifo_full,
48859+ .intr_pending = SA5_performant_intr_pending,
48860+ .command_completed = SA5_performant_completed,
48861 };
48862
48863 struct board_type {
48864diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
48865index 1b3a094..068e683 100644
48866--- a/drivers/scsi/libfc/fc_exch.c
48867+++ b/drivers/scsi/libfc/fc_exch.c
48868@@ -101,12 +101,12 @@ struct fc_exch_mgr {
48869 u16 pool_max_index;
48870
48871 struct {
48872- atomic_t no_free_exch;
48873- atomic_t no_free_exch_xid;
48874- atomic_t xid_not_found;
48875- atomic_t xid_busy;
48876- atomic_t seq_not_found;
48877- atomic_t non_bls_resp;
48878+ atomic_unchecked_t no_free_exch;
48879+ atomic_unchecked_t no_free_exch_xid;
48880+ atomic_unchecked_t xid_not_found;
48881+ atomic_unchecked_t xid_busy;
48882+ atomic_unchecked_t seq_not_found;
48883+ atomic_unchecked_t non_bls_resp;
48884 } stats;
48885 };
48886
48887@@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
48888 /* allocate memory for exchange */
48889 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
48890 if (!ep) {
48891- atomic_inc(&mp->stats.no_free_exch);
48892+ atomic_inc_unchecked(&mp->stats.no_free_exch);
48893 goto out;
48894 }
48895 memset(ep, 0, sizeof(*ep));
48896@@ -874,7 +874,7 @@ out:
48897 return ep;
48898 err:
48899 spin_unlock_bh(&pool->lock);
48900- atomic_inc(&mp->stats.no_free_exch_xid);
48901+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
48902 mempool_free(ep, mp->ep_pool);
48903 return NULL;
48904 }
48905@@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48906 xid = ntohs(fh->fh_ox_id); /* we originated exch */
48907 ep = fc_exch_find(mp, xid);
48908 if (!ep) {
48909- atomic_inc(&mp->stats.xid_not_found);
48910+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48911 reject = FC_RJT_OX_ID;
48912 goto out;
48913 }
48914@@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48915 ep = fc_exch_find(mp, xid);
48916 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
48917 if (ep) {
48918- atomic_inc(&mp->stats.xid_busy);
48919+ atomic_inc_unchecked(&mp->stats.xid_busy);
48920 reject = FC_RJT_RX_ID;
48921 goto rel;
48922 }
48923@@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48924 }
48925 xid = ep->xid; /* get our XID */
48926 } else if (!ep) {
48927- atomic_inc(&mp->stats.xid_not_found);
48928+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48929 reject = FC_RJT_RX_ID; /* XID not found */
48930 goto out;
48931 }
48932@@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48933 } else {
48934 sp = &ep->seq;
48935 if (sp->id != fh->fh_seq_id) {
48936- atomic_inc(&mp->stats.seq_not_found);
48937+ atomic_inc_unchecked(&mp->stats.seq_not_found);
48938 if (f_ctl & FC_FC_END_SEQ) {
48939 /*
48940 * Update sequence_id based on incoming last
48941@@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48942
48943 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
48944 if (!ep) {
48945- atomic_inc(&mp->stats.xid_not_found);
48946+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48947 goto out;
48948 }
48949 if (ep->esb_stat & ESB_ST_COMPLETE) {
48950- atomic_inc(&mp->stats.xid_not_found);
48951+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48952 goto rel;
48953 }
48954 if (ep->rxid == FC_XID_UNKNOWN)
48955 ep->rxid = ntohs(fh->fh_rx_id);
48956 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
48957- atomic_inc(&mp->stats.xid_not_found);
48958+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48959 goto rel;
48960 }
48961 if (ep->did != ntoh24(fh->fh_s_id) &&
48962 ep->did != FC_FID_FLOGI) {
48963- atomic_inc(&mp->stats.xid_not_found);
48964+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48965 goto rel;
48966 }
48967 sof = fr_sof(fp);
48968@@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48969 sp->ssb_stat |= SSB_ST_RESP;
48970 sp->id = fh->fh_seq_id;
48971 } else if (sp->id != fh->fh_seq_id) {
48972- atomic_inc(&mp->stats.seq_not_found);
48973+ atomic_inc_unchecked(&mp->stats.seq_not_found);
48974 goto rel;
48975 }
48976
48977@@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48978 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
48979
48980 if (!sp)
48981- atomic_inc(&mp->stats.xid_not_found);
48982+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48983 else
48984- atomic_inc(&mp->stats.non_bls_resp);
48985+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
48986
48987 fc_frame_free(fp);
48988 }
48989@@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
48990
48991 list_for_each_entry(ema, &lport->ema_list, ema_list) {
48992 mp = ema->mp;
48993- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
48994+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
48995 st->fc_no_free_exch_xid +=
48996- atomic_read(&mp->stats.no_free_exch_xid);
48997- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
48998- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
48999- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
49000- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
49001+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
49002+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
49003+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
49004+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
49005+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
49006 }
49007 }
49008 EXPORT_SYMBOL(fc_exch_update_stats);
49009diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
49010index d289583..b745eec 100644
49011--- a/drivers/scsi/libsas/sas_ata.c
49012+++ b/drivers/scsi/libsas/sas_ata.c
49013@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
49014 .postreset = ata_std_postreset,
49015 .error_handler = ata_std_error_handler,
49016 .post_internal_cmd = sas_ata_post_internal,
49017- .qc_defer = ata_std_qc_defer,
49018+ .qc_defer = ata_std_qc_defer,
49019 .qc_prep = ata_noop_qc_prep,
49020 .qc_issue = sas_ata_qc_issue,
49021 .qc_fill_rtf = sas_ata_qc_fill_rtf,
49022diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
49023index 4e1b75c..0bbdfa9 100644
49024--- a/drivers/scsi/lpfc/lpfc.h
49025+++ b/drivers/scsi/lpfc/lpfc.h
49026@@ -432,7 +432,7 @@ struct lpfc_vport {
49027 struct dentry *debug_nodelist;
49028 struct dentry *vport_debugfs_root;
49029 struct lpfc_debugfs_trc *disc_trc;
49030- atomic_t disc_trc_cnt;
49031+ atomic_unchecked_t disc_trc_cnt;
49032 #endif
49033 uint8_t stat_data_enabled;
49034 uint8_t stat_data_blocked;
49035@@ -865,8 +865,8 @@ struct lpfc_hba {
49036 struct timer_list fabric_block_timer;
49037 unsigned long bit_flags;
49038 #define FABRIC_COMANDS_BLOCKED 0
49039- atomic_t num_rsrc_err;
49040- atomic_t num_cmd_success;
49041+ atomic_unchecked_t num_rsrc_err;
49042+ atomic_unchecked_t num_cmd_success;
49043 unsigned long last_rsrc_error_time;
49044 unsigned long last_ramp_down_time;
49045 unsigned long last_ramp_up_time;
49046@@ -902,7 +902,7 @@ struct lpfc_hba {
49047
49048 struct dentry *debug_slow_ring_trc;
49049 struct lpfc_debugfs_trc *slow_ring_trc;
49050- atomic_t slow_ring_trc_cnt;
49051+ atomic_unchecked_t slow_ring_trc_cnt;
49052 /* iDiag debugfs sub-directory */
49053 struct dentry *idiag_root;
49054 struct dentry *idiag_pci_cfg;
49055diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
49056index 60084e6..0e2e700 100644
49057--- a/drivers/scsi/lpfc/lpfc_debugfs.c
49058+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
49059@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
49060
49061 #include <linux/debugfs.h>
49062
49063-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49064+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49065 static unsigned long lpfc_debugfs_start_time = 0L;
49066
49067 /* iDiag */
49068@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
49069 lpfc_debugfs_enable = 0;
49070
49071 len = 0;
49072- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
49073+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
49074 (lpfc_debugfs_max_disc_trc - 1);
49075 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
49076 dtp = vport->disc_trc + i;
49077@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
49078 lpfc_debugfs_enable = 0;
49079
49080 len = 0;
49081- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
49082+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
49083 (lpfc_debugfs_max_slow_ring_trc - 1);
49084 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
49085 dtp = phba->slow_ring_trc + i;
49086@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
49087 !vport || !vport->disc_trc)
49088 return;
49089
49090- index = atomic_inc_return(&vport->disc_trc_cnt) &
49091+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
49092 (lpfc_debugfs_max_disc_trc - 1);
49093 dtp = vport->disc_trc + index;
49094 dtp->fmt = fmt;
49095 dtp->data1 = data1;
49096 dtp->data2 = data2;
49097 dtp->data3 = data3;
49098- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49099+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49100 dtp->jif = jiffies;
49101 #endif
49102 return;
49103@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
49104 !phba || !phba->slow_ring_trc)
49105 return;
49106
49107- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
49108+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
49109 (lpfc_debugfs_max_slow_ring_trc - 1);
49110 dtp = phba->slow_ring_trc + index;
49111 dtp->fmt = fmt;
49112 dtp->data1 = data1;
49113 dtp->data2 = data2;
49114 dtp->data3 = data3;
49115- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49116+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49117 dtp->jif = jiffies;
49118 #endif
49119 return;
49120@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49121 "slow_ring buffer\n");
49122 goto debug_failed;
49123 }
49124- atomic_set(&phba->slow_ring_trc_cnt, 0);
49125+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49126 memset(phba->slow_ring_trc, 0,
49127 (sizeof(struct lpfc_debugfs_trc) *
49128 lpfc_debugfs_max_slow_ring_trc));
49129@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49130 "buffer\n");
49131 goto debug_failed;
49132 }
49133- atomic_set(&vport->disc_trc_cnt, 0);
49134+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49135
49136 snprintf(name, sizeof(name), "discovery_trace");
49137 vport->debug_disc_trc =
49138diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49139index 68c94cc..8c27be5 100644
49140--- a/drivers/scsi/lpfc/lpfc_init.c
49141+++ b/drivers/scsi/lpfc/lpfc_init.c
49142@@ -10949,8 +10949,10 @@ lpfc_init(void)
49143 "misc_register returned with status %d", error);
49144
49145 if (lpfc_enable_npiv) {
49146- lpfc_transport_functions.vport_create = lpfc_vport_create;
49147- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49148+ pax_open_kernel();
49149+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49150+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49151+ pax_close_kernel();
49152 }
49153 lpfc_transport_template =
49154 fc_attach_transport(&lpfc_transport_functions);
49155diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49156index b2ede05..aaf482ca 100644
49157--- a/drivers/scsi/lpfc/lpfc_scsi.c
49158+++ b/drivers/scsi/lpfc/lpfc_scsi.c
49159@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49160 uint32_t evt_posted;
49161
49162 spin_lock_irqsave(&phba->hbalock, flags);
49163- atomic_inc(&phba->num_rsrc_err);
49164+ atomic_inc_unchecked(&phba->num_rsrc_err);
49165 phba->last_rsrc_error_time = jiffies;
49166
49167 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49168@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
49169 unsigned long flags;
49170 struct lpfc_hba *phba = vport->phba;
49171 uint32_t evt_posted;
49172- atomic_inc(&phba->num_cmd_success);
49173+ atomic_inc_unchecked(&phba->num_cmd_success);
49174
49175 if (vport->cfg_lun_queue_depth <= queue_depth)
49176 return;
49177@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49178 unsigned long num_rsrc_err, num_cmd_success;
49179 int i;
49180
49181- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49182- num_cmd_success = atomic_read(&phba->num_cmd_success);
49183+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49184+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49185
49186 /*
49187 * The error and success command counters are global per
49188@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49189 }
49190 }
49191 lpfc_destroy_vport_work_array(phba, vports);
49192- atomic_set(&phba->num_rsrc_err, 0);
49193- atomic_set(&phba->num_cmd_success, 0);
49194+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49195+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49196 }
49197
49198 /**
49199@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
49200 }
49201 }
49202 lpfc_destroy_vport_work_array(phba, vports);
49203- atomic_set(&phba->num_rsrc_err, 0);
49204- atomic_set(&phba->num_cmd_success, 0);
49205+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49206+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49207 }
49208
49209 /**
49210diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49211index 7f0af4f..193ac3e 100644
49212--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49213+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49214@@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49215 {
49216 struct scsi_device *sdev = to_scsi_device(dev);
49217 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49218- static struct _raid_device *raid_device;
49219+ struct _raid_device *raid_device;
49220 unsigned long flags;
49221 Mpi2RaidVolPage0_t vol_pg0;
49222 Mpi2ConfigReply_t mpi_reply;
49223@@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49224 {
49225 struct scsi_device *sdev = to_scsi_device(dev);
49226 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49227- static struct _raid_device *raid_device;
49228+ struct _raid_device *raid_device;
49229 unsigned long flags;
49230 Mpi2RaidVolPage0_t vol_pg0;
49231 Mpi2ConfigReply_t mpi_reply;
49232@@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49233 struct fw_event_work *fw_event)
49234 {
49235 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49236- static struct _raid_device *raid_device;
49237+ struct _raid_device *raid_device;
49238 unsigned long flags;
49239 u16 handle;
49240
49241@@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49242 u64 sas_address;
49243 struct _sas_device *sas_device;
49244 struct _sas_node *expander_device;
49245- static struct _raid_device *raid_device;
49246+ struct _raid_device *raid_device;
49247 u8 retry_count;
49248 unsigned long flags;
49249
49250diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49251index be8ce54..94ed33a 100644
49252--- a/drivers/scsi/pmcraid.c
49253+++ b/drivers/scsi/pmcraid.c
49254@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49255 res->scsi_dev = scsi_dev;
49256 scsi_dev->hostdata = res;
49257 res->change_detected = 0;
49258- atomic_set(&res->read_failures, 0);
49259- atomic_set(&res->write_failures, 0);
49260+ atomic_set_unchecked(&res->read_failures, 0);
49261+ atomic_set_unchecked(&res->write_failures, 0);
49262 rc = 0;
49263 }
49264 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49265@@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49266
49267 /* If this was a SCSI read/write command keep count of errors */
49268 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49269- atomic_inc(&res->read_failures);
49270+ atomic_inc_unchecked(&res->read_failures);
49271 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49272- atomic_inc(&res->write_failures);
49273+ atomic_inc_unchecked(&res->write_failures);
49274
49275 if (!RES_IS_GSCSI(res->cfg_entry) &&
49276 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49277@@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49278 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49279 * hrrq_id assigned here in queuecommand
49280 */
49281- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49282+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49283 pinstance->num_hrrq;
49284 cmd->cmd_done = pmcraid_io_done;
49285
49286@@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49287 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49288 * hrrq_id assigned here in queuecommand
49289 */
49290- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49291+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49292 pinstance->num_hrrq;
49293
49294 if (request_size) {
49295@@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49296
49297 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49298 /* add resources only after host is added into system */
49299- if (!atomic_read(&pinstance->expose_resources))
49300+ if (!atomic_read_unchecked(&pinstance->expose_resources))
49301 return;
49302
49303 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49304@@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49305 init_waitqueue_head(&pinstance->reset_wait_q);
49306
49307 atomic_set(&pinstance->outstanding_cmds, 0);
49308- atomic_set(&pinstance->last_message_id, 0);
49309- atomic_set(&pinstance->expose_resources, 0);
49310+ atomic_set_unchecked(&pinstance->last_message_id, 0);
49311+ atomic_set_unchecked(&pinstance->expose_resources, 0);
49312
49313 INIT_LIST_HEAD(&pinstance->free_res_q);
49314 INIT_LIST_HEAD(&pinstance->used_res_q);
49315@@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49316 /* Schedule worker thread to handle CCN and take care of adding and
49317 * removing devices to OS
49318 */
49319- atomic_set(&pinstance->expose_resources, 1);
49320+ atomic_set_unchecked(&pinstance->expose_resources, 1);
49321 schedule_work(&pinstance->worker_q);
49322 return rc;
49323
49324diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49325index e1d150f..6c6df44 100644
49326--- a/drivers/scsi/pmcraid.h
49327+++ b/drivers/scsi/pmcraid.h
49328@@ -748,7 +748,7 @@ struct pmcraid_instance {
49329 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49330
49331 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49332- atomic_t last_message_id;
49333+ atomic_unchecked_t last_message_id;
49334
49335 /* configuration table */
49336 struct pmcraid_config_table *cfg_table;
49337@@ -777,7 +777,7 @@ struct pmcraid_instance {
49338 atomic_t outstanding_cmds;
49339
49340 /* should add/delete resources to mid-layer now ?*/
49341- atomic_t expose_resources;
49342+ atomic_unchecked_t expose_resources;
49343
49344
49345
49346@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49347 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49348 };
49349 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49350- atomic_t read_failures; /* count of failed READ commands */
49351- atomic_t write_failures; /* count of failed WRITE commands */
49352+ atomic_unchecked_t read_failures; /* count of failed READ commands */
49353+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49354
49355 /* To indicate add/delete/modify during CCN */
49356 u8 change_detected;
49357diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49358index 5f174b8..98d32b0 100644
49359--- a/drivers/scsi/qla2xxx/qla_attr.c
49360+++ b/drivers/scsi/qla2xxx/qla_attr.c
49361@@ -2040,7 +2040,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49362 return 0;
49363 }
49364
49365-struct fc_function_template qla2xxx_transport_functions = {
49366+fc_function_template_no_const qla2xxx_transport_functions = {
49367
49368 .show_host_node_name = 1,
49369 .show_host_port_name = 1,
49370@@ -2088,7 +2088,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49371 .bsg_timeout = qla24xx_bsg_timeout,
49372 };
49373
49374-struct fc_function_template qla2xxx_transport_vport_functions = {
49375+fc_function_template_no_const qla2xxx_transport_vport_functions = {
49376
49377 .show_host_node_name = 1,
49378 .show_host_port_name = 1,
49379diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49380index 4446bf5..9a3574d 100644
49381--- a/drivers/scsi/qla2xxx/qla_gbl.h
49382+++ b/drivers/scsi/qla2xxx/qla_gbl.h
49383@@ -538,8 +538,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49384 struct device_attribute;
49385 extern struct device_attribute *qla2x00_host_attrs[];
49386 struct fc_function_template;
49387-extern struct fc_function_template qla2xxx_transport_functions;
49388-extern struct fc_function_template qla2xxx_transport_vport_functions;
49389+extern fc_function_template_no_const qla2xxx_transport_functions;
49390+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49391 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49392 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
49393 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49394diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49395index 52be35e..b933907 100644
49396--- a/drivers/scsi/qla2xxx/qla_os.c
49397+++ b/drivers/scsi/qla2xxx/qla_os.c
49398@@ -1568,8 +1568,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49399 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49400 /* Ok, a 64bit DMA mask is applicable. */
49401 ha->flags.enable_64bit_addressing = 1;
49402- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49403- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49404+ pax_open_kernel();
49405+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49406+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49407+ pax_close_kernel();
49408 return;
49409 }
49410 }
49411diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49412index 084d1fd..9f939eb 100644
49413--- a/drivers/scsi/qla4xxx/ql4_def.h
49414+++ b/drivers/scsi/qla4xxx/ql4_def.h
49415@@ -296,7 +296,7 @@ struct ddb_entry {
49416 * (4000 only) */
49417 atomic_t relogin_timer; /* Max Time to wait for
49418 * relogin to complete */
49419- atomic_t relogin_retry_count; /* Num of times relogin has been
49420+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49421 * retried */
49422 uint32_t default_time2wait; /* Default Min time between
49423 * relogins (+aens) */
49424diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49425index cf174a4..128a420 100644
49426--- a/drivers/scsi/qla4xxx/ql4_os.c
49427+++ b/drivers/scsi/qla4xxx/ql4_os.c
49428@@ -3311,12 +3311,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49429 */
49430 if (!iscsi_is_session_online(cls_sess)) {
49431 /* Reset retry relogin timer */
49432- atomic_inc(&ddb_entry->relogin_retry_count);
49433+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49434 DEBUG2(ql4_printk(KERN_INFO, ha,
49435 "%s: index[%d] relogin timed out-retrying"
49436 " relogin (%d), retry (%d)\n", __func__,
49437 ddb_entry->fw_ddb_index,
49438- atomic_read(&ddb_entry->relogin_retry_count),
49439+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49440 ddb_entry->default_time2wait + 4));
49441 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49442 atomic_set(&ddb_entry->retry_relogin_timer,
49443@@ -5458,7 +5458,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49444
49445 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49446 atomic_set(&ddb_entry->relogin_timer, 0);
49447- atomic_set(&ddb_entry->relogin_retry_count, 0);
49448+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49449 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49450 ddb_entry->default_relogin_timeout =
49451 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49452diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
49453index fe0bcb1..c9255be 100644
49454--- a/drivers/scsi/scsi.c
49455+++ b/drivers/scsi/scsi.c
49456@@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
49457 struct Scsi_Host *host = cmd->device->host;
49458 int rtn = 0;
49459
49460- atomic_inc(&cmd->device->iorequest_cnt);
49461+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49462
49463 /* check if the device is still usable */
49464 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
49465diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
49466index 62ec84b..93159d8 100644
49467--- a/drivers/scsi/scsi_lib.c
49468+++ b/drivers/scsi/scsi_lib.c
49469@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
49470 shost = sdev->host;
49471 scsi_init_cmd_errh(cmd);
49472 cmd->result = DID_NO_CONNECT << 16;
49473- atomic_inc(&cmd->device->iorequest_cnt);
49474+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49475
49476 /*
49477 * SCSI request completion path will do scsi_device_unbusy(),
49478@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
49479
49480 INIT_LIST_HEAD(&cmd->eh_entry);
49481
49482- atomic_inc(&cmd->device->iodone_cnt);
49483+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
49484 if (cmd->result)
49485- atomic_inc(&cmd->device->ioerr_cnt);
49486+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
49487
49488 disposition = scsi_decide_disposition(cmd);
49489 if (disposition != SUCCESS &&
49490diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
49491index 8ff62c2..693b6f7 100644
49492--- a/drivers/scsi/scsi_sysfs.c
49493+++ b/drivers/scsi/scsi_sysfs.c
49494@@ -725,7 +725,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
49495 char *buf) \
49496 { \
49497 struct scsi_device *sdev = to_scsi_device(dev); \
49498- unsigned long long count = atomic_read(&sdev->field); \
49499+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
49500 return snprintf(buf, 20, "0x%llx\n", count); \
49501 } \
49502 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
49503diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
49504index 84a1fdf..693b0d6 100644
49505--- a/drivers/scsi/scsi_tgt_lib.c
49506+++ b/drivers/scsi/scsi_tgt_lib.c
49507@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
49508 int err;
49509
49510 dprintk("%lx %u\n", uaddr, len);
49511- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
49512+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
49513 if (err) {
49514 /*
49515 * TODO: need to fixup sg_tablesize, max_segment_size,
49516diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
49517index 4628fd5..a94a1c2 100644
49518--- a/drivers/scsi/scsi_transport_fc.c
49519+++ b/drivers/scsi/scsi_transport_fc.c
49520@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
49521 * Netlink Infrastructure
49522 */
49523
49524-static atomic_t fc_event_seq;
49525+static atomic_unchecked_t fc_event_seq;
49526
49527 /**
49528 * fc_get_event_number - Obtain the next sequential FC event number
49529@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
49530 u32
49531 fc_get_event_number(void)
49532 {
49533- return atomic_add_return(1, &fc_event_seq);
49534+ return atomic_add_return_unchecked(1, &fc_event_seq);
49535 }
49536 EXPORT_SYMBOL(fc_get_event_number);
49537
49538@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
49539 {
49540 int error;
49541
49542- atomic_set(&fc_event_seq, 0);
49543+ atomic_set_unchecked(&fc_event_seq, 0);
49544
49545 error = transport_class_register(&fc_host_class);
49546 if (error)
49547@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
49548 char *cp;
49549
49550 *val = simple_strtoul(buf, &cp, 0);
49551- if ((*cp && (*cp != '\n')) || (*val < 0))
49552+ if (*cp && (*cp != '\n'))
49553 return -EINVAL;
49554 /*
49555 * Check for overflow; dev_loss_tmo is u32
49556diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
49557index 63a6ca4..5d5cadd 100644
49558--- a/drivers/scsi/scsi_transport_iscsi.c
49559+++ b/drivers/scsi/scsi_transport_iscsi.c
49560@@ -79,7 +79,7 @@ struct iscsi_internal {
49561 struct transport_container session_cont;
49562 };
49563
49564-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
49565+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
49566 static struct workqueue_struct *iscsi_eh_timer_workq;
49567
49568 static DEFINE_IDA(iscsi_sess_ida);
49569@@ -1737,7 +1737,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
49570 int err;
49571
49572 ihost = shost->shost_data;
49573- session->sid = atomic_add_return(1, &iscsi_session_nr);
49574+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
49575
49576 if (target_id == ISCSI_MAX_TARGET) {
49577 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
49578@@ -4103,7 +4103,7 @@ static __init int iscsi_transport_init(void)
49579 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
49580 ISCSI_TRANSPORT_VERSION);
49581
49582- atomic_set(&iscsi_session_nr, 0);
49583+ atomic_set_unchecked(&iscsi_session_nr, 0);
49584
49585 err = class_register(&iscsi_transport_class);
49586 if (err)
49587diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
49588index 2700a5a..752ec38 100644
49589--- a/drivers/scsi/scsi_transport_srp.c
49590+++ b/drivers/scsi/scsi_transport_srp.c
49591@@ -36,7 +36,7 @@
49592 #include "scsi_transport_srp_internal.h"
49593
49594 struct srp_host_attrs {
49595- atomic_t next_port_id;
49596+ atomic_unchecked_t next_port_id;
49597 };
49598 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
49599
49600@@ -94,7 +94,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
49601 struct Scsi_Host *shost = dev_to_shost(dev);
49602 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
49603
49604- atomic_set(&srp_host->next_port_id, 0);
49605+ atomic_set_unchecked(&srp_host->next_port_id, 0);
49606 return 0;
49607 }
49608
49609@@ -730,7 +730,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
49610 rport_fast_io_fail_timedout);
49611 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
49612
49613- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
49614+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
49615 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
49616
49617 transport_setup_device(&rport->dev);
49618diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
49619index 69725f7..03aaee1 100644
49620--- a/drivers/scsi/sd.c
49621+++ b/drivers/scsi/sd.c
49622@@ -2964,7 +2964,7 @@ static int sd_probe(struct device *dev)
49623 sdkp->disk = gd;
49624 sdkp->index = index;
49625 atomic_set(&sdkp->openers, 0);
49626- atomic_set(&sdkp->device->ioerr_cnt, 0);
49627+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
49628
49629 if (!sdp->request_queue->rq_timeout) {
49630 if (sdp->type != TYPE_MOD)
49631diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
49632index df5e961..df6b97f 100644
49633--- a/drivers/scsi/sg.c
49634+++ b/drivers/scsi/sg.c
49635@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
49636 sdp->disk->disk_name,
49637 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
49638 NULL,
49639- (char *)arg);
49640+ (char __user *)arg);
49641 case BLKTRACESTART:
49642 return blk_trace_startstop(sdp->device->request_queue, 1);
49643 case BLKTRACESTOP:
49644diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
49645index 349ebba..ff2a249 100644
49646--- a/drivers/spi/spi.c
49647+++ b/drivers/spi/spi.c
49648@@ -1945,7 +1945,7 @@ int spi_bus_unlock(struct spi_master *master)
49649 EXPORT_SYMBOL_GPL(spi_bus_unlock);
49650
49651 /* portable code must never pass more than 32 bytes */
49652-#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
49653+#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
49654
49655 static u8 *buf;
49656
49657diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
49658index 2c61783..4d49e4e 100644
49659--- a/drivers/staging/android/timed_output.c
49660+++ b/drivers/staging/android/timed_output.c
49661@@ -25,7 +25,7 @@
49662 #include "timed_output.h"
49663
49664 static struct class *timed_output_class;
49665-static atomic_t device_count;
49666+static atomic_unchecked_t device_count;
49667
49668 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
49669 char *buf)
49670@@ -63,7 +63,7 @@ static int create_timed_output_class(void)
49671 timed_output_class = class_create(THIS_MODULE, "timed_output");
49672 if (IS_ERR(timed_output_class))
49673 return PTR_ERR(timed_output_class);
49674- atomic_set(&device_count, 0);
49675+ atomic_set_unchecked(&device_count, 0);
49676 timed_output_class->dev_groups = timed_output_groups;
49677 }
49678
49679@@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
49680 if (ret < 0)
49681 return ret;
49682
49683- tdev->index = atomic_inc_return(&device_count);
49684+ tdev->index = atomic_inc_return_unchecked(&device_count);
49685 tdev->dev = device_create(timed_output_class, NULL,
49686 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
49687 if (IS_ERR(tdev->dev))
49688diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
49689index c0f7cd7..5424212 100644
49690--- a/drivers/staging/gdm724x/gdm_tty.c
49691+++ b/drivers/staging/gdm724x/gdm_tty.c
49692@@ -45,7 +45,7 @@
49693 #define gdm_tty_send_control(n, r, v, d, l) (\
49694 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
49695
49696-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
49697+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
49698
49699 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
49700 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
49701diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
49702index 96e4eee..6d7c37e 100644
49703--- a/drivers/staging/imx-drm/imx-drm-core.c
49704+++ b/drivers/staging/imx-drm/imx-drm-core.c
49705@@ -510,7 +510,7 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
49706 goto err_busy;
49707 }
49708
49709- if (imxdrm->drm->open_count) {
49710+ if (local_read(&imxdrm->drm->open_count)) {
49711 ret = -EBUSY;
49712 goto err_busy;
49713 }
49714@@ -590,7 +590,7 @@ int imx_drm_add_encoder(struct drm_encoder *encoder,
49715
49716 mutex_lock(&imxdrm->mutex);
49717
49718- if (imxdrm->drm->open_count) {
49719+ if (local_read(&imxdrm->drm->open_count)) {
49720 ret = -EBUSY;
49721 goto err_busy;
49722 }
49723@@ -729,7 +729,7 @@ int imx_drm_add_connector(struct drm_connector *connector,
49724
49725 mutex_lock(&imxdrm->mutex);
49726
49727- if (imxdrm->drm->open_count) {
49728+ if (local_read(&imxdrm->drm->open_count)) {
49729 ret = -EBUSY;
49730 goto err_busy;
49731 }
49732diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
49733index b7613c8..c302392 100644
49734--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
49735+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
49736@@ -487,13 +487,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
49737 return 0;
49738 }
49739
49740-sfw_test_client_ops_t brw_test_client;
49741-void brw_init_test_client(void)
49742-{
49743- brw_test_client.tso_init = brw_client_init;
49744- brw_test_client.tso_fini = brw_client_fini;
49745- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
49746- brw_test_client.tso_done_rpc = brw_client_done_rpc;
49747+sfw_test_client_ops_t brw_test_client = {
49748+ .tso_init = brw_client_init,
49749+ .tso_fini = brw_client_fini,
49750+ .tso_prep_rpc = brw_client_prep_rpc,
49751+ .tso_done_rpc = brw_client_done_rpc,
49752 };
49753
49754 srpc_service_t brw_test_service;
49755diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
49756index 483c785..e1a2a7b 100644
49757--- a/drivers/staging/lustre/lnet/selftest/framework.c
49758+++ b/drivers/staging/lustre/lnet/selftest/framework.c
49759@@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
49760
49761 extern sfw_test_client_ops_t ping_test_client;
49762 extern srpc_service_t ping_test_service;
49763-extern void ping_init_test_client(void);
49764 extern void ping_init_test_service(void);
49765
49766 extern sfw_test_client_ops_t brw_test_client;
49767 extern srpc_service_t brw_test_service;
49768-extern void brw_init_test_client(void);
49769 extern void brw_init_test_service(void);
49770
49771
49772@@ -1684,12 +1682,10 @@ sfw_startup (void)
49773 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
49774 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
49775
49776- brw_init_test_client();
49777 brw_init_test_service();
49778 rc = sfw_register_test(&brw_test_service, &brw_test_client);
49779 LASSERT (rc == 0);
49780
49781- ping_init_test_client();
49782 ping_init_test_service();
49783 rc = sfw_register_test(&ping_test_service, &ping_test_client);
49784 LASSERT (rc == 0);
49785diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
49786index f0f9194..b589047 100644
49787--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
49788+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
49789@@ -210,14 +210,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
49790 return 0;
49791 }
49792
49793-sfw_test_client_ops_t ping_test_client;
49794-void ping_init_test_client(void)
49795-{
49796- ping_test_client.tso_init = ping_client_init;
49797- ping_test_client.tso_fini = ping_client_fini;
49798- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
49799- ping_test_client.tso_done_rpc = ping_client_done_rpc;
49800-}
49801+sfw_test_client_ops_t ping_test_client = {
49802+ .tso_init = ping_client_init,
49803+ .tso_fini = ping_client_fini,
49804+ .tso_prep_rpc = ping_client_prep_rpc,
49805+ .tso_done_rpc = ping_client_done_rpc,
49806+};
49807
49808 srpc_service_t ping_test_service;
49809 void ping_init_test_service(void)
49810diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49811index bc2b82f..67fd598 100644
49812--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
49813+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49814@@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
49815 ldlm_completion_callback lcs_completion;
49816 ldlm_blocking_callback lcs_blocking;
49817 ldlm_glimpse_callback lcs_glimpse;
49818-};
49819+} __no_const;
49820
49821 /* ldlm_lockd.c */
49822 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
49823diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
49824index d0aea15..7af68e1 100644
49825--- a/drivers/staging/lustre/lustre/include/obd.h
49826+++ b/drivers/staging/lustre/lustre/include/obd.h
49827@@ -1417,7 +1417,7 @@ struct md_ops {
49828 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
49829 * wrapper function in include/linux/obd_class.h.
49830 */
49831-};
49832+} __no_const;
49833
49834 struct lsm_operations {
49835 void (*lsm_free)(struct lov_stripe_md *);
49836diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49837index 39fcdac..222780f 100644
49838--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49839+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49840@@ -249,7 +249,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
49841 int added = (mode == LCK_NL);
49842 int overlaps = 0;
49843 int splitted = 0;
49844- const struct ldlm_callback_suite null_cbs = { NULL };
49845+ const struct ldlm_callback_suite null_cbs = { };
49846 int rc;
49847
49848 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
49849diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49850index fc6c977..df1f956 100644
49851--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49852+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49853@@ -219,7 +219,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
49854 int LL_PROC_PROTO(proc_console_max_delay_cs)
49855 {
49856 int rc, max_delay_cs;
49857- ctl_table_t dummy = *table;
49858+ ctl_table_no_const dummy = *table;
49859 cfs_duration_t d;
49860
49861 dummy.data = &max_delay_cs;
49862@@ -250,7 +250,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
49863 int LL_PROC_PROTO(proc_console_min_delay_cs)
49864 {
49865 int rc, min_delay_cs;
49866- ctl_table_t dummy = *table;
49867+ ctl_table_no_const dummy = *table;
49868 cfs_duration_t d;
49869
49870 dummy.data = &min_delay_cs;
49871@@ -281,7 +281,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
49872 int LL_PROC_PROTO(proc_console_backoff)
49873 {
49874 int rc, backoff;
49875- ctl_table_t dummy = *table;
49876+ ctl_table_no_const dummy = *table;
49877
49878 dummy.data = &backoff;
49879 dummy.proc_handler = &proc_dointvec;
49880diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
49881index f3108c7..cd4f9da 100644
49882--- a/drivers/staging/lustre/lustre/libcfs/module.c
49883+++ b/drivers/staging/lustre/lustre/libcfs/module.c
49884@@ -348,11 +348,11 @@ out:
49885
49886
49887 struct cfs_psdev_ops libcfs_psdev_ops = {
49888- libcfs_psdev_open,
49889- libcfs_psdev_release,
49890- NULL,
49891- NULL,
49892- libcfs_ioctl
49893+ .p_open = libcfs_psdev_open,
49894+ .p_close = libcfs_psdev_release,
49895+ .p_read = NULL,
49896+ .p_write = NULL,
49897+ .p_ioctl = libcfs_ioctl
49898 };
49899
49900 extern int insert_proc(void);
49901diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
49902index a4e0472..05d854c 100644
49903--- a/drivers/staging/lustre/lustre/llite/dir.c
49904+++ b/drivers/staging/lustre/lustre/llite/dir.c
49905@@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
49906 int mode;
49907 int err;
49908
49909- mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
49910+ mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
49911 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
49912 strlen(filename), mode, LUSTRE_OPC_MKDIR,
49913 lump);
49914diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
49915index 3675020..e80d92c 100644
49916--- a/drivers/staging/media/solo6x10/solo6x10-core.c
49917+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
49918@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
49919
49920 static int solo_sysfs_init(struct solo_dev *solo_dev)
49921 {
49922- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
49923+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
49924 struct device *dev = &solo_dev->dev;
49925 const char *driver;
49926 int i;
49927diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
49928index 1db18c7..35e6afc 100644
49929--- a/drivers/staging/media/solo6x10/solo6x10-g723.c
49930+++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
49931@@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
49932
49933 int solo_g723_init(struct solo_dev *solo_dev)
49934 {
49935- static struct snd_device_ops ops = { NULL };
49936+ static struct snd_device_ops ops = { };
49937 struct snd_card *card;
49938 struct snd_kcontrol_new kctl;
49939 char name[32];
49940diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49941index 7f2f247..d999137 100644
49942--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
49943+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49944@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
49945
49946 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
49947 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
49948- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
49949+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
49950 if (p2m_id < 0)
49951 p2m_id = -p2m_id;
49952 }
49953diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
49954index f1bbb8c..a73eaba 100644
49955--- a/drivers/staging/media/solo6x10/solo6x10.h
49956+++ b/drivers/staging/media/solo6x10/solo6x10.h
49957@@ -237,7 +237,7 @@ struct solo_dev {
49958
49959 /* P2M DMA Engine */
49960 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
49961- atomic_t p2m_count;
49962+ atomic_unchecked_t p2m_count;
49963 int p2m_jiffies;
49964 unsigned int p2m_timeouts;
49965
49966diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
49967index 0315f60..ce93f406 100644
49968--- a/drivers/staging/octeon/ethernet-rx.c
49969+++ b/drivers/staging/octeon/ethernet-rx.c
49970@@ -418,11 +418,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49971 /* Increment RX stats for virtual ports */
49972 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
49973 #ifdef CONFIG_64BIT
49974- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
49975- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
49976+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
49977+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
49978 #else
49979- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
49980- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
49981+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
49982+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
49983 #endif
49984 }
49985 netif_receive_skb(skb);
49986@@ -433,9 +433,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49987 dev->name);
49988 */
49989 #ifdef CONFIG_64BIT
49990- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
49991+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49992 #else
49993- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
49994+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
49995 #endif
49996 dev_kfree_skb_irq(skb);
49997 }
49998diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
49999index bd6ca71..8f0961e 100644
50000--- a/drivers/staging/octeon/ethernet.c
50001+++ b/drivers/staging/octeon/ethernet.c
50002@@ -254,11 +254,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
50003 * since the RX tasklet also increments it.
50004 */
50005 #ifdef CONFIG_64BIT
50006- atomic64_add(rx_status.dropped_packets,
50007- (atomic64_t *)&priv->stats.rx_dropped);
50008+ atomic64_add_unchecked(rx_status.dropped_packets,
50009+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50010 #else
50011- atomic_add(rx_status.dropped_packets,
50012- (atomic_t *)&priv->stats.rx_dropped);
50013+ atomic_add_unchecked(rx_status.dropped_packets,
50014+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
50015 #endif
50016 }
50017
50018diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
50019index 439c3c9..2d74293 100644
50020--- a/drivers/staging/rtl8188eu/include/hal_intf.h
50021+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
50022@@ -271,7 +271,7 @@ struct hal_ops {
50023 s32 (*c2h_handler)(struct adapter *padapter,
50024 struct c2h_evt_hdr *c2h_evt);
50025 c2h_id_filter c2h_id_filter_ccx;
50026-};
50027+} __no_const;
50028
50029 enum rt_eeprom_type {
50030 EEPROM_93C46,
50031diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
50032index eb6f0e5..e6a0958 100644
50033--- a/drivers/staging/rtl8188eu/include/rtw_io.h
50034+++ b/drivers/staging/rtl8188eu/include/rtw_io.h
50035@@ -126,7 +126,7 @@ struct _io_ops {
50036 u32 (*_write_scsi)(struct intf_hdl *pintfhdl,u32 cnt, u8 *pmem);
50037 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50038 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50039-};
50040+} __no_const;
50041
50042 struct io_req {
50043 struct list_head list;
50044diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
50045index dc23395..cf7e9b1 100644
50046--- a/drivers/staging/rtl8712/rtl871x_io.h
50047+++ b/drivers/staging/rtl8712/rtl871x_io.h
50048@@ -108,7 +108,7 @@ struct _io_ops {
50049 u8 *pmem);
50050 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
50051 u8 *pmem);
50052-};
50053+} __no_const;
50054
50055 struct io_req {
50056 struct list_head list;
50057diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
50058index 1f5088b..0e59820 100644
50059--- a/drivers/staging/sbe-2t3e3/netdev.c
50060+++ b/drivers/staging/sbe-2t3e3/netdev.c
50061@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50062 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
50063
50064 if (rlen)
50065- if (copy_to_user(data, &resp, rlen))
50066+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
50067 return -EFAULT;
50068
50069 return 0;
50070diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
50071index a863a98..d272795 100644
50072--- a/drivers/staging/usbip/vhci.h
50073+++ b/drivers/staging/usbip/vhci.h
50074@@ -83,7 +83,7 @@ struct vhci_hcd {
50075 unsigned resuming:1;
50076 unsigned long re_timeout;
50077
50078- atomic_t seqnum;
50079+ atomic_unchecked_t seqnum;
50080
50081 /*
50082 * NOTE:
50083diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
50084index e810ad5..931336f 100644
50085--- a/drivers/staging/usbip/vhci_hcd.c
50086+++ b/drivers/staging/usbip/vhci_hcd.c
50087@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
50088
50089 spin_lock(&vdev->priv_lock);
50090
50091- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
50092+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50093 if (priv->seqnum == 0xffff)
50094 dev_info(&urb->dev->dev, "seqnum max\n");
50095
50096@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
50097 return -ENOMEM;
50098 }
50099
50100- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
50101+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50102 if (unlink->seqnum == 0xffff)
50103 pr_info("seqnum max\n");
50104
50105@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
50106 vdev->rhport = rhport;
50107 }
50108
50109- atomic_set(&vhci->seqnum, 0);
50110+ atomic_set_unchecked(&vhci->seqnum, 0);
50111 spin_lock_init(&vhci->lock);
50112
50113 hcd->power_budget = 0; /* no limit */
50114diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
50115index d07fcb5..358e1e1 100644
50116--- a/drivers/staging/usbip/vhci_rx.c
50117+++ b/drivers/staging/usbip/vhci_rx.c
50118@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
50119 if (!urb) {
50120 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
50121 pr_info("max seqnum %d\n",
50122- atomic_read(&the_controller->seqnum));
50123+ atomic_read_unchecked(&the_controller->seqnum));
50124 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
50125 return;
50126 }
50127diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50128index ab8b2ba..99184aa 100644
50129--- a/drivers/staging/vt6655/hostap.c
50130+++ b/drivers/staging/vt6655/hostap.c
50131@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50132 *
50133 */
50134
50135+static net_device_ops_no_const apdev_netdev_ops;
50136+
50137 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50138 {
50139 PSDevice apdev_priv;
50140 struct net_device *dev = pDevice->dev;
50141 int ret;
50142- const struct net_device_ops apdev_netdev_ops = {
50143- .ndo_start_xmit = pDevice->tx_80211,
50144- };
50145
50146 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50147
50148@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50149 *apdev_priv = *pDevice;
50150 eth_hw_addr_inherit(pDevice->apdev, dev);
50151
50152+ /* only half broken now */
50153+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50154 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50155
50156 pDevice->apdev->type = ARPHRD_IEEE80211;
50157diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50158index 67ba48b..24e602f 100644
50159--- a/drivers/staging/vt6656/hostap.c
50160+++ b/drivers/staging/vt6656/hostap.c
50161@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50162 *
50163 */
50164
50165+static net_device_ops_no_const apdev_netdev_ops;
50166+
50167 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50168 {
50169 struct vnt_private *apdev_priv;
50170 struct net_device *dev = pDevice->dev;
50171 int ret;
50172- const struct net_device_ops apdev_netdev_ops = {
50173- .ndo_start_xmit = pDevice->tx_80211,
50174- };
50175
50176 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50177
50178@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50179 *apdev_priv = *pDevice;
50180 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50181
50182+ /* only half broken now */
50183+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50184 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50185
50186 pDevice->apdev->type = ARPHRD_IEEE80211;
50187diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50188index 24884ca..26c8220 100644
50189--- a/drivers/target/sbp/sbp_target.c
50190+++ b/drivers/target/sbp/sbp_target.c
50191@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50192
50193 #define SESSION_MAINTENANCE_INTERVAL HZ
50194
50195-static atomic_t login_id = ATOMIC_INIT(0);
50196+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50197
50198 static void session_maintenance_work(struct work_struct *);
50199 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50200@@ -444,7 +444,7 @@ static void sbp_management_request_login(
50201 login->lun = se_lun;
50202 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50203 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50204- login->login_id = atomic_inc_return(&login_id);
50205+ login->login_id = atomic_inc_return_unchecked(&login_id);
50206
50207 login->tgt_agt = sbp_target_agent_register(login);
50208 if (IS_ERR(login->tgt_agt)) {
50209diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50210index d06de84..fd38c9b 100644
50211--- a/drivers/target/target_core_device.c
50212+++ b/drivers/target/target_core_device.c
50213@@ -1435,7 +1435,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50214 spin_lock_init(&dev->se_tmr_lock);
50215 spin_lock_init(&dev->qf_cmd_lock);
50216 sema_init(&dev->caw_sem, 1);
50217- atomic_set(&dev->dev_ordered_id, 0);
50218+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
50219 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50220 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50221 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50222diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50223index dee2be1..f5fd8ca 100644
50224--- a/drivers/target/target_core_transport.c
50225+++ b/drivers/target/target_core_transport.c
50226@@ -1113,7 +1113,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50227 * Used to determine when ORDERED commands should go from
50228 * Dormant to Active status.
50229 */
50230- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50231+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50232 smp_mb__after_atomic_inc();
50233 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50234 cmd->se_ordered_id, cmd->sam_task_attr,
50235diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50236index 33f83fe..d80f8e1 100644
50237--- a/drivers/tty/cyclades.c
50238+++ b/drivers/tty/cyclades.c
50239@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50240 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50241 info->port.count);
50242 #endif
50243- info->port.count++;
50244+ atomic_inc(&info->port.count);
50245 #ifdef CY_DEBUG_COUNT
50246 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50247- current->pid, info->port.count);
50248+ current->pid, atomic_read(&info->port.count));
50249 #endif
50250
50251 /*
50252@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50253 for (j = 0; j < cy_card[i].nports; j++) {
50254 info = &cy_card[i].ports[j];
50255
50256- if (info->port.count) {
50257+ if (atomic_read(&info->port.count)) {
50258 /* XXX is the ldisc num worth this? */
50259 struct tty_struct *tty;
50260 struct tty_ldisc *ld;
50261diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50262index 9eba119..5070303 100644
50263--- a/drivers/tty/hvc/hvc_console.c
50264+++ b/drivers/tty/hvc/hvc_console.c
50265@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50266
50267 spin_lock_irqsave(&hp->port.lock, flags);
50268 /* Check and then increment for fast path open. */
50269- if (hp->port.count++ > 0) {
50270+ if (atomic_inc_return(&hp->port.count) > 1) {
50271 spin_unlock_irqrestore(&hp->port.lock, flags);
50272 hvc_kick();
50273 return 0;
50274@@ -393,7 +393,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50275
50276 spin_lock_irqsave(&hp->port.lock, flags);
50277
50278- if (--hp->port.count == 0) {
50279+ if (atomic_dec_return(&hp->port.count) == 0) {
50280 spin_unlock_irqrestore(&hp->port.lock, flags);
50281 /* We are done with the tty pointer now. */
50282 tty_port_tty_set(&hp->port, NULL);
50283@@ -415,9 +415,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50284 */
50285 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50286 } else {
50287- if (hp->port.count < 0)
50288+ if (atomic_read(&hp->port.count) < 0)
50289 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50290- hp->vtermno, hp->port.count);
50291+ hp->vtermno, atomic_read(&hp->port.count));
50292 spin_unlock_irqrestore(&hp->port.lock, flags);
50293 }
50294 }
50295@@ -447,12 +447,12 @@ static void hvc_hangup(struct tty_struct *tty)
50296 * open->hangup case this can be called after the final close so prevent
50297 * that from happening for now.
50298 */
50299- if (hp->port.count <= 0) {
50300+ if (atomic_read(&hp->port.count) <= 0) {
50301 spin_unlock_irqrestore(&hp->port.lock, flags);
50302 return;
50303 }
50304
50305- hp->port.count = 0;
50306+ atomic_set(&hp->port.count, 0);
50307 spin_unlock_irqrestore(&hp->port.lock, flags);
50308 tty_port_tty_set(&hp->port, NULL);
50309
50310@@ -500,7 +500,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50311 return -EPIPE;
50312
50313 /* FIXME what's this (unprotected) check for? */
50314- if (hp->port.count <= 0)
50315+ if (atomic_read(&hp->port.count) <= 0)
50316 return -EIO;
50317
50318 spin_lock_irqsave(&hp->lock, flags);
50319diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50320index 81e939e..95ead10 100644
50321--- a/drivers/tty/hvc/hvcs.c
50322+++ b/drivers/tty/hvc/hvcs.c
50323@@ -83,6 +83,7 @@
50324 #include <asm/hvcserver.h>
50325 #include <asm/uaccess.h>
50326 #include <asm/vio.h>
50327+#include <asm/local.h>
50328
50329 /*
50330 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50331@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50332
50333 spin_lock_irqsave(&hvcsd->lock, flags);
50334
50335- if (hvcsd->port.count > 0) {
50336+ if (atomic_read(&hvcsd->port.count) > 0) {
50337 spin_unlock_irqrestore(&hvcsd->lock, flags);
50338 printk(KERN_INFO "HVCS: vterm state unchanged. "
50339 "The hvcs device node is still in use.\n");
50340@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50341 }
50342 }
50343
50344- hvcsd->port.count = 0;
50345+ atomic_set(&hvcsd->port.count, 0);
50346 hvcsd->port.tty = tty;
50347 tty->driver_data = hvcsd;
50348
50349@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50350 unsigned long flags;
50351
50352 spin_lock_irqsave(&hvcsd->lock, flags);
50353- hvcsd->port.count++;
50354+ atomic_inc(&hvcsd->port.count);
50355 hvcsd->todo_mask |= HVCS_SCHED_READ;
50356 spin_unlock_irqrestore(&hvcsd->lock, flags);
50357
50358@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50359 hvcsd = tty->driver_data;
50360
50361 spin_lock_irqsave(&hvcsd->lock, flags);
50362- if (--hvcsd->port.count == 0) {
50363+ if (atomic_dec_and_test(&hvcsd->port.count)) {
50364
50365 vio_disable_interrupts(hvcsd->vdev);
50366
50367@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50368
50369 free_irq(irq, hvcsd);
50370 return;
50371- } else if (hvcsd->port.count < 0) {
50372+ } else if (atomic_read(&hvcsd->port.count) < 0) {
50373 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50374 " is missmanaged.\n",
50375- hvcsd->vdev->unit_address, hvcsd->port.count);
50376+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50377 }
50378
50379 spin_unlock_irqrestore(&hvcsd->lock, flags);
50380@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50381
50382 spin_lock_irqsave(&hvcsd->lock, flags);
50383 /* Preserve this so that we know how many kref refs to put */
50384- temp_open_count = hvcsd->port.count;
50385+ temp_open_count = atomic_read(&hvcsd->port.count);
50386
50387 /*
50388 * Don't kref put inside the spinlock because the destruction
50389@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50390 tty->driver_data = NULL;
50391 hvcsd->port.tty = NULL;
50392
50393- hvcsd->port.count = 0;
50394+ atomic_set(&hvcsd->port.count, 0);
50395
50396 /* This will drop any buffered data on the floor which is OK in a hangup
50397 * scenario. */
50398@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50399 * the middle of a write operation? This is a crummy place to do this
50400 * but we want to keep it all in the spinlock.
50401 */
50402- if (hvcsd->port.count <= 0) {
50403+ if (atomic_read(&hvcsd->port.count) <= 0) {
50404 spin_unlock_irqrestore(&hvcsd->lock, flags);
50405 return -ENODEV;
50406 }
50407@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
50408 {
50409 struct hvcs_struct *hvcsd = tty->driver_data;
50410
50411- if (!hvcsd || hvcsd->port.count <= 0)
50412+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
50413 return 0;
50414
50415 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
50416diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
50417index 4190199..06d5bfa 100644
50418--- a/drivers/tty/hvc/hvsi.c
50419+++ b/drivers/tty/hvc/hvsi.c
50420@@ -85,7 +85,7 @@ struct hvsi_struct {
50421 int n_outbuf;
50422 uint32_t vtermno;
50423 uint32_t virq;
50424- atomic_t seqno; /* HVSI packet sequence number */
50425+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
50426 uint16_t mctrl;
50427 uint8_t state; /* HVSI protocol state */
50428 uint8_t flags;
50429@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
50430
50431 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
50432 packet.hdr.len = sizeof(struct hvsi_query_response);
50433- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50434+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50435 packet.verb = VSV_SEND_VERSION_NUMBER;
50436 packet.u.version = HVSI_VERSION;
50437 packet.query_seqno = query_seqno+1;
50438@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
50439
50440 packet.hdr.type = VS_QUERY_PACKET_HEADER;
50441 packet.hdr.len = sizeof(struct hvsi_query);
50442- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50443+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50444 packet.verb = verb;
50445
50446 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
50447@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
50448 int wrote;
50449
50450 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
50451- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50452+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50453 packet.hdr.len = sizeof(struct hvsi_control);
50454 packet.verb = VSV_SET_MODEM_CTL;
50455 packet.mask = HVSI_TSDTR;
50456@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
50457 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
50458
50459 packet.hdr.type = VS_DATA_PACKET_HEADER;
50460- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50461+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50462 packet.hdr.len = count + sizeof(struct hvsi_header);
50463 memcpy(&packet.data, buf, count);
50464
50465@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
50466 struct hvsi_control packet __ALIGNED__;
50467
50468 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
50469- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50470+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50471 packet.hdr.len = 6;
50472 packet.verb = VSV_CLOSE_PROTOCOL;
50473
50474@@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
50475
50476 tty_port_tty_set(&hp->port, tty);
50477 spin_lock_irqsave(&hp->lock, flags);
50478- hp->port.count++;
50479+ atomic_inc(&hp->port.count);
50480 atomic_set(&hp->seqno, 0);
50481 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
50482 spin_unlock_irqrestore(&hp->lock, flags);
50483@@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50484
50485 spin_lock_irqsave(&hp->lock, flags);
50486
50487- if (--hp->port.count == 0) {
50488+ if (atomic_dec_return(&hp->port.count) == 0) {
50489 tty_port_tty_set(&hp->port, NULL);
50490 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
50491
50492@@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50493
50494 spin_lock_irqsave(&hp->lock, flags);
50495 }
50496- } else if (hp->port.count < 0)
50497+ } else if (atomic_read(&hp->port.count) < 0)
50498 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
50499- hp - hvsi_ports, hp->port.count);
50500+ hp - hvsi_ports, atomic_read(&hp->port.count));
50501
50502 spin_unlock_irqrestore(&hp->lock, flags);
50503 }
50504@@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
50505 tty_port_tty_set(&hp->port, NULL);
50506
50507 spin_lock_irqsave(&hp->lock, flags);
50508- hp->port.count = 0;
50509+ atomic_set(&hp->port.count, 0);
50510 hp->n_outbuf = 0;
50511 spin_unlock_irqrestore(&hp->lock, flags);
50512 }
50513diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
50514index 347050e..14f8fbf 100644
50515--- a/drivers/tty/hvc/hvsi_lib.c
50516+++ b/drivers/tty/hvc/hvsi_lib.c
50517@@ -9,7 +9,7 @@
50518
50519 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
50520 {
50521- packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
50522+ packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
50523
50524 /* Assumes that always succeeds, works in practice */
50525 return pv->put_chars(pv->termno, (char *)packet, packet->len);
50526@@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
50527
50528 /* Reset state */
50529 pv->established = 0;
50530- atomic_set(&pv->seqno, 0);
50531+ atomic_set_unchecked(&pv->seqno, 0);
50532
50533 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
50534
50535diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
50536index 8fd72ff..34a0bed 100644
50537--- a/drivers/tty/ipwireless/tty.c
50538+++ b/drivers/tty/ipwireless/tty.c
50539@@ -29,6 +29,7 @@
50540 #include <linux/tty_driver.h>
50541 #include <linux/tty_flip.h>
50542 #include <linux/uaccess.h>
50543+#include <asm/local.h>
50544
50545 #include "tty.h"
50546 #include "network.h"
50547@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50548 mutex_unlock(&tty->ipw_tty_mutex);
50549 return -ENODEV;
50550 }
50551- if (tty->port.count == 0)
50552+ if (atomic_read(&tty->port.count) == 0)
50553 tty->tx_bytes_queued = 0;
50554
50555- tty->port.count++;
50556+ atomic_inc(&tty->port.count);
50557
50558 tty->port.tty = linux_tty;
50559 linux_tty->driver_data = tty;
50560@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50561
50562 static void do_ipw_close(struct ipw_tty *tty)
50563 {
50564- tty->port.count--;
50565-
50566- if (tty->port.count == 0) {
50567+ if (atomic_dec_return(&tty->port.count) == 0) {
50568 struct tty_struct *linux_tty = tty->port.tty;
50569
50570 if (linux_tty != NULL) {
50571@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
50572 return;
50573
50574 mutex_lock(&tty->ipw_tty_mutex);
50575- if (tty->port.count == 0) {
50576+ if (atomic_read(&tty->port.count) == 0) {
50577 mutex_unlock(&tty->ipw_tty_mutex);
50578 return;
50579 }
50580@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
50581
50582 mutex_lock(&tty->ipw_tty_mutex);
50583
50584- if (!tty->port.count) {
50585+ if (!atomic_read(&tty->port.count)) {
50586 mutex_unlock(&tty->ipw_tty_mutex);
50587 return;
50588 }
50589@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
50590 return -ENODEV;
50591
50592 mutex_lock(&tty->ipw_tty_mutex);
50593- if (!tty->port.count) {
50594+ if (!atomic_read(&tty->port.count)) {
50595 mutex_unlock(&tty->ipw_tty_mutex);
50596 return -EINVAL;
50597 }
50598@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
50599 if (!tty)
50600 return -ENODEV;
50601
50602- if (!tty->port.count)
50603+ if (!atomic_read(&tty->port.count))
50604 return -EINVAL;
50605
50606 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
50607@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
50608 if (!tty)
50609 return 0;
50610
50611- if (!tty->port.count)
50612+ if (!atomic_read(&tty->port.count))
50613 return 0;
50614
50615 return tty->tx_bytes_queued;
50616@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
50617 if (!tty)
50618 return -ENODEV;
50619
50620- if (!tty->port.count)
50621+ if (!atomic_read(&tty->port.count))
50622 return -EINVAL;
50623
50624 return get_control_lines(tty);
50625@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
50626 if (!tty)
50627 return -ENODEV;
50628
50629- if (!tty->port.count)
50630+ if (!atomic_read(&tty->port.count))
50631 return -EINVAL;
50632
50633 return set_control_lines(tty, set, clear);
50634@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
50635 if (!tty)
50636 return -ENODEV;
50637
50638- if (!tty->port.count)
50639+ if (!atomic_read(&tty->port.count))
50640 return -EINVAL;
50641
50642 /* FIXME: Exactly how is the tty object locked here .. */
50643@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
50644 * are gone */
50645 mutex_lock(&ttyj->ipw_tty_mutex);
50646 }
50647- while (ttyj->port.count)
50648+ while (atomic_read(&ttyj->port.count))
50649 do_ipw_close(ttyj);
50650 ipwireless_disassociate_network_ttys(network,
50651 ttyj->channel_idx);
50652diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
50653index 1deaca4..c8582d4 100644
50654--- a/drivers/tty/moxa.c
50655+++ b/drivers/tty/moxa.c
50656@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
50657 }
50658
50659 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
50660- ch->port.count++;
50661+ atomic_inc(&ch->port.count);
50662 tty->driver_data = ch;
50663 tty_port_tty_set(&ch->port, tty);
50664 mutex_lock(&ch->port.mutex);
50665diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
50666index 5056090..c80ca04 100644
50667--- a/drivers/tty/n_gsm.c
50668+++ b/drivers/tty/n_gsm.c
50669@@ -1643,7 +1643,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
50670 spin_lock_init(&dlci->lock);
50671 mutex_init(&dlci->mutex);
50672 dlci->fifo = &dlci->_fifo;
50673- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
50674+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
50675 kfree(dlci);
50676 return NULL;
50677 }
50678@@ -2946,7 +2946,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
50679 struct gsm_dlci *dlci = tty->driver_data;
50680 struct tty_port *port = &dlci->port;
50681
50682- port->count++;
50683+ atomic_inc(&port->count);
50684 dlci_get(dlci);
50685 dlci_get(dlci->gsm->dlci[0]);
50686 mux_get(dlci->gsm);
50687diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
50688index 4c10837..a40ec45 100644
50689--- a/drivers/tty/n_tty.c
50690+++ b/drivers/tty/n_tty.c
50691@@ -114,7 +114,7 @@ struct n_tty_data {
50692 int minimum_to_wake;
50693
50694 /* consumer-published */
50695- size_t read_tail;
50696+ size_t read_tail __intentional_overflow(-1);
50697 size_t line_start;
50698
50699 /* protected by output lock */
50700@@ -2504,6 +2504,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
50701 {
50702 *ops = tty_ldisc_N_TTY;
50703 ops->owner = NULL;
50704- ops->refcount = ops->flags = 0;
50705+ atomic_set(&ops->refcount, 0);
50706+ ops->flags = 0;
50707 }
50708 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
50709diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
50710index 25c9bc7..24077b7 100644
50711--- a/drivers/tty/pty.c
50712+++ b/drivers/tty/pty.c
50713@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
50714 panic("Couldn't register Unix98 pts driver");
50715
50716 /* Now create the /dev/ptmx special device */
50717+ pax_open_kernel();
50718 tty_default_fops(&ptmx_fops);
50719- ptmx_fops.open = ptmx_open;
50720+ *(void **)&ptmx_fops.open = ptmx_open;
50721+ pax_close_kernel();
50722
50723 cdev_init(&ptmx_cdev, &ptmx_fops);
50724 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
50725diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
50726index 354564e..fe50d9a 100644
50727--- a/drivers/tty/rocket.c
50728+++ b/drivers/tty/rocket.c
50729@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50730 tty->driver_data = info;
50731 tty_port_tty_set(port, tty);
50732
50733- if (port->count++ == 0) {
50734+ if (atomic_inc_return(&port->count) == 1) {
50735 atomic_inc(&rp_num_ports_open);
50736
50737 #ifdef ROCKET_DEBUG_OPEN
50738@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50739 #endif
50740 }
50741 #ifdef ROCKET_DEBUG_OPEN
50742- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
50743+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
50744 #endif
50745
50746 /*
50747@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
50748 spin_unlock_irqrestore(&info->port.lock, flags);
50749 return;
50750 }
50751- if (info->port.count)
50752+ if (atomic_read(&info->port.count))
50753 atomic_dec(&rp_num_ports_open);
50754 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
50755 spin_unlock_irqrestore(&info->port.lock, flags);
50756diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
50757index 1274499..f541382 100644
50758--- a/drivers/tty/serial/ioc4_serial.c
50759+++ b/drivers/tty/serial/ioc4_serial.c
50760@@ -437,7 +437,7 @@ struct ioc4_soft {
50761 } is_intr_info[MAX_IOC4_INTR_ENTS];
50762
50763 /* Number of entries active in the above array */
50764- atomic_t is_num_intrs;
50765+ atomic_unchecked_t is_num_intrs;
50766 } is_intr_type[IOC4_NUM_INTR_TYPES];
50767
50768 /* is_ir_lock must be held while
50769@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
50770 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
50771 || (type == IOC4_OTHER_INTR_TYPE)));
50772
50773- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
50774+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
50775 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
50776
50777 /* Save off the lower level interrupt handler */
50778@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
50779
50780 soft = arg;
50781 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
50782- num_intrs = (int)atomic_read(
50783+ num_intrs = (int)atomic_read_unchecked(
50784 &soft->is_intr_type[intr_type].is_num_intrs);
50785
50786 this_mir = this_ir = pending_intrs(soft, intr_type);
50787diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
50788index a260cde..6b2b5ce 100644
50789--- a/drivers/tty/serial/kgdboc.c
50790+++ b/drivers/tty/serial/kgdboc.c
50791@@ -24,8 +24,9 @@
50792 #define MAX_CONFIG_LEN 40
50793
50794 static struct kgdb_io kgdboc_io_ops;
50795+static struct kgdb_io kgdboc_io_ops_console;
50796
50797-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
50798+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
50799 static int configured = -1;
50800
50801 static char config[MAX_CONFIG_LEN];
50802@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
50803 kgdboc_unregister_kbd();
50804 if (configured == 1)
50805 kgdb_unregister_io_module(&kgdboc_io_ops);
50806+ else if (configured == 2)
50807+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
50808 }
50809
50810 static int configure_kgdboc(void)
50811@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
50812 int err;
50813 char *cptr = config;
50814 struct console *cons;
50815+ int is_console = 0;
50816
50817 err = kgdboc_option_setup(config);
50818 if (err || !strlen(config) || isspace(config[0]))
50819 goto noconfig;
50820
50821 err = -ENODEV;
50822- kgdboc_io_ops.is_console = 0;
50823 kgdb_tty_driver = NULL;
50824
50825 kgdboc_use_kms = 0;
50826@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
50827 int idx;
50828 if (cons->device && cons->device(cons, &idx) == p &&
50829 idx == tty_line) {
50830- kgdboc_io_ops.is_console = 1;
50831+ is_console = 1;
50832 break;
50833 }
50834 cons = cons->next;
50835@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
50836 kgdb_tty_line = tty_line;
50837
50838 do_register:
50839- err = kgdb_register_io_module(&kgdboc_io_ops);
50840+ if (is_console) {
50841+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
50842+ configured = 2;
50843+ } else {
50844+ err = kgdb_register_io_module(&kgdboc_io_ops);
50845+ configured = 1;
50846+ }
50847 if (err)
50848 goto noconfig;
50849
50850@@ -205,8 +214,6 @@ do_register:
50851 if (err)
50852 goto nmi_con_failed;
50853
50854- configured = 1;
50855-
50856 return 0;
50857
50858 nmi_con_failed:
50859@@ -223,7 +230,7 @@ noconfig:
50860 static int __init init_kgdboc(void)
50861 {
50862 /* Already configured? */
50863- if (configured == 1)
50864+ if (configured >= 1)
50865 return 0;
50866
50867 return configure_kgdboc();
50868@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
50869 if (config[len - 1] == '\n')
50870 config[len - 1] = '\0';
50871
50872- if (configured == 1)
50873+ if (configured >= 1)
50874 cleanup_kgdboc();
50875
50876 /* Go and configure with the new params. */
50877@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
50878 .post_exception = kgdboc_post_exp_handler,
50879 };
50880
50881+static struct kgdb_io kgdboc_io_ops_console = {
50882+ .name = "kgdboc",
50883+ .read_char = kgdboc_get_char,
50884+ .write_char = kgdboc_put_char,
50885+ .pre_exception = kgdboc_pre_exp_handler,
50886+ .post_exception = kgdboc_post_exp_handler,
50887+ .is_console = 1
50888+};
50889+
50890 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
50891 /* This is only available if kgdboc is a built in for early debugging */
50892 static int __init kgdboc_early_init(char *opt)
50893diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
50894index b5d779c..3622cfe 100644
50895--- a/drivers/tty/serial/msm_serial.c
50896+++ b/drivers/tty/serial/msm_serial.c
50897@@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
50898 .cons = MSM_CONSOLE,
50899 };
50900
50901-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
50902+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
50903
50904 static const struct of_device_id msm_uartdm_table[] = {
50905 { .compatible = "qcom,msm-uartdm" },
50906@@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
50907 int irq;
50908
50909 if (pdev->id == -1)
50910- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
50911+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
50912
50913 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
50914 return -ENXIO;
50915diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
50916index c1af04d..0815c8a 100644
50917--- a/drivers/tty/serial/samsung.c
50918+++ b/drivers/tty/serial/samsung.c
50919@@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
50920 }
50921 }
50922
50923+static int s3c64xx_serial_startup(struct uart_port *port);
50924 static int s3c24xx_serial_startup(struct uart_port *port)
50925 {
50926 struct s3c24xx_uart_port *ourport = to_ourport(port);
50927 int ret;
50928
50929+ /* Startup sequence is different for s3c64xx and higher SoC's */
50930+ if (s3c24xx_serial_has_interrupt_mask(port))
50931+ return s3c64xx_serial_startup(port);
50932+
50933 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
50934 port->mapbase, port->membase);
50935
50936@@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
50937 /* setup info for port */
50938 port->dev = &platdev->dev;
50939
50940- /* Startup sequence is different for s3c64xx and higher SoC's */
50941- if (s3c24xx_serial_has_interrupt_mask(port))
50942- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
50943-
50944 port->uartclk = 1;
50945
50946 if (cfg->uart_flags & UPF_CONS_FLOW) {
50947diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
50948index 0f02351..07c59c5 100644
50949--- a/drivers/tty/serial/serial_core.c
50950+++ b/drivers/tty/serial/serial_core.c
50951@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
50952 uart_flush_buffer(tty);
50953 uart_shutdown(tty, state);
50954 spin_lock_irqsave(&port->lock, flags);
50955- port->count = 0;
50956+ atomic_set(&port->count, 0);
50957 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
50958 spin_unlock_irqrestore(&port->lock, flags);
50959 tty_port_tty_set(port, NULL);
50960@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50961 goto end;
50962 }
50963
50964- port->count++;
50965+ atomic_inc(&port->count);
50966 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
50967 retval = -ENXIO;
50968 goto err_dec_count;
50969@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50970 /*
50971 * Make sure the device is in D0 state.
50972 */
50973- if (port->count == 1)
50974+ if (atomic_read(&port->count) == 1)
50975 uart_change_pm(state, UART_PM_STATE_ON);
50976
50977 /*
50978@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50979 end:
50980 return retval;
50981 err_dec_count:
50982- port->count--;
50983+ atomic_inc(&port->count);
50984 mutex_unlock(&port->mutex);
50985 goto end;
50986 }
50987diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
50988index e1ce141..6d4ed80 100644
50989--- a/drivers/tty/synclink.c
50990+++ b/drivers/tty/synclink.c
50991@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
50992
50993 if (debug_level >= DEBUG_LEVEL_INFO)
50994 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
50995- __FILE__,__LINE__, info->device_name, info->port.count);
50996+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
50997
50998 if (tty_port_close_start(&info->port, tty, filp) == 0)
50999 goto cleanup;
51000@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51001 cleanup:
51002 if (debug_level >= DEBUG_LEVEL_INFO)
51003 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
51004- tty->driver->name, info->port.count);
51005+ tty->driver->name, atomic_read(&info->port.count));
51006
51007 } /* end of mgsl_close() */
51008
51009@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
51010
51011 mgsl_flush_buffer(tty);
51012 shutdown(info);
51013-
51014- info->port.count = 0;
51015+
51016+ atomic_set(&info->port.count, 0);
51017 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51018 info->port.tty = NULL;
51019
51020@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51021
51022 if (debug_level >= DEBUG_LEVEL_INFO)
51023 printk("%s(%d):block_til_ready before block on %s count=%d\n",
51024- __FILE__,__LINE__, tty->driver->name, port->count );
51025+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51026
51027 spin_lock_irqsave(&info->irq_spinlock, flags);
51028 if (!tty_hung_up_p(filp)) {
51029 extra_count = true;
51030- port->count--;
51031+ atomic_dec(&port->count);
51032 }
51033 spin_unlock_irqrestore(&info->irq_spinlock, flags);
51034 port->blocked_open++;
51035@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51036
51037 if (debug_level >= DEBUG_LEVEL_INFO)
51038 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
51039- __FILE__,__LINE__, tty->driver->name, port->count );
51040+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51041
51042 tty_unlock(tty);
51043 schedule();
51044@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51045
51046 /* FIXME: Racy on hangup during close wait */
51047 if (extra_count)
51048- port->count++;
51049+ atomic_inc(&port->count);
51050 port->blocked_open--;
51051
51052 if (debug_level >= DEBUG_LEVEL_INFO)
51053 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
51054- __FILE__,__LINE__, tty->driver->name, port->count );
51055+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51056
51057 if (!retval)
51058 port->flags |= ASYNC_NORMAL_ACTIVE;
51059@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51060
51061 if (debug_level >= DEBUG_LEVEL_INFO)
51062 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
51063- __FILE__,__LINE__,tty->driver->name, info->port.count);
51064+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51065
51066 /* If port is closing, signal caller to try again */
51067 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51068@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51069 spin_unlock_irqrestore(&info->netlock, flags);
51070 goto cleanup;
51071 }
51072- info->port.count++;
51073+ atomic_inc(&info->port.count);
51074 spin_unlock_irqrestore(&info->netlock, flags);
51075
51076- if (info->port.count == 1) {
51077+ if (atomic_read(&info->port.count) == 1) {
51078 /* 1st open on this device, init hardware */
51079 retval = startup(info);
51080 if (retval < 0)
51081@@ -3446,8 +3446,8 @@ cleanup:
51082 if (retval) {
51083 if (tty->count == 1)
51084 info->port.tty = NULL; /* tty layer will release tty struct */
51085- if(info->port.count)
51086- info->port.count--;
51087+ if (atomic_read(&info->port.count))
51088+ atomic_dec(&info->port.count);
51089 }
51090
51091 return retval;
51092@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51093 unsigned short new_crctype;
51094
51095 /* return error if TTY interface open */
51096- if (info->port.count)
51097+ if (atomic_read(&info->port.count))
51098 return -EBUSY;
51099
51100 switch (encoding)
51101@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
51102
51103 /* arbitrate between network and tty opens */
51104 spin_lock_irqsave(&info->netlock, flags);
51105- if (info->port.count != 0 || info->netcount != 0) {
51106+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51107 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51108 spin_unlock_irqrestore(&info->netlock, flags);
51109 return -EBUSY;
51110@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51111 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51112
51113 /* return error if TTY interface open */
51114- if (info->port.count)
51115+ if (atomic_read(&info->port.count))
51116 return -EBUSY;
51117
51118 if (cmd != SIOCWANDEV)
51119diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
51120index 1abf946..1ee34fc 100644
51121--- a/drivers/tty/synclink_gt.c
51122+++ b/drivers/tty/synclink_gt.c
51123@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51124 tty->driver_data = info;
51125 info->port.tty = tty;
51126
51127- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51128+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51129
51130 /* If port is closing, signal caller to try again */
51131 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51132@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51133 mutex_unlock(&info->port.mutex);
51134 goto cleanup;
51135 }
51136- info->port.count++;
51137+ atomic_inc(&info->port.count);
51138 spin_unlock_irqrestore(&info->netlock, flags);
51139
51140- if (info->port.count == 1) {
51141+ if (atomic_read(&info->port.count) == 1) {
51142 /* 1st open on this device, init hardware */
51143 retval = startup(info);
51144 if (retval < 0) {
51145@@ -715,8 +715,8 @@ cleanup:
51146 if (retval) {
51147 if (tty->count == 1)
51148 info->port.tty = NULL; /* tty layer will release tty struct */
51149- if(info->port.count)
51150- info->port.count--;
51151+ if(atomic_read(&info->port.count))
51152+ atomic_dec(&info->port.count);
51153 }
51154
51155 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51156@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51157
51158 if (sanity_check(info, tty->name, "close"))
51159 return;
51160- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51161+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51162
51163 if (tty_port_close_start(&info->port, tty, filp) == 0)
51164 goto cleanup;
51165@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51166 tty_port_close_end(&info->port, tty);
51167 info->port.tty = NULL;
51168 cleanup:
51169- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51170+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51171 }
51172
51173 static void hangup(struct tty_struct *tty)
51174@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51175 shutdown(info);
51176
51177 spin_lock_irqsave(&info->port.lock, flags);
51178- info->port.count = 0;
51179+ atomic_set(&info->port.count, 0);
51180 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51181 info->port.tty = NULL;
51182 spin_unlock_irqrestore(&info->port.lock, flags);
51183@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51184 unsigned short new_crctype;
51185
51186 /* return error if TTY interface open */
51187- if (info->port.count)
51188+ if (atomic_read(&info->port.count))
51189 return -EBUSY;
51190
51191 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51192@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51193
51194 /* arbitrate between network and tty opens */
51195 spin_lock_irqsave(&info->netlock, flags);
51196- if (info->port.count != 0 || info->netcount != 0) {
51197+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51198 DBGINFO(("%s hdlc_open busy\n", dev->name));
51199 spin_unlock_irqrestore(&info->netlock, flags);
51200 return -EBUSY;
51201@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51202 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51203
51204 /* return error if TTY interface open */
51205- if (info->port.count)
51206+ if (atomic_read(&info->port.count))
51207 return -EBUSY;
51208
51209 if (cmd != SIOCWANDEV)
51210@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51211 if (port == NULL)
51212 continue;
51213 spin_lock(&port->lock);
51214- if ((port->port.count || port->netcount) &&
51215+ if ((atomic_read(&port->port.count) || port->netcount) &&
51216 port->pending_bh && !port->bh_running &&
51217 !port->bh_requested) {
51218 DBGISR(("%s bh queued\n", port->device_name));
51219@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51220 spin_lock_irqsave(&info->lock, flags);
51221 if (!tty_hung_up_p(filp)) {
51222 extra_count = true;
51223- port->count--;
51224+ atomic_dec(&port->count);
51225 }
51226 spin_unlock_irqrestore(&info->lock, flags);
51227 port->blocked_open++;
51228@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51229 remove_wait_queue(&port->open_wait, &wait);
51230
51231 if (extra_count)
51232- port->count++;
51233+ atomic_inc(&port->count);
51234 port->blocked_open--;
51235
51236 if (!retval)
51237diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51238index dc6e969..5dc8786 100644
51239--- a/drivers/tty/synclinkmp.c
51240+++ b/drivers/tty/synclinkmp.c
51241@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51242
51243 if (debug_level >= DEBUG_LEVEL_INFO)
51244 printk("%s(%d):%s open(), old ref count = %d\n",
51245- __FILE__,__LINE__,tty->driver->name, info->port.count);
51246+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51247
51248 /* If port is closing, signal caller to try again */
51249 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51250@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51251 spin_unlock_irqrestore(&info->netlock, flags);
51252 goto cleanup;
51253 }
51254- info->port.count++;
51255+ atomic_inc(&info->port.count);
51256 spin_unlock_irqrestore(&info->netlock, flags);
51257
51258- if (info->port.count == 1) {
51259+ if (atomic_read(&info->port.count) == 1) {
51260 /* 1st open on this device, init hardware */
51261 retval = startup(info);
51262 if (retval < 0)
51263@@ -796,8 +796,8 @@ cleanup:
51264 if (retval) {
51265 if (tty->count == 1)
51266 info->port.tty = NULL; /* tty layer will release tty struct */
51267- if(info->port.count)
51268- info->port.count--;
51269+ if(atomic_read(&info->port.count))
51270+ atomic_dec(&info->port.count);
51271 }
51272
51273 return retval;
51274@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51275
51276 if (debug_level >= DEBUG_LEVEL_INFO)
51277 printk("%s(%d):%s close() entry, count=%d\n",
51278- __FILE__,__LINE__, info->device_name, info->port.count);
51279+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51280
51281 if (tty_port_close_start(&info->port, tty, filp) == 0)
51282 goto cleanup;
51283@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51284 cleanup:
51285 if (debug_level >= DEBUG_LEVEL_INFO)
51286 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51287- tty->driver->name, info->port.count);
51288+ tty->driver->name, atomic_read(&info->port.count));
51289 }
51290
51291 /* Called by tty_hangup() when a hangup is signaled.
51292@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51293 shutdown(info);
51294
51295 spin_lock_irqsave(&info->port.lock, flags);
51296- info->port.count = 0;
51297+ atomic_set(&info->port.count, 0);
51298 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51299 info->port.tty = NULL;
51300 spin_unlock_irqrestore(&info->port.lock, flags);
51301@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51302 unsigned short new_crctype;
51303
51304 /* return error if TTY interface open */
51305- if (info->port.count)
51306+ if (atomic_read(&info->port.count))
51307 return -EBUSY;
51308
51309 switch (encoding)
51310@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51311
51312 /* arbitrate between network and tty opens */
51313 spin_lock_irqsave(&info->netlock, flags);
51314- if (info->port.count != 0 || info->netcount != 0) {
51315+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51316 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51317 spin_unlock_irqrestore(&info->netlock, flags);
51318 return -EBUSY;
51319@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51320 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51321
51322 /* return error if TTY interface open */
51323- if (info->port.count)
51324+ if (atomic_read(&info->port.count))
51325 return -EBUSY;
51326
51327 if (cmd != SIOCWANDEV)
51328@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51329 * do not request bottom half processing if the
51330 * device is not open in a normal mode.
51331 */
51332- if ( port && (port->port.count || port->netcount) &&
51333+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51334 port->pending_bh && !port->bh_running &&
51335 !port->bh_requested ) {
51336 if ( debug_level >= DEBUG_LEVEL_ISR )
51337@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51338
51339 if (debug_level >= DEBUG_LEVEL_INFO)
51340 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51341- __FILE__,__LINE__, tty->driver->name, port->count );
51342+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51343
51344 spin_lock_irqsave(&info->lock, flags);
51345 if (!tty_hung_up_p(filp)) {
51346 extra_count = true;
51347- port->count--;
51348+ atomic_dec(&port->count);
51349 }
51350 spin_unlock_irqrestore(&info->lock, flags);
51351 port->blocked_open++;
51352@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51353
51354 if (debug_level >= DEBUG_LEVEL_INFO)
51355 printk("%s(%d):%s block_til_ready() count=%d\n",
51356- __FILE__,__LINE__, tty->driver->name, port->count );
51357+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51358
51359 tty_unlock(tty);
51360 schedule();
51361@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51362 remove_wait_queue(&port->open_wait, &wait);
51363
51364 if (extra_count)
51365- port->count++;
51366+ atomic_inc(&port->count);
51367 port->blocked_open--;
51368
51369 if (debug_level >= DEBUG_LEVEL_INFO)
51370 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51371- __FILE__,__LINE__, tty->driver->name, port->count );
51372+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51373
51374 if (!retval)
51375 port->flags |= ASYNC_NORMAL_ACTIVE;
51376diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51377index ce396ec..04a37be 100644
51378--- a/drivers/tty/sysrq.c
51379+++ b/drivers/tty/sysrq.c
51380@@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51381 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51382 size_t count, loff_t *ppos)
51383 {
51384- if (count) {
51385+ if (count && capable(CAP_SYS_ADMIN)) {
51386 char c;
51387
51388 if (get_user(c, buf))
51389diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51390index c74a00a..02cf211a 100644
51391--- a/drivers/tty/tty_io.c
51392+++ b/drivers/tty/tty_io.c
51393@@ -3474,7 +3474,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51394
51395 void tty_default_fops(struct file_operations *fops)
51396 {
51397- *fops = tty_fops;
51398+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51399 }
51400
51401 /*
51402diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51403index 6458e11..6cfc218 100644
51404--- a/drivers/tty/tty_ldisc.c
51405+++ b/drivers/tty/tty_ldisc.c
51406@@ -72,7 +72,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
51407 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51408 tty_ldiscs[disc] = new_ldisc;
51409 new_ldisc->num = disc;
51410- new_ldisc->refcount = 0;
51411+ atomic_set(&new_ldisc->refcount, 0);
51412 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51413
51414 return ret;
51415@@ -100,7 +100,7 @@ int tty_unregister_ldisc(int disc)
51416 return -EINVAL;
51417
51418 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51419- if (tty_ldiscs[disc]->refcount)
51420+ if (atomic_read(&tty_ldiscs[disc]->refcount))
51421 ret = -EBUSY;
51422 else
51423 tty_ldiscs[disc] = NULL;
51424@@ -121,7 +121,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
51425 if (ldops) {
51426 ret = ERR_PTR(-EAGAIN);
51427 if (try_module_get(ldops->owner)) {
51428- ldops->refcount++;
51429+ atomic_inc(&ldops->refcount);
51430 ret = ldops;
51431 }
51432 }
51433@@ -134,7 +134,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
51434 unsigned long flags;
51435
51436 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51437- ldops->refcount--;
51438+ atomic_dec(&ldops->refcount);
51439 module_put(ldops->owner);
51440 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51441 }
51442diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
51443index c94d234..8210f2d 100644
51444--- a/drivers/tty/tty_port.c
51445+++ b/drivers/tty/tty_port.c
51446@@ -236,7 +236,7 @@ void tty_port_hangup(struct tty_port *port)
51447 unsigned long flags;
51448
51449 spin_lock_irqsave(&port->lock, flags);
51450- port->count = 0;
51451+ atomic_set(&port->count, 0);
51452 port->flags &= ~ASYNC_NORMAL_ACTIVE;
51453 tty = port->tty;
51454 if (tty)
51455@@ -394,7 +394,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51456 /* The port lock protects the port counts */
51457 spin_lock_irqsave(&port->lock, flags);
51458 if (!tty_hung_up_p(filp))
51459- port->count--;
51460+ atomic_dec(&port->count);
51461 port->blocked_open++;
51462 spin_unlock_irqrestore(&port->lock, flags);
51463
51464@@ -436,7 +436,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51465 we must not mess that up further */
51466 spin_lock_irqsave(&port->lock, flags);
51467 if (!tty_hung_up_p(filp))
51468- port->count++;
51469+ atomic_inc(&port->count);
51470 port->blocked_open--;
51471 if (retval == 0)
51472 port->flags |= ASYNC_NORMAL_ACTIVE;
51473@@ -470,19 +470,19 @@ int tty_port_close_start(struct tty_port *port,
51474 return 0;
51475 }
51476
51477- if (tty->count == 1 && port->count != 1) {
51478+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
51479 printk(KERN_WARNING
51480 "tty_port_close_start: tty->count = 1 port count = %d.\n",
51481- port->count);
51482- port->count = 1;
51483+ atomic_read(&port->count));
51484+ atomic_set(&port->count, 1);
51485 }
51486- if (--port->count < 0) {
51487+ if (atomic_dec_return(&port->count) < 0) {
51488 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
51489- port->count);
51490- port->count = 0;
51491+ atomic_read(&port->count));
51492+ atomic_set(&port->count, 0);
51493 }
51494
51495- if (port->count) {
51496+ if (atomic_read(&port->count)) {
51497 spin_unlock_irqrestore(&port->lock, flags);
51498 return 0;
51499 }
51500@@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
51501 {
51502 spin_lock_irq(&port->lock);
51503 if (!tty_hung_up_p(filp))
51504- ++port->count;
51505+ atomic_inc(&port->count);
51506 spin_unlock_irq(&port->lock);
51507 tty_port_tty_set(port, tty);
51508
51509diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
51510index d0e3a44..5f8b754 100644
51511--- a/drivers/tty/vt/keyboard.c
51512+++ b/drivers/tty/vt/keyboard.c
51513@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
51514 kbd->kbdmode == VC_OFF) &&
51515 value != KVAL(K_SAK))
51516 return; /* SAK is allowed even in raw mode */
51517+
51518+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51519+ {
51520+ void *func = fn_handler[value];
51521+ if (func == fn_show_state || func == fn_show_ptregs ||
51522+ func == fn_show_mem)
51523+ return;
51524+ }
51525+#endif
51526+
51527 fn_handler[value](vc);
51528 }
51529
51530@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51531 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
51532 return -EFAULT;
51533
51534- if (!capable(CAP_SYS_TTY_CONFIG))
51535- perm = 0;
51536-
51537 switch (cmd) {
51538 case KDGKBENT:
51539 /* Ensure another thread doesn't free it under us */
51540@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51541 spin_unlock_irqrestore(&kbd_event_lock, flags);
51542 return put_user(val, &user_kbe->kb_value);
51543 case KDSKBENT:
51544+ if (!capable(CAP_SYS_TTY_CONFIG))
51545+ perm = 0;
51546+
51547 if (!perm)
51548 return -EPERM;
51549 if (!i && v == K_NOSUCHMAP) {
51550@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51551 int i, j, k;
51552 int ret;
51553
51554- if (!capable(CAP_SYS_TTY_CONFIG))
51555- perm = 0;
51556-
51557 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
51558 if (!kbs) {
51559 ret = -ENOMEM;
51560@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51561 kfree(kbs);
51562 return ((p && *p) ? -EOVERFLOW : 0);
51563 case KDSKBSENT:
51564+ if (!capable(CAP_SYS_TTY_CONFIG))
51565+ perm = 0;
51566+
51567 if (!perm) {
51568 ret = -EPERM;
51569 goto reterr;
51570diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
51571index a673e5b..36e5d32 100644
51572--- a/drivers/uio/uio.c
51573+++ b/drivers/uio/uio.c
51574@@ -25,6 +25,7 @@
51575 #include <linux/kobject.h>
51576 #include <linux/cdev.h>
51577 #include <linux/uio_driver.h>
51578+#include <asm/local.h>
51579
51580 #define UIO_MAX_DEVICES (1U << MINORBITS)
51581
51582@@ -32,7 +33,7 @@ struct uio_device {
51583 struct module *owner;
51584 struct device *dev;
51585 int minor;
51586- atomic_t event;
51587+ atomic_unchecked_t event;
51588 struct fasync_struct *async_queue;
51589 wait_queue_head_t wait;
51590 struct uio_info *info;
51591@@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
51592 struct device_attribute *attr, char *buf)
51593 {
51594 struct uio_device *idev = dev_get_drvdata(dev);
51595- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
51596+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
51597 }
51598 static DEVICE_ATTR_RO(event);
51599
51600@@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
51601 {
51602 struct uio_device *idev = info->uio_dev;
51603
51604- atomic_inc(&idev->event);
51605+ atomic_inc_unchecked(&idev->event);
51606 wake_up_interruptible(&idev->wait);
51607 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
51608 }
51609@@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
51610 }
51611
51612 listener->dev = idev;
51613- listener->event_count = atomic_read(&idev->event);
51614+ listener->event_count = atomic_read_unchecked(&idev->event);
51615 filep->private_data = listener;
51616
51617 if (idev->info->open) {
51618@@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
51619 return -EIO;
51620
51621 poll_wait(filep, &idev->wait, wait);
51622- if (listener->event_count != atomic_read(&idev->event))
51623+ if (listener->event_count != atomic_read_unchecked(&idev->event))
51624 return POLLIN | POLLRDNORM;
51625 return 0;
51626 }
51627@@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
51628 do {
51629 set_current_state(TASK_INTERRUPTIBLE);
51630
51631- event_count = atomic_read(&idev->event);
51632+ event_count = atomic_read_unchecked(&idev->event);
51633 if (event_count != listener->event_count) {
51634 if (copy_to_user(buf, &event_count, count))
51635 retval = -EFAULT;
51636@@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
51637 static int uio_find_mem_index(struct vm_area_struct *vma)
51638 {
51639 struct uio_device *idev = vma->vm_private_data;
51640+ unsigned long size;
51641
51642 if (vma->vm_pgoff < MAX_UIO_MAPS) {
51643- if (idev->info->mem[vma->vm_pgoff].size == 0)
51644+ size = idev->info->mem[vma->vm_pgoff].size;
51645+ if (size == 0)
51646+ return -1;
51647+ if (vma->vm_end - vma->vm_start > size)
51648 return -1;
51649 return (int)vma->vm_pgoff;
51650 }
51651@@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
51652 idev->owner = owner;
51653 idev->info = info;
51654 init_waitqueue_head(&idev->wait);
51655- atomic_set(&idev->event, 0);
51656+ atomic_set_unchecked(&idev->event, 0);
51657
51658 ret = uio_get_minor(idev);
51659 if (ret)
51660diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
51661index 8a7eb77..c00402f 100644
51662--- a/drivers/usb/atm/cxacru.c
51663+++ b/drivers/usb/atm/cxacru.c
51664@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
51665 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
51666 if (ret < 2)
51667 return -EINVAL;
51668- if (index < 0 || index > 0x7f)
51669+ if (index > 0x7f)
51670 return -EINVAL;
51671 pos += tmp;
51672
51673diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
51674index 25a7bfc..57f3cf5 100644
51675--- a/drivers/usb/atm/usbatm.c
51676+++ b/drivers/usb/atm/usbatm.c
51677@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51678 if (printk_ratelimit())
51679 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
51680 __func__, vpi, vci);
51681- atomic_inc(&vcc->stats->rx_err);
51682+ atomic_inc_unchecked(&vcc->stats->rx_err);
51683 return;
51684 }
51685
51686@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51687 if (length > ATM_MAX_AAL5_PDU) {
51688 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
51689 __func__, length, vcc);
51690- atomic_inc(&vcc->stats->rx_err);
51691+ atomic_inc_unchecked(&vcc->stats->rx_err);
51692 goto out;
51693 }
51694
51695@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51696 if (sarb->len < pdu_length) {
51697 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
51698 __func__, pdu_length, sarb->len, vcc);
51699- atomic_inc(&vcc->stats->rx_err);
51700+ atomic_inc_unchecked(&vcc->stats->rx_err);
51701 goto out;
51702 }
51703
51704 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
51705 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
51706 __func__, vcc);
51707- atomic_inc(&vcc->stats->rx_err);
51708+ atomic_inc_unchecked(&vcc->stats->rx_err);
51709 goto out;
51710 }
51711
51712@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51713 if (printk_ratelimit())
51714 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
51715 __func__, length);
51716- atomic_inc(&vcc->stats->rx_drop);
51717+ atomic_inc_unchecked(&vcc->stats->rx_drop);
51718 goto out;
51719 }
51720
51721@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51722
51723 vcc->push(vcc, skb);
51724
51725- atomic_inc(&vcc->stats->rx);
51726+ atomic_inc_unchecked(&vcc->stats->rx);
51727 out:
51728 skb_trim(sarb, 0);
51729 }
51730@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
51731 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
51732
51733 usbatm_pop(vcc, skb);
51734- atomic_inc(&vcc->stats->tx);
51735+ atomic_inc_unchecked(&vcc->stats->tx);
51736
51737 skb = skb_dequeue(&instance->sndqueue);
51738 }
51739@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
51740 if (!left--)
51741 return sprintf(page,
51742 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
51743- atomic_read(&atm_dev->stats.aal5.tx),
51744- atomic_read(&atm_dev->stats.aal5.tx_err),
51745- atomic_read(&atm_dev->stats.aal5.rx),
51746- atomic_read(&atm_dev->stats.aal5.rx_err),
51747- atomic_read(&atm_dev->stats.aal5.rx_drop));
51748+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
51749+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
51750+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
51751+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
51752+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
51753
51754 if (!left--) {
51755 if (instance->disconnected)
51756diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
51757index 2a3bbdf..91d72cf 100644
51758--- a/drivers/usb/core/devices.c
51759+++ b/drivers/usb/core/devices.c
51760@@ -126,7 +126,7 @@ static const char format_endpt[] =
51761 * time it gets called.
51762 */
51763 static struct device_connect_event {
51764- atomic_t count;
51765+ atomic_unchecked_t count;
51766 wait_queue_head_t wait;
51767 } device_event = {
51768 .count = ATOMIC_INIT(1),
51769@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
51770
51771 void usbfs_conn_disc_event(void)
51772 {
51773- atomic_add(2, &device_event.count);
51774+ atomic_add_unchecked(2, &device_event.count);
51775 wake_up(&device_event.wait);
51776 }
51777
51778@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
51779
51780 poll_wait(file, &device_event.wait, wait);
51781
51782- event_count = atomic_read(&device_event.count);
51783+ event_count = atomic_read_unchecked(&device_event.count);
51784 if (file->f_version != event_count) {
51785 file->f_version = event_count;
51786 return POLLIN | POLLRDNORM;
51787diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
51788index 967152a..16fa2e5 100644
51789--- a/drivers/usb/core/devio.c
51790+++ b/drivers/usb/core/devio.c
51791@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51792 struct dev_state *ps = file->private_data;
51793 struct usb_device *dev = ps->dev;
51794 ssize_t ret = 0;
51795- unsigned len;
51796+ size_t len;
51797 loff_t pos;
51798 int i;
51799
51800@@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51801 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
51802 struct usb_config_descriptor *config =
51803 (struct usb_config_descriptor *)dev->rawdescriptors[i];
51804- unsigned int length = le16_to_cpu(config->wTotalLength);
51805+ size_t length = le16_to_cpu(config->wTotalLength);
51806
51807 if (*ppos < pos + length) {
51808
51809 /* The descriptor may claim to be longer than it
51810 * really is. Here is the actual allocated length. */
51811- unsigned alloclen =
51812+ size_t alloclen =
51813 le16_to_cpu(dev->config[i].desc.wTotalLength);
51814
51815- len = length - (*ppos - pos);
51816+ len = length + pos - *ppos;
51817 if (len > nbytes)
51818 len = nbytes;
51819
51820 /* Simply don't write (skip over) unallocated parts */
51821 if (alloclen > (*ppos - pos)) {
51822- alloclen -= (*ppos - pos);
51823+ alloclen = alloclen + pos - *ppos;
51824 if (copy_to_user(buf,
51825 dev->rawdescriptors[i] + (*ppos - pos),
51826 min(len, alloclen))) {
51827diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
51828index d39106c..bfe13a4 100644
51829--- a/drivers/usb/core/hcd.c
51830+++ b/drivers/usb/core/hcd.c
51831@@ -1549,7 +1549,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51832 */
51833 usb_get_urb(urb);
51834 atomic_inc(&urb->use_count);
51835- atomic_inc(&urb->dev->urbnum);
51836+ atomic_inc_unchecked(&urb->dev->urbnum);
51837 usbmon_urb_submit(&hcd->self, urb);
51838
51839 /* NOTE requirements on root-hub callers (usbfs and the hub
51840@@ -1576,7 +1576,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51841 urb->hcpriv = NULL;
51842 INIT_LIST_HEAD(&urb->urb_list);
51843 atomic_dec(&urb->use_count);
51844- atomic_dec(&urb->dev->urbnum);
51845+ atomic_dec_unchecked(&urb->dev->urbnum);
51846 if (atomic_read(&urb->reject))
51847 wake_up(&usb_kill_urb_queue);
51848 usb_put_urb(urb);
51849diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
51850index ebcd3bf..be93a64 100644
51851--- a/drivers/usb/core/hub.c
51852+++ b/drivers/usb/core/hub.c
51853@@ -27,6 +27,7 @@
51854 #include <linux/freezer.h>
51855 #include <linux/random.h>
51856 #include <linux/pm_qos.h>
51857+#include <linux/grsecurity.h>
51858
51859 #include <asm/uaccess.h>
51860 #include <asm/byteorder.h>
51861@@ -4437,6 +4438,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
51862 goto done;
51863 return;
51864 }
51865+
51866+ if (gr_handle_new_usb())
51867+ goto done;
51868+
51869 if (hub_is_superspeed(hub->hdev))
51870 unit_load = 150;
51871 else
51872diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
51873index bb31597..6c5ef8b 100644
51874--- a/drivers/usb/core/message.c
51875+++ b/drivers/usb/core/message.c
51876@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
51877 * Return: If successful, the number of bytes transferred. Otherwise, a negative
51878 * error number.
51879 */
51880-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51881+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51882 __u8 requesttype, __u16 value, __u16 index, void *data,
51883 __u16 size, int timeout)
51884 {
51885@@ -181,7 +181,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
51886 * If successful, 0. Otherwise a negative error number. The number of actual
51887 * bytes transferred will be stored in the @actual_length paramater.
51888 */
51889-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51890+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51891 void *data, int len, int *actual_length, int timeout)
51892 {
51893 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
51894@@ -221,7 +221,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
51895 * bytes transferred will be stored in the @actual_length paramater.
51896 *
51897 */
51898-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51899+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51900 void *data, int len, int *actual_length, int timeout)
51901 {
51902 struct urb *urb;
51903diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
51904index 52a97ad..e73330f 100644
51905--- a/drivers/usb/core/sysfs.c
51906+++ b/drivers/usb/core/sysfs.c
51907@@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
51908 struct usb_device *udev;
51909
51910 udev = to_usb_device(dev);
51911- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
51912+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
51913 }
51914 static DEVICE_ATTR_RO(urbnum);
51915
51916diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
51917index 4d11449..f4ccabf 100644
51918--- a/drivers/usb/core/usb.c
51919+++ b/drivers/usb/core/usb.c
51920@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
51921 set_dev_node(&dev->dev, dev_to_node(bus->controller));
51922 dev->state = USB_STATE_ATTACHED;
51923 dev->lpm_disable_count = 1;
51924- atomic_set(&dev->urbnum, 0);
51925+ atomic_set_unchecked(&dev->urbnum, 0);
51926
51927 INIT_LIST_HEAD(&dev->ep0.urb_list);
51928 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
51929diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
51930index 02e44fc..3c4fe64 100644
51931--- a/drivers/usb/dwc3/gadget.c
51932+++ b/drivers/usb/dwc3/gadget.c
51933@@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
51934 if (!usb_endpoint_xfer_isoc(desc))
51935 return 0;
51936
51937- memset(&trb_link, 0, sizeof(trb_link));
51938-
51939 /* Link TRB for ISOC. The HWO bit is never reset */
51940 trb_st_hw = &dep->trb_pool[0];
51941
51942diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
51943index 8cfc319..4868255 100644
51944--- a/drivers/usb/early/ehci-dbgp.c
51945+++ b/drivers/usb/early/ehci-dbgp.c
51946@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
51947
51948 #ifdef CONFIG_KGDB
51949 static struct kgdb_io kgdbdbgp_io_ops;
51950-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
51951+static struct kgdb_io kgdbdbgp_io_ops_console;
51952+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
51953 #else
51954 #define dbgp_kgdb_mode (0)
51955 #endif
51956@@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
51957 .write_char = kgdbdbgp_write_char,
51958 };
51959
51960+static struct kgdb_io kgdbdbgp_io_ops_console = {
51961+ .name = "kgdbdbgp",
51962+ .read_char = kgdbdbgp_read_char,
51963+ .write_char = kgdbdbgp_write_char,
51964+ .is_console = 1
51965+};
51966+
51967 static int kgdbdbgp_wait_time;
51968
51969 static int __init kgdbdbgp_parse_config(char *str)
51970@@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
51971 ptr++;
51972 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
51973 }
51974- kgdb_register_io_module(&kgdbdbgp_io_ops);
51975- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
51976+ if (early_dbgp_console.index != -1)
51977+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
51978+ else
51979+ kgdb_register_io_module(&kgdbdbgp_io_ops);
51980
51981 return 0;
51982 }
51983diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
51984index b369292..9f3ba40 100644
51985--- a/drivers/usb/gadget/u_serial.c
51986+++ b/drivers/usb/gadget/u_serial.c
51987@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
51988 spin_lock_irq(&port->port_lock);
51989
51990 /* already open? Great. */
51991- if (port->port.count) {
51992+ if (atomic_read(&port->port.count)) {
51993 status = 0;
51994- port->port.count++;
51995+ atomic_inc(&port->port.count);
51996
51997 /* currently opening/closing? wait ... */
51998 } else if (port->openclose) {
51999@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52000 tty->driver_data = port;
52001 port->port.tty = tty;
52002
52003- port->port.count = 1;
52004+ atomic_set(&port->port.count, 1);
52005 port->openclose = false;
52006
52007 /* if connected, start the I/O stream */
52008@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52009
52010 spin_lock_irq(&port->port_lock);
52011
52012- if (port->port.count != 1) {
52013- if (port->port.count == 0)
52014+ if (atomic_read(&port->port.count) != 1) {
52015+ if (atomic_read(&port->port.count) == 0)
52016 WARN_ON(1);
52017 else
52018- --port->port.count;
52019+ atomic_dec(&port->port.count);
52020 goto exit;
52021 }
52022
52023@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52024 * and sleep if necessary
52025 */
52026 port->openclose = true;
52027- port->port.count = 0;
52028+ atomic_set(&port->port.count, 0);
52029
52030 gser = port->port_usb;
52031 if (gser && gser->disconnect)
52032@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
52033 int cond;
52034
52035 spin_lock_irq(&port->port_lock);
52036- cond = (port->port.count == 0) && !port->openclose;
52037+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
52038 spin_unlock_irq(&port->port_lock);
52039 return cond;
52040 }
52041@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
52042 /* if it's already open, start I/O ... and notify the serial
52043 * protocol about open/close status (connect/disconnect).
52044 */
52045- if (port->port.count) {
52046+ if (atomic_read(&port->port.count)) {
52047 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
52048 gs_start_io(port);
52049 if (gser->connect)
52050@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
52051
52052 port->port_usb = NULL;
52053 gser->ioport = NULL;
52054- if (port->port.count > 0 || port->openclose) {
52055+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
52056 wake_up_interruptible(&port->drain_wait);
52057 if (port->port.tty)
52058 tty_hangup(port->port.tty);
52059@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
52060
52061 /* finally, free any unused/unusable I/O buffers */
52062 spin_lock_irqsave(&port->port_lock, flags);
52063- if (port->port.count == 0 && !port->openclose)
52064+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
52065 gs_buf_free(&port->port_write_buf);
52066 gs_free_requests(gser->out, &port->read_pool, NULL);
52067 gs_free_requests(gser->out, &port->read_queue, NULL);
52068diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
52069index 1bb85be..29e28d9 100644
52070--- a/drivers/usb/host/ehci-hub.c
52071+++ b/drivers/usb/host/ehci-hub.c
52072@@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
52073 urb->transfer_flags = URB_DIR_IN;
52074 usb_get_urb(urb);
52075 atomic_inc(&urb->use_count);
52076- atomic_inc(&urb->dev->urbnum);
52077+ atomic_inc_unchecked(&urb->dev->urbnum);
52078 urb->setup_dma = dma_map_single(
52079 hcd->self.controller,
52080 urb->setup_packet,
52081@@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
52082 urb->status = -EINPROGRESS;
52083 usb_get_urb(urb);
52084 atomic_inc(&urb->use_count);
52085- atomic_inc(&urb->dev->urbnum);
52086+ atomic_inc_unchecked(&urb->dev->urbnum);
52087 retval = submit_single_step_set_feature(hcd, urb, 0);
52088 if (!retval && !wait_for_completion_timeout(&done,
52089 msecs_to_jiffies(2000))) {
52090diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
52091index ba6a5d6..f88f7f3 100644
52092--- a/drivers/usb/misc/appledisplay.c
52093+++ b/drivers/usb/misc/appledisplay.c
52094@@ -83,7 +83,7 @@ struct appledisplay {
52095 spinlock_t lock;
52096 };
52097
52098-static atomic_t count_displays = ATOMIC_INIT(0);
52099+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
52100 static struct workqueue_struct *wq;
52101
52102 static void appledisplay_complete(struct urb *urb)
52103@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
52104
52105 /* Register backlight device */
52106 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
52107- atomic_inc_return(&count_displays) - 1);
52108+ atomic_inc_return_unchecked(&count_displays) - 1);
52109 memset(&props, 0, sizeof(struct backlight_properties));
52110 props.type = BACKLIGHT_RAW;
52111 props.max_brightness = 0xff;
52112diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
52113index c69bb50..215ef37 100644
52114--- a/drivers/usb/serial/console.c
52115+++ b/drivers/usb/serial/console.c
52116@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
52117
52118 info->port = port;
52119
52120- ++port->port.count;
52121+ atomic_inc(&port->port.count);
52122 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
52123 if (serial->type->set_termios) {
52124 /*
52125@@ -170,7 +170,7 @@ static int usb_console_setup(struct console *co, char *options)
52126 }
52127 /* Now that any required fake tty operations are completed restore
52128 * the tty port count */
52129- --port->port.count;
52130+ atomic_dec(&port->port.count);
52131 /* The console is special in terms of closing the device so
52132 * indicate this port is now acting as a system console. */
52133 port->port.console = 1;
52134@@ -183,7 +183,7 @@ static int usb_console_setup(struct console *co, char *options)
52135 free_tty:
52136 kfree(tty);
52137 reset_open_count:
52138- port->port.count = 0;
52139+ atomic_set(&port->port.count, 0);
52140 usb_autopm_put_interface(serial->interface);
52141 error_get_interface:
52142 usb_serial_put(serial);
52143@@ -194,7 +194,7 @@ static int usb_console_setup(struct console *co, char *options)
52144 static void usb_console_write(struct console *co,
52145 const char *buf, unsigned count)
52146 {
52147- static struct usbcons_info *info = &usbcons_info;
52148+ struct usbcons_info *info = &usbcons_info;
52149 struct usb_serial_port *port = info->port;
52150 struct usb_serial *serial;
52151 int retval = -ENODEV;
52152diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52153index 75f70f0..d467e1a 100644
52154--- a/drivers/usb/storage/usb.h
52155+++ b/drivers/usb/storage/usb.h
52156@@ -63,7 +63,7 @@ struct us_unusual_dev {
52157 __u8 useProtocol;
52158 __u8 useTransport;
52159 int (*initFunction)(struct us_data *);
52160-};
52161+} __do_const;
52162
52163
52164 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52165diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52166index e614f02..3fd60e2 100644
52167--- a/drivers/usb/wusbcore/wa-hc.h
52168+++ b/drivers/usb/wusbcore/wa-hc.h
52169@@ -225,7 +225,7 @@ struct wahc {
52170 spinlock_t xfer_list_lock;
52171 struct work_struct xfer_enqueue_work;
52172 struct work_struct xfer_error_work;
52173- atomic_t xfer_id_count;
52174+ atomic_unchecked_t xfer_id_count;
52175
52176 kernel_ulong_t quirks;
52177 };
52178@@ -287,7 +287,7 @@ static inline void wa_init(struct wahc *wa)
52179 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52180 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52181 wa->dto_in_use = 0;
52182- atomic_set(&wa->xfer_id_count, 1);
52183+ atomic_set_unchecked(&wa->xfer_id_count, 1);
52184 }
52185
52186 /**
52187diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52188index ed5abe8..7036400 100644
52189--- a/drivers/usb/wusbcore/wa-xfer.c
52190+++ b/drivers/usb/wusbcore/wa-xfer.c
52191@@ -312,7 +312,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52192 */
52193 static void wa_xfer_id_init(struct wa_xfer *xfer)
52194 {
52195- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52196+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52197 }
52198
52199 /* Return the xfer's ID. */
52200diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52201index 1eab4ac..e21efc9 100644
52202--- a/drivers/vfio/vfio.c
52203+++ b/drivers/vfio/vfio.c
52204@@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52205 return 0;
52206
52207 /* TODO Prevent device auto probing */
52208- WARN("Device %s added to live group %d!\n", dev_name(dev),
52209+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52210 iommu_group_id(group->iommu_group));
52211
52212 return 0;
52213diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
52214index b12176f..e5522d9 100644
52215--- a/drivers/vhost/net.c
52216+++ b/drivers/vhost/net.c
52217@@ -528,6 +528,12 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
52218 *iovcount = seg;
52219 if (unlikely(log))
52220 *log_num = nlogs;
52221+
52222+ /* Detect overrun */
52223+ if (unlikely(datalen > 0)) {
52224+ r = UIO_MAXIOV + 1;
52225+ goto err;
52226+ }
52227 return headcount;
52228 err:
52229 vhost_discard_vq_desc(vq, headcount);
52230@@ -583,6 +589,14 @@ static void handle_rx(struct vhost_net *net)
52231 /* On error, stop handling until the next kick. */
52232 if (unlikely(headcount < 0))
52233 break;
52234+ /* On overrun, truncate and discard */
52235+ if (unlikely(headcount > UIO_MAXIOV)) {
52236+ msg.msg_iovlen = 1;
52237+ err = sock->ops->recvmsg(NULL, sock, &msg,
52238+ 1, MSG_DONTWAIT | MSG_TRUNC);
52239+ pr_debug("Discarded rx packet: len %zd\n", sock_len);
52240+ continue;
52241+ }
52242 /* OK, now we need to know about added descriptors. */
52243 if (!headcount) {
52244 if (unlikely(vhost_enable_notify(&net->dev, vq))) {
52245diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52246index 5174eba..451e6bc 100644
52247--- a/drivers/vhost/vringh.c
52248+++ b/drivers/vhost/vringh.c
52249@@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52250 /* Userspace access helpers: in this case, addresses are really userspace. */
52251 static inline int getu16_user(u16 *val, const u16 *p)
52252 {
52253- return get_user(*val, (__force u16 __user *)p);
52254+ return get_user(*val, (u16 __force_user *)p);
52255 }
52256
52257 static inline int putu16_user(u16 *p, u16 val)
52258 {
52259- return put_user(val, (__force u16 __user *)p);
52260+ return put_user(val, (u16 __force_user *)p);
52261 }
52262
52263 static inline int copydesc_user(void *dst, const void *src, size_t len)
52264 {
52265- return copy_from_user(dst, (__force void __user *)src, len) ?
52266+ return copy_from_user(dst, (void __force_user *)src, len) ?
52267 -EFAULT : 0;
52268 }
52269
52270@@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52271 const struct vring_used_elem *src,
52272 unsigned int num)
52273 {
52274- return copy_to_user((__force void __user *)dst, src,
52275+ return copy_to_user((void __force_user *)dst, src,
52276 sizeof(*dst) * num) ? -EFAULT : 0;
52277 }
52278
52279 static inline int xfer_from_user(void *src, void *dst, size_t len)
52280 {
52281- return copy_from_user(dst, (__force void __user *)src, len) ?
52282+ return copy_from_user(dst, (void __force_user *)src, len) ?
52283 -EFAULT : 0;
52284 }
52285
52286 static inline int xfer_to_user(void *dst, void *src, size_t len)
52287 {
52288- return copy_to_user((__force void __user *)dst, src, len) ?
52289+ return copy_to_user((void __force_user *)dst, src, len) ?
52290 -EFAULT : 0;
52291 }
52292
52293@@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52294 vrh->last_used_idx = 0;
52295 vrh->vring.num = num;
52296 /* vring expects kernel addresses, but only used via accessors. */
52297- vrh->vring.desc = (__force struct vring_desc *)desc;
52298- vrh->vring.avail = (__force struct vring_avail *)avail;
52299- vrh->vring.used = (__force struct vring_used *)used;
52300+ vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52301+ vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52302+ vrh->vring.used = (__force_kernel struct vring_used *)used;
52303 return 0;
52304 }
52305 EXPORT_SYMBOL(vringh_init_user);
52306@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52307
52308 static inline int putu16_kern(u16 *p, u16 val)
52309 {
52310- ACCESS_ONCE(*p) = val;
52311+ ACCESS_ONCE_RW(*p) = val;
52312 return 0;
52313 }
52314
52315diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
52316index 1b0b233..6f34c2c 100644
52317--- a/drivers/video/arcfb.c
52318+++ b/drivers/video/arcfb.c
52319@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52320 return -ENOSPC;
52321
52322 err = 0;
52323- if ((count + p) > fbmemlength) {
52324+ if (count > (fbmemlength - p)) {
52325 count = fbmemlength - p;
52326 err = -ENOSPC;
52327 }
52328diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
52329index 12ca031..84a8a74 100644
52330--- a/drivers/video/aty/aty128fb.c
52331+++ b/drivers/video/aty/aty128fb.c
52332@@ -149,7 +149,7 @@ enum {
52333 };
52334
52335 /* Must match above enum */
52336-static char * const r128_family[] = {
52337+static const char * const r128_family[] = {
52338 "AGP",
52339 "PCI",
52340 "PRO AGP",
52341diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
52342index 28fafbf..ae91651 100644
52343--- a/drivers/video/aty/atyfb_base.c
52344+++ b/drivers/video/aty/atyfb_base.c
52345@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52346 par->accel_flags = var->accel_flags; /* hack */
52347
52348 if (var->accel_flags) {
52349- info->fbops->fb_sync = atyfb_sync;
52350+ pax_open_kernel();
52351+ *(void **)&info->fbops->fb_sync = atyfb_sync;
52352+ pax_close_kernel();
52353 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52354 } else {
52355- info->fbops->fb_sync = NULL;
52356+ pax_open_kernel();
52357+ *(void **)&info->fbops->fb_sync = NULL;
52358+ pax_close_kernel();
52359 info->flags |= FBINFO_HWACCEL_DISABLED;
52360 }
52361
52362diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
52363index 95ec042..e6affdd 100644
52364--- a/drivers/video/aty/mach64_cursor.c
52365+++ b/drivers/video/aty/mach64_cursor.c
52366@@ -7,6 +7,7 @@
52367 #include <linux/string.h>
52368
52369 #include <asm/io.h>
52370+#include <asm/pgtable.h>
52371
52372 #ifdef __sparc__
52373 #include <asm/fbio.h>
52374@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
52375 info->sprite.buf_align = 16; /* and 64 lines tall. */
52376 info->sprite.flags = FB_PIXMAP_IO;
52377
52378- info->fbops->fb_cursor = atyfb_cursor;
52379+ pax_open_kernel();
52380+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
52381+ pax_close_kernel();
52382
52383 return 0;
52384 }
52385diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52386index 7592cc2..92feb56 100644
52387--- a/drivers/video/backlight/kb3886_bl.c
52388+++ b/drivers/video/backlight/kb3886_bl.c
52389@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52390 static unsigned long kb3886bl_flags;
52391 #define KB3886BL_SUSPENDED 0x01
52392
52393-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
52394+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
52395 {
52396 .ident = "Sahara Touch-iT",
52397 .matches = {
52398diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
52399index 900aa4e..6d49418 100644
52400--- a/drivers/video/fb_defio.c
52401+++ b/drivers/video/fb_defio.c
52402@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
52403
52404 BUG_ON(!fbdefio);
52405 mutex_init(&fbdefio->lock);
52406- info->fbops->fb_mmap = fb_deferred_io_mmap;
52407+ pax_open_kernel();
52408+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
52409+ pax_close_kernel();
52410 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
52411 INIT_LIST_HEAD(&fbdefio->pagelist);
52412 if (fbdefio->delay == 0) /* set a default of 1 s */
52413@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
52414 page->mapping = NULL;
52415 }
52416
52417- info->fbops->fb_mmap = NULL;
52418+ *(void **)&info->fbops->fb_mmap = NULL;
52419 mutex_destroy(&fbdefio->lock);
52420 }
52421 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
52422diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
52423index 010d191..7b8235a 100644
52424--- a/drivers/video/fbmem.c
52425+++ b/drivers/video/fbmem.c
52426@@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52427 image->dx += image->width + 8;
52428 }
52429 } else if (rotate == FB_ROTATE_UD) {
52430- for (x = 0; x < num && image->dx >= 0; x++) {
52431+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
52432 info->fbops->fb_imageblit(info, image);
52433 image->dx -= image->width + 8;
52434 }
52435@@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52436 image->dy += image->height + 8;
52437 }
52438 } else if (rotate == FB_ROTATE_CCW) {
52439- for (x = 0; x < num && image->dy >= 0; x++) {
52440+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
52441 info->fbops->fb_imageblit(info, image);
52442 image->dy -= image->height + 8;
52443 }
52444@@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
52445 return -EFAULT;
52446 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
52447 return -EINVAL;
52448- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
52449+ if (con2fb.framebuffer >= FB_MAX)
52450 return -EINVAL;
52451 if (!registered_fb[con2fb.framebuffer])
52452 request_module("fb%d", con2fb.framebuffer);
52453@@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
52454 __u32 data;
52455 int err;
52456
52457- err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
52458+ err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
52459
52460 data = (__u32) (unsigned long) fix->smem_start;
52461 err |= put_user(data, &fix32->smem_start);
52462diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
52463index 130708f..cdac1a9 100644
52464--- a/drivers/video/hyperv_fb.c
52465+++ b/drivers/video/hyperv_fb.c
52466@@ -233,7 +233,7 @@ static uint screen_fb_size;
52467 static inline int synthvid_send(struct hv_device *hdev,
52468 struct synthvid_msg *msg)
52469 {
52470- static atomic64_t request_id = ATOMIC64_INIT(0);
52471+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
52472 int ret;
52473
52474 msg->pipe_hdr.type = PIPE_MSG_DATA;
52475@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
52476
52477 ret = vmbus_sendpacket(hdev->channel, msg,
52478 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
52479- atomic64_inc_return(&request_id),
52480+ atomic64_inc_return_unchecked(&request_id),
52481 VM_PKT_DATA_INBAND, 0);
52482
52483 if (ret)
52484diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
52485index 7672d2e..b56437f 100644
52486--- a/drivers/video/i810/i810_accel.c
52487+++ b/drivers/video/i810/i810_accel.c
52488@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
52489 }
52490 }
52491 printk("ringbuffer lockup!!!\n");
52492+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
52493 i810_report_error(mmio);
52494 par->dev_flags |= LOCKUP;
52495 info->pixmap.scan_align = 1;
52496diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
52497index 3c14e43..2630570 100644
52498--- a/drivers/video/logo/logo_linux_clut224.ppm
52499+++ b/drivers/video/logo/logo_linux_clut224.ppm
52500@@ -2,1603 +2,1123 @@ P3
52501 # Standard 224-color Linux logo
52502 80 80
52503 255
52504- 0 0 0 0 0 0 0 0 0 0 0 0
52505- 0 0 0 0 0 0 0 0 0 0 0 0
52506- 0 0 0 0 0 0 0 0 0 0 0 0
52507- 0 0 0 0 0 0 0 0 0 0 0 0
52508- 0 0 0 0 0 0 0 0 0 0 0 0
52509- 0 0 0 0 0 0 0 0 0 0 0 0
52510- 0 0 0 0 0 0 0 0 0 0 0 0
52511- 0 0 0 0 0 0 0 0 0 0 0 0
52512- 0 0 0 0 0 0 0 0 0 0 0 0
52513- 6 6 6 6 6 6 10 10 10 10 10 10
52514- 10 10 10 6 6 6 6 6 6 6 6 6
52515- 0 0 0 0 0 0 0 0 0 0 0 0
52516- 0 0 0 0 0 0 0 0 0 0 0 0
52517- 0 0 0 0 0 0 0 0 0 0 0 0
52518- 0 0 0 0 0 0 0 0 0 0 0 0
52519- 0 0 0 0 0 0 0 0 0 0 0 0
52520- 0 0 0 0 0 0 0 0 0 0 0 0
52521- 0 0 0 0 0 0 0 0 0 0 0 0
52522- 0 0 0 0 0 0 0 0 0 0 0 0
52523- 0 0 0 0 0 0 0 0 0 0 0 0
52524- 0 0 0 0 0 0 0 0 0 0 0 0
52525- 0 0 0 0 0 0 0 0 0 0 0 0
52526- 0 0 0 0 0 0 0 0 0 0 0 0
52527- 0 0 0 0 0 0 0 0 0 0 0 0
52528- 0 0 0 0 0 0 0 0 0 0 0 0
52529- 0 0 0 0 0 0 0 0 0 0 0 0
52530- 0 0 0 0 0 0 0 0 0 0 0 0
52531- 0 0 0 0 0 0 0 0 0 0 0 0
52532- 0 0 0 6 6 6 10 10 10 14 14 14
52533- 22 22 22 26 26 26 30 30 30 34 34 34
52534- 30 30 30 30 30 30 26 26 26 18 18 18
52535- 14 14 14 10 10 10 6 6 6 0 0 0
52536- 0 0 0 0 0 0 0 0 0 0 0 0
52537- 0 0 0 0 0 0 0 0 0 0 0 0
52538- 0 0 0 0 0 0 0 0 0 0 0 0
52539- 0 0 0 0 0 0 0 0 0 0 0 0
52540- 0 0 0 0 0 0 0 0 0 0 0 0
52541- 0 0 0 0 0 0 0 0 0 0 0 0
52542- 0 0 0 0 0 0 0 0 0 0 0 0
52543- 0 0 0 0 0 0 0 0 0 0 0 0
52544- 0 0 0 0 0 0 0 0 0 0 0 0
52545- 0 0 0 0 0 1 0 0 1 0 0 0
52546- 0 0 0 0 0 0 0 0 0 0 0 0
52547- 0 0 0 0 0 0 0 0 0 0 0 0
52548- 0 0 0 0 0 0 0 0 0 0 0 0
52549- 0 0 0 0 0 0 0 0 0 0 0 0
52550- 0 0 0 0 0 0 0 0 0 0 0 0
52551- 0 0 0 0 0 0 0 0 0 0 0 0
52552- 6 6 6 14 14 14 26 26 26 42 42 42
52553- 54 54 54 66 66 66 78 78 78 78 78 78
52554- 78 78 78 74 74 74 66 66 66 54 54 54
52555- 42 42 42 26 26 26 18 18 18 10 10 10
52556- 6 6 6 0 0 0 0 0 0 0 0 0
52557- 0 0 0 0 0 0 0 0 0 0 0 0
52558- 0 0 0 0 0 0 0 0 0 0 0 0
52559- 0 0 0 0 0 0 0 0 0 0 0 0
52560- 0 0 0 0 0 0 0 0 0 0 0 0
52561- 0 0 0 0 0 0 0 0 0 0 0 0
52562- 0 0 0 0 0 0 0 0 0 0 0 0
52563- 0 0 0 0 0 0 0 0 0 0 0 0
52564- 0 0 0 0 0 0 0 0 0 0 0 0
52565- 0 0 1 0 0 0 0 0 0 0 0 0
52566- 0 0 0 0 0 0 0 0 0 0 0 0
52567- 0 0 0 0 0 0 0 0 0 0 0 0
52568- 0 0 0 0 0 0 0 0 0 0 0 0
52569- 0 0 0 0 0 0 0 0 0 0 0 0
52570- 0 0 0 0 0 0 0 0 0 0 0 0
52571- 0 0 0 0 0 0 0 0 0 10 10 10
52572- 22 22 22 42 42 42 66 66 66 86 86 86
52573- 66 66 66 38 38 38 38 38 38 22 22 22
52574- 26 26 26 34 34 34 54 54 54 66 66 66
52575- 86 86 86 70 70 70 46 46 46 26 26 26
52576- 14 14 14 6 6 6 0 0 0 0 0 0
52577- 0 0 0 0 0 0 0 0 0 0 0 0
52578- 0 0 0 0 0 0 0 0 0 0 0 0
52579- 0 0 0 0 0 0 0 0 0 0 0 0
52580- 0 0 0 0 0 0 0 0 0 0 0 0
52581- 0 0 0 0 0 0 0 0 0 0 0 0
52582- 0 0 0 0 0 0 0 0 0 0 0 0
52583- 0 0 0 0 0 0 0 0 0 0 0 0
52584- 0 0 0 0 0 0 0 0 0 0 0 0
52585- 0 0 1 0 0 1 0 0 1 0 0 0
52586- 0 0 0 0 0 0 0 0 0 0 0 0
52587- 0 0 0 0 0 0 0 0 0 0 0 0
52588- 0 0 0 0 0 0 0 0 0 0 0 0
52589- 0 0 0 0 0 0 0 0 0 0 0 0
52590- 0 0 0 0 0 0 0 0 0 0 0 0
52591- 0 0 0 0 0 0 10 10 10 26 26 26
52592- 50 50 50 82 82 82 58 58 58 6 6 6
52593- 2 2 6 2 2 6 2 2 6 2 2 6
52594- 2 2 6 2 2 6 2 2 6 2 2 6
52595- 6 6 6 54 54 54 86 86 86 66 66 66
52596- 38 38 38 18 18 18 6 6 6 0 0 0
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- 0 0 0 0 0 0 0 0 0 0 0 0
52607- 0 0 0 0 0 0 0 0 0 0 0 0
52608- 0 0 0 0 0 0 0 0 0 0 0 0
52609- 0 0 0 0 0 0 0 0 0 0 0 0
52610- 0 0 0 0 0 0 0 0 0 0 0 0
52611- 0 0 0 6 6 6 22 22 22 50 50 50
52612- 78 78 78 34 34 34 2 2 6 2 2 6
52613- 2 2 6 2 2 6 2 2 6 2 2 6
52614- 2 2 6 2 2 6 2 2 6 2 2 6
52615- 2 2 6 2 2 6 6 6 6 70 70 70
52616- 78 78 78 46 46 46 22 22 22 6 6 6
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 1 0 0 1 0 0 1 0 0 0
52626- 0 0 0 0 0 0 0 0 0 0 0 0
52627- 0 0 0 0 0 0 0 0 0 0 0 0
52628- 0 0 0 0 0 0 0 0 0 0 0 0
52629- 0 0 0 0 0 0 0 0 0 0 0 0
52630- 0 0 0 0 0 0 0 0 0 0 0 0
52631- 6 6 6 18 18 18 42 42 42 82 82 82
52632- 26 26 26 2 2 6 2 2 6 2 2 6
52633- 2 2 6 2 2 6 2 2 6 2 2 6
52634- 2 2 6 2 2 6 2 2 6 14 14 14
52635- 46 46 46 34 34 34 6 6 6 2 2 6
52636- 42 42 42 78 78 78 42 42 42 18 18 18
52637- 6 6 6 0 0 0 0 0 0 0 0 0
52638- 0 0 0 0 0 0 0 0 0 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- 0 0 1 0 0 0 0 0 1 0 0 0
52646- 0 0 0 0 0 0 0 0 0 0 0 0
52647- 0 0 0 0 0 0 0 0 0 0 0 0
52648- 0 0 0 0 0 0 0 0 0 0 0 0
52649- 0 0 0 0 0 0 0 0 0 0 0 0
52650- 0 0 0 0 0 0 0 0 0 0 0 0
52651- 10 10 10 30 30 30 66 66 66 58 58 58
52652- 2 2 6 2 2 6 2 2 6 2 2 6
52653- 2 2 6 2 2 6 2 2 6 2 2 6
52654- 2 2 6 2 2 6 2 2 6 26 26 26
52655- 86 86 86 101 101 101 46 46 46 10 10 10
52656- 2 2 6 58 58 58 70 70 70 34 34 34
52657- 10 10 10 0 0 0 0 0 0 0 0 0
52658- 0 0 0 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 0 0 0
52665- 0 0 1 0 0 1 0 0 1 0 0 0
52666- 0 0 0 0 0 0 0 0 0 0 0 0
52667- 0 0 0 0 0 0 0 0 0 0 0 0
52668- 0 0 0 0 0 0 0 0 0 0 0 0
52669- 0 0 0 0 0 0 0 0 0 0 0 0
52670- 0 0 0 0 0 0 0 0 0 0 0 0
52671- 14 14 14 42 42 42 86 86 86 10 10 10
52672- 2 2 6 2 2 6 2 2 6 2 2 6
52673- 2 2 6 2 2 6 2 2 6 2 2 6
52674- 2 2 6 2 2 6 2 2 6 30 30 30
52675- 94 94 94 94 94 94 58 58 58 26 26 26
52676- 2 2 6 6 6 6 78 78 78 54 54 54
52677- 22 22 22 6 6 6 0 0 0 0 0 0
52678- 0 0 0 0 0 0 0 0 0 0 0 0
52679- 0 0 0 0 0 0 0 0 0 0 0 0
52680- 0 0 0 0 0 0 0 0 0 0 0 0
52681- 0 0 0 0 0 0 0 0 0 0 0 0
52682- 0 0 0 0 0 0 0 0 0 0 0 0
52683- 0 0 0 0 0 0 0 0 0 0 0 0
52684- 0 0 0 0 0 0 0 0 0 0 0 0
52685- 0 0 0 0 0 0 0 0 0 0 0 0
52686- 0 0 0 0 0 0 0 0 0 0 0 0
52687- 0 0 0 0 0 0 0 0 0 0 0 0
52688- 0 0 0 0 0 0 0 0 0 0 0 0
52689- 0 0 0 0 0 0 0 0 0 0 0 0
52690- 0 0 0 0 0 0 0 0 0 6 6 6
52691- 22 22 22 62 62 62 62 62 62 2 2 6
52692- 2 2 6 2 2 6 2 2 6 2 2 6
52693- 2 2 6 2 2 6 2 2 6 2 2 6
52694- 2 2 6 2 2 6 2 2 6 26 26 26
52695- 54 54 54 38 38 38 18 18 18 10 10 10
52696- 2 2 6 2 2 6 34 34 34 82 82 82
52697- 38 38 38 14 14 14 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 0 0 0 0 0 0 0 0 0
52705- 0 0 0 0 0 1 0 0 1 0 0 0
52706- 0 0 0 0 0 0 0 0 0 0 0 0
52707- 0 0 0 0 0 0 0 0 0 0 0 0
52708- 0 0 0 0 0 0 0 0 0 0 0 0
52709- 0 0 0 0 0 0 0 0 0 0 0 0
52710- 0 0 0 0 0 0 0 0 0 6 6 6
52711- 30 30 30 78 78 78 30 30 30 2 2 6
52712- 2 2 6 2 2 6 2 2 6 2 2 6
52713- 2 2 6 2 2 6 2 2 6 2 2 6
52714- 2 2 6 2 2 6 2 2 6 10 10 10
52715- 10 10 10 2 2 6 2 2 6 2 2 6
52716- 2 2 6 2 2 6 2 2 6 78 78 78
52717- 50 50 50 18 18 18 6 6 6 0 0 0
52718- 0 0 0 0 0 0 0 0 0 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- 0 0 0 0 0 0 0 0 0 0 0 0
52725- 0 0 1 0 0 0 0 0 0 0 0 0
52726- 0 0 0 0 0 0 0 0 0 0 0 0
52727- 0 0 0 0 0 0 0 0 0 0 0 0
52728- 0 0 0 0 0 0 0 0 0 0 0 0
52729- 0 0 0 0 0 0 0 0 0 0 0 0
52730- 0 0 0 0 0 0 0 0 0 10 10 10
52731- 38 38 38 86 86 86 14 14 14 2 2 6
52732- 2 2 6 2 2 6 2 2 6 2 2 6
52733- 2 2 6 2 2 6 2 2 6 2 2 6
52734- 2 2 6 2 2 6 2 2 6 2 2 6
52735- 2 2 6 2 2 6 2 2 6 2 2 6
52736- 2 2 6 2 2 6 2 2 6 54 54 54
52737- 66 66 66 26 26 26 6 6 6 0 0 0
52738- 0 0 0 0 0 0 0 0 0 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- 0 0 0 0 0 0 0 0 0 0 0 0
52745- 0 0 0 0 0 1 0 0 1 0 0 0
52746- 0 0 0 0 0 0 0 0 0 0 0 0
52747- 0 0 0 0 0 0 0 0 0 0 0 0
52748- 0 0 0 0 0 0 0 0 0 0 0 0
52749- 0 0 0 0 0 0 0 0 0 0 0 0
52750- 0 0 0 0 0 0 0 0 0 14 14 14
52751- 42 42 42 82 82 82 2 2 6 2 2 6
52752- 2 2 6 6 6 6 10 10 10 2 2 6
52753- 2 2 6 2 2 6 2 2 6 2 2 6
52754- 2 2 6 2 2 6 2 2 6 6 6 6
52755- 14 14 14 10 10 10 2 2 6 2 2 6
52756- 2 2 6 2 2 6 2 2 6 18 18 18
52757- 82 82 82 34 34 34 10 10 10 0 0 0
52758- 0 0 0 0 0 0 0 0 0 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- 0 0 0 0 0 0 0 0 0 0 0 0
52765- 0 0 1 0 0 0 0 0 0 0 0 0
52766- 0 0 0 0 0 0 0 0 0 0 0 0
52767- 0 0 0 0 0 0 0 0 0 0 0 0
52768- 0 0 0 0 0 0 0 0 0 0 0 0
52769- 0 0 0 0 0 0 0 0 0 0 0 0
52770- 0 0 0 0 0 0 0 0 0 14 14 14
52771- 46 46 46 86 86 86 2 2 6 2 2 6
52772- 6 6 6 6 6 6 22 22 22 34 34 34
52773- 6 6 6 2 2 6 2 2 6 2 2 6
52774- 2 2 6 2 2 6 18 18 18 34 34 34
52775- 10 10 10 50 50 50 22 22 22 2 2 6
52776- 2 2 6 2 2 6 2 2 6 10 10 10
52777- 86 86 86 42 42 42 14 14 14 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 0 0 0
52784- 0 0 0 0 0 0 0 0 0 0 0 0
52785- 0 0 1 0 0 1 0 0 1 0 0 0
52786- 0 0 0 0 0 0 0 0 0 0 0 0
52787- 0 0 0 0 0 0 0 0 0 0 0 0
52788- 0 0 0 0 0 0 0 0 0 0 0 0
52789- 0 0 0 0 0 0 0 0 0 0 0 0
52790- 0 0 0 0 0 0 0 0 0 14 14 14
52791- 46 46 46 86 86 86 2 2 6 2 2 6
52792- 38 38 38 116 116 116 94 94 94 22 22 22
52793- 22 22 22 2 2 6 2 2 6 2 2 6
52794- 14 14 14 86 86 86 138 138 138 162 162 162
52795-154 154 154 38 38 38 26 26 26 6 6 6
52796- 2 2 6 2 2 6 2 2 6 2 2 6
52797- 86 86 86 46 46 46 14 14 14 0 0 0
52798- 0 0 0 0 0 0 0 0 0 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 0 0 0
52804- 0 0 0 0 0 0 0 0 0 0 0 0
52805- 0 0 0 0 0 0 0 0 0 0 0 0
52806- 0 0 0 0 0 0 0 0 0 0 0 0
52807- 0 0 0 0 0 0 0 0 0 0 0 0
52808- 0 0 0 0 0 0 0 0 0 0 0 0
52809- 0 0 0 0 0 0 0 0 0 0 0 0
52810- 0 0 0 0 0 0 0 0 0 14 14 14
52811- 46 46 46 86 86 86 2 2 6 14 14 14
52812-134 134 134 198 198 198 195 195 195 116 116 116
52813- 10 10 10 2 2 6 2 2 6 6 6 6
52814-101 98 89 187 187 187 210 210 210 218 218 218
52815-214 214 214 134 134 134 14 14 14 6 6 6
52816- 2 2 6 2 2 6 2 2 6 2 2 6
52817- 86 86 86 50 50 50 18 18 18 6 6 6
52818- 0 0 0 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 0 0 0
52824- 0 0 0 0 0 0 0 0 1 0 0 0
52825- 0 0 1 0 0 1 0 0 1 0 0 0
52826- 0 0 0 0 0 0 0 0 0 0 0 0
52827- 0 0 0 0 0 0 0 0 0 0 0 0
52828- 0 0 0 0 0 0 0 0 0 0 0 0
52829- 0 0 0 0 0 0 0 0 0 0 0 0
52830- 0 0 0 0 0 0 0 0 0 14 14 14
52831- 46 46 46 86 86 86 2 2 6 54 54 54
52832-218 218 218 195 195 195 226 226 226 246 246 246
52833- 58 58 58 2 2 6 2 2 6 30 30 30
52834-210 210 210 253 253 253 174 174 174 123 123 123
52835-221 221 221 234 234 234 74 74 74 2 2 6
52836- 2 2 6 2 2 6 2 2 6 2 2 6
52837- 70 70 70 58 58 58 22 22 22 6 6 6
52838- 0 0 0 0 0 0 0 0 0 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 0 0 0
52844- 0 0 0 0 0 0 0 0 0 0 0 0
52845- 0 0 0 0 0 0 0 0 0 0 0 0
52846- 0 0 0 0 0 0 0 0 0 0 0 0
52847- 0 0 0 0 0 0 0 0 0 0 0 0
52848- 0 0 0 0 0 0 0 0 0 0 0 0
52849- 0 0 0 0 0 0 0 0 0 0 0 0
52850- 0 0 0 0 0 0 0 0 0 14 14 14
52851- 46 46 46 82 82 82 2 2 6 106 106 106
52852-170 170 170 26 26 26 86 86 86 226 226 226
52853-123 123 123 10 10 10 14 14 14 46 46 46
52854-231 231 231 190 190 190 6 6 6 70 70 70
52855- 90 90 90 238 238 238 158 158 158 2 2 6
52856- 2 2 6 2 2 6 2 2 6 2 2 6
52857- 70 70 70 58 58 58 22 22 22 6 6 6
52858- 0 0 0 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 0 0 0
52864- 0 0 0 0 0 0 0 0 1 0 0 0
52865- 0 0 1 0 0 1 0 0 1 0 0 0
52866- 0 0 0 0 0 0 0 0 0 0 0 0
52867- 0 0 0 0 0 0 0 0 0 0 0 0
52868- 0 0 0 0 0 0 0 0 0 0 0 0
52869- 0 0 0 0 0 0 0 0 0 0 0 0
52870- 0 0 0 0 0 0 0 0 0 14 14 14
52871- 42 42 42 86 86 86 6 6 6 116 116 116
52872-106 106 106 6 6 6 70 70 70 149 149 149
52873-128 128 128 18 18 18 38 38 38 54 54 54
52874-221 221 221 106 106 106 2 2 6 14 14 14
52875- 46 46 46 190 190 190 198 198 198 2 2 6
52876- 2 2 6 2 2 6 2 2 6 2 2 6
52877- 74 74 74 62 62 62 22 22 22 6 6 6
52878- 0 0 0 0 0 0 0 0 0 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 0 0 0
52884- 0 0 0 0 0 0 0 0 1 0 0 0
52885- 0 0 1 0 0 0 0 0 1 0 0 0
52886- 0 0 0 0 0 0 0 0 0 0 0 0
52887- 0 0 0 0 0 0 0 0 0 0 0 0
52888- 0 0 0 0 0 0 0 0 0 0 0 0
52889- 0 0 0 0 0 0 0 0 0 0 0 0
52890- 0 0 0 0 0 0 0 0 0 14 14 14
52891- 42 42 42 94 94 94 14 14 14 101 101 101
52892-128 128 128 2 2 6 18 18 18 116 116 116
52893-118 98 46 121 92 8 121 92 8 98 78 10
52894-162 162 162 106 106 106 2 2 6 2 2 6
52895- 2 2 6 195 195 195 195 195 195 6 6 6
52896- 2 2 6 2 2 6 2 2 6 2 2 6
52897- 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0
52904- 0 0 0 0 0 0 0 0 1 0 0 1
52905- 0 0 1 0 0 0 0 0 1 0 0 0
52906- 0 0 0 0 0 0 0 0 0 0 0 0
52907- 0 0 0 0 0 0 0 0 0 0 0 0
52908- 0 0 0 0 0 0 0 0 0 0 0 0
52909- 0 0 0 0 0 0 0 0 0 0 0 0
52910- 0 0 0 0 0 0 0 0 0 10 10 10
52911- 38 38 38 90 90 90 14 14 14 58 58 58
52912-210 210 210 26 26 26 54 38 6 154 114 10
52913-226 170 11 236 186 11 225 175 15 184 144 12
52914-215 174 15 175 146 61 37 26 9 2 2 6
52915- 70 70 70 246 246 246 138 138 138 2 2 6
52916- 2 2 6 2 2 6 2 2 6 2 2 6
52917- 70 70 70 66 66 66 26 26 26 6 6 6
52918- 0 0 0 0 0 0 0 0 0 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 0 0 0
52924- 0 0 0 0 0 0 0 0 0 0 0 0
52925- 0 0 0 0 0 0 0 0 0 0 0 0
52926- 0 0 0 0 0 0 0 0 0 0 0 0
52927- 0 0 0 0 0 0 0 0 0 0 0 0
52928- 0 0 0 0 0 0 0 0 0 0 0 0
52929- 0 0 0 0 0 0 0 0 0 0 0 0
52930- 0 0 0 0 0 0 0 0 0 10 10 10
52931- 38 38 38 86 86 86 14 14 14 10 10 10
52932-195 195 195 188 164 115 192 133 9 225 175 15
52933-239 182 13 234 190 10 232 195 16 232 200 30
52934-245 207 45 241 208 19 232 195 16 184 144 12
52935-218 194 134 211 206 186 42 42 42 2 2 6
52936- 2 2 6 2 2 6 2 2 6 2 2 6
52937- 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
52944- 0 0 0 0 0 0 0 0 0 0 0 0
52945- 0 0 0 0 0 0 0 0 0 0 0 0
52946- 0 0 0 0 0 0 0 0 0 0 0 0
52947- 0 0 0 0 0 0 0 0 0 0 0 0
52948- 0 0 0 0 0 0 0 0 0 0 0 0
52949- 0 0 0 0 0 0 0 0 0 0 0 0
52950- 0 0 0 0 0 0 0 0 0 10 10 10
52951- 34 34 34 86 86 86 14 14 14 2 2 6
52952-121 87 25 192 133 9 219 162 10 239 182 13
52953-236 186 11 232 195 16 241 208 19 244 214 54
52954-246 218 60 246 218 38 246 215 20 241 208 19
52955-241 208 19 226 184 13 121 87 25 2 2 6
52956- 2 2 6 2 2 6 2 2 6 2 2 6
52957- 50 50 50 82 82 82 34 34 34 10 10 10
52958- 0 0 0 0 0 0 0 0 0 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 0 0 0
52964- 0 0 0 0 0 0 0 0 0 0 0 0
52965- 0 0 0 0 0 0 0 0 0 0 0 0
52966- 0 0 0 0 0 0 0 0 0 0 0 0
52967- 0 0 0 0 0 0 0 0 0 0 0 0
52968- 0 0 0 0 0 0 0 0 0 0 0 0
52969- 0 0 0 0 0 0 0 0 0 0 0 0
52970- 0 0 0 0 0 0 0 0 0 10 10 10
52971- 34 34 34 82 82 82 30 30 30 61 42 6
52972-180 123 7 206 145 10 230 174 11 239 182 13
52973-234 190 10 238 202 15 241 208 19 246 218 74
52974-246 218 38 246 215 20 246 215 20 246 215 20
52975-226 184 13 215 174 15 184 144 12 6 6 6
52976- 2 2 6 2 2 6 2 2 6 2 2 6
52977- 26 26 26 94 94 94 42 42 42 14 14 14
52978- 0 0 0 0 0 0 0 0 0 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 0 0 0
52984- 0 0 0 0 0 0 0 0 0 0 0 0
52985- 0 0 0 0 0 0 0 0 0 0 0 0
52986- 0 0 0 0 0 0 0 0 0 0 0 0
52987- 0 0 0 0 0 0 0 0 0 0 0 0
52988- 0 0 0 0 0 0 0 0 0 0 0 0
52989- 0 0 0 0 0 0 0 0 0 0 0 0
52990- 0 0 0 0 0 0 0 0 0 10 10 10
52991- 30 30 30 78 78 78 50 50 50 104 69 6
52992-192 133 9 216 158 10 236 178 12 236 186 11
52993-232 195 16 241 208 19 244 214 54 245 215 43
52994-246 215 20 246 215 20 241 208 19 198 155 10
52995-200 144 11 216 158 10 156 118 10 2 2 6
52996- 2 2 6 2 2 6 2 2 6 2 2 6
52997- 6 6 6 90 90 90 54 54 54 18 18 18
52998- 6 6 6 0 0 0 0 0 0 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 0 0 0
53004- 0 0 0 0 0 0 0 0 0 0 0 0
53005- 0 0 0 0 0 0 0 0 0 0 0 0
53006- 0 0 0 0 0 0 0 0 0 0 0 0
53007- 0 0 0 0 0 0 0 0 0 0 0 0
53008- 0 0 0 0 0 0 0 0 0 0 0 0
53009- 0 0 0 0 0 0 0 0 0 0 0 0
53010- 0 0 0 0 0 0 0 0 0 10 10 10
53011- 30 30 30 78 78 78 46 46 46 22 22 22
53012-137 92 6 210 162 10 239 182 13 238 190 10
53013-238 202 15 241 208 19 246 215 20 246 215 20
53014-241 208 19 203 166 17 185 133 11 210 150 10
53015-216 158 10 210 150 10 102 78 10 2 2 6
53016- 6 6 6 54 54 54 14 14 14 2 2 6
53017- 2 2 6 62 62 62 74 74 74 30 30 30
53018- 10 10 10 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 0 0 0
53024- 0 0 0 0 0 0 0 0 0 0 0 0
53025- 0 0 0 0 0 0 0 0 0 0 0 0
53026- 0 0 0 0 0 0 0 0 0 0 0 0
53027- 0 0 0 0 0 0 0 0 0 0 0 0
53028- 0 0 0 0 0 0 0 0 0 0 0 0
53029- 0 0 0 0 0 0 0 0 0 0 0 0
53030- 0 0 0 0 0 0 0 0 0 10 10 10
53031- 34 34 34 78 78 78 50 50 50 6 6 6
53032- 94 70 30 139 102 15 190 146 13 226 184 13
53033-232 200 30 232 195 16 215 174 15 190 146 13
53034-168 122 10 192 133 9 210 150 10 213 154 11
53035-202 150 34 182 157 106 101 98 89 2 2 6
53036- 2 2 6 78 78 78 116 116 116 58 58 58
53037- 2 2 6 22 22 22 90 90 90 46 46 46
53038- 18 18 18 6 6 6 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 0 0 0
53044- 0 0 0 0 0 0 0 0 0 0 0 0
53045- 0 0 0 0 0 0 0 0 0 0 0 0
53046- 0 0 0 0 0 0 0 0 0 0 0 0
53047- 0 0 0 0 0 0 0 0 0 0 0 0
53048- 0 0 0 0 0 0 0 0 0 0 0 0
53049- 0 0 0 0 0 0 0 0 0 0 0 0
53050- 0 0 0 0 0 0 0 0 0 10 10 10
53051- 38 38 38 86 86 86 50 50 50 6 6 6
53052-128 128 128 174 154 114 156 107 11 168 122 10
53053-198 155 10 184 144 12 197 138 11 200 144 11
53054-206 145 10 206 145 10 197 138 11 188 164 115
53055-195 195 195 198 198 198 174 174 174 14 14 14
53056- 2 2 6 22 22 22 116 116 116 116 116 116
53057- 22 22 22 2 2 6 74 74 74 70 70 70
53058- 30 30 30 10 10 10 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 0 0 0
53064- 0 0 0 0 0 0 0 0 0 0 0 0
53065- 0 0 0 0 0 0 0 0 0 0 0 0
53066- 0 0 0 0 0 0 0 0 0 0 0 0
53067- 0 0 0 0 0 0 0 0 0 0 0 0
53068- 0 0 0 0 0 0 0 0 0 0 0 0
53069- 0 0 0 0 0 0 0 0 0 0 0 0
53070- 0 0 0 0 0 0 6 6 6 18 18 18
53071- 50 50 50 101 101 101 26 26 26 10 10 10
53072-138 138 138 190 190 190 174 154 114 156 107 11
53073-197 138 11 200 144 11 197 138 11 192 133 9
53074-180 123 7 190 142 34 190 178 144 187 187 187
53075-202 202 202 221 221 221 214 214 214 66 66 66
53076- 2 2 6 2 2 6 50 50 50 62 62 62
53077- 6 6 6 2 2 6 10 10 10 90 90 90
53078- 50 50 50 18 18 18 6 6 6 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 0 0 0
53084- 0 0 0 0 0 0 0 0 0 0 0 0
53085- 0 0 0 0 0 0 0 0 0 0 0 0
53086- 0 0 0 0 0 0 0 0 0 0 0 0
53087- 0 0 0 0 0 0 0 0 0 0 0 0
53088- 0 0 0 0 0 0 0 0 0 0 0 0
53089- 0 0 0 0 0 0 0 0 0 0 0 0
53090- 0 0 0 0 0 0 10 10 10 34 34 34
53091- 74 74 74 74 74 74 2 2 6 6 6 6
53092-144 144 144 198 198 198 190 190 190 178 166 146
53093-154 121 60 156 107 11 156 107 11 168 124 44
53094-174 154 114 187 187 187 190 190 190 210 210 210
53095-246 246 246 253 253 253 253 253 253 182 182 182
53096- 6 6 6 2 2 6 2 2 6 2 2 6
53097- 2 2 6 2 2 6 2 2 6 62 62 62
53098- 74 74 74 34 34 34 14 14 14 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 0 0 0
53104- 0 0 0 0 0 0 0 0 0 0 0 0
53105- 0 0 0 0 0 0 0 0 0 0 0 0
53106- 0 0 0 0 0 0 0 0 0 0 0 0
53107- 0 0 0 0 0 0 0 0 0 0 0 0
53108- 0 0 0 0 0 0 0 0 0 0 0 0
53109- 0 0 0 0 0 0 0 0 0 0 0 0
53110- 0 0 0 10 10 10 22 22 22 54 54 54
53111- 94 94 94 18 18 18 2 2 6 46 46 46
53112-234 234 234 221 221 221 190 190 190 190 190 190
53113-190 190 190 187 187 187 187 187 187 190 190 190
53114-190 190 190 195 195 195 214 214 214 242 242 242
53115-253 253 253 253 253 253 253 253 253 253 253 253
53116- 82 82 82 2 2 6 2 2 6 2 2 6
53117- 2 2 6 2 2 6 2 2 6 14 14 14
53118- 86 86 86 54 54 54 22 22 22 6 6 6
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 0 0 0
53124- 0 0 0 0 0 0 0 0 0 0 0 0
53125- 0 0 0 0 0 0 0 0 0 0 0 0
53126- 0 0 0 0 0 0 0 0 0 0 0 0
53127- 0 0 0 0 0 0 0 0 0 0 0 0
53128- 0 0 0 0 0 0 0 0 0 0 0 0
53129- 0 0 0 0 0 0 0 0 0 0 0 0
53130- 6 6 6 18 18 18 46 46 46 90 90 90
53131- 46 46 46 18 18 18 6 6 6 182 182 182
53132-253 253 253 246 246 246 206 206 206 190 190 190
53133-190 190 190 190 190 190 190 190 190 190 190 190
53134-206 206 206 231 231 231 250 250 250 253 253 253
53135-253 253 253 253 253 253 253 253 253 253 253 253
53136-202 202 202 14 14 14 2 2 6 2 2 6
53137- 2 2 6 2 2 6 2 2 6 2 2 6
53138- 42 42 42 86 86 86 42 42 42 18 18 18
53139- 6 6 6 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 0 0 0
53144- 0 0 0 0 0 0 0 0 0 0 0 0
53145- 0 0 0 0 0 0 0 0 0 0 0 0
53146- 0 0 0 0 0 0 0 0 0 0 0 0
53147- 0 0 0 0 0 0 0 0 0 0 0 0
53148- 0 0 0 0 0 0 0 0 0 0 0 0
53149- 0 0 0 0 0 0 0 0 0 6 6 6
53150- 14 14 14 38 38 38 74 74 74 66 66 66
53151- 2 2 6 6 6 6 90 90 90 250 250 250
53152-253 253 253 253 253 253 238 238 238 198 198 198
53153-190 190 190 190 190 190 195 195 195 221 221 221
53154-246 246 246 253 253 253 253 253 253 253 253 253
53155-253 253 253 253 253 253 253 253 253 253 253 253
53156-253 253 253 82 82 82 2 2 6 2 2 6
53157- 2 2 6 2 2 6 2 2 6 2 2 6
53158- 2 2 6 78 78 78 70 70 70 34 34 34
53159- 14 14 14 6 6 6 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 0 0 0 0 0 0
53164- 0 0 0 0 0 0 0 0 0 0 0 0
53165- 0 0 0 0 0 0 0 0 0 0 0 0
53166- 0 0 0 0 0 0 0 0 0 0 0 0
53167- 0 0 0 0 0 0 0 0 0 0 0 0
53168- 0 0 0 0 0 0 0 0 0 0 0 0
53169- 0 0 0 0 0 0 0 0 0 14 14 14
53170- 34 34 34 66 66 66 78 78 78 6 6 6
53171- 2 2 6 18 18 18 218 218 218 253 253 253
53172-253 253 253 253 253 253 253 253 253 246 246 246
53173-226 226 226 231 231 231 246 246 246 253 253 253
53174-253 253 253 253 253 253 253 253 253 253 253 253
53175-253 253 253 253 253 253 253 253 253 253 253 253
53176-253 253 253 178 178 178 2 2 6 2 2 6
53177- 2 2 6 2 2 6 2 2 6 2 2 6
53178- 2 2 6 18 18 18 90 90 90 62 62 62
53179- 30 30 30 10 10 10 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 0 0 0 0 0 0
53184- 0 0 0 0 0 0 0 0 0 0 0 0
53185- 0 0 0 0 0 0 0 0 0 0 0 0
53186- 0 0 0 0 0 0 0 0 0 0 0 0
53187- 0 0 0 0 0 0 0 0 0 0 0 0
53188- 0 0 0 0 0 0 0 0 0 0 0 0
53189- 0 0 0 0 0 0 10 10 10 26 26 26
53190- 58 58 58 90 90 90 18 18 18 2 2 6
53191- 2 2 6 110 110 110 253 253 253 253 253 253
53192-253 253 253 253 253 253 253 253 253 253 253 253
53193-250 250 250 253 253 253 253 253 253 253 253 253
53194-253 253 253 253 253 253 253 253 253 253 253 253
53195-253 253 253 253 253 253 253 253 253 253 253 253
53196-253 253 253 231 231 231 18 18 18 2 2 6
53197- 2 2 6 2 2 6 2 2 6 2 2 6
53198- 2 2 6 2 2 6 18 18 18 94 94 94
53199- 54 54 54 26 26 26 10 10 10 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 0 0 0 0 0 0 0 0 0
53204- 0 0 0 0 0 0 0 0 0 0 0 0
53205- 0 0 0 0 0 0 0 0 0 0 0 0
53206- 0 0 0 0 0 0 0 0 0 0 0 0
53207- 0 0 0 0 0 0 0 0 0 0 0 0
53208- 0 0 0 0 0 0 0 0 0 0 0 0
53209- 0 0 0 6 6 6 22 22 22 50 50 50
53210- 90 90 90 26 26 26 2 2 6 2 2 6
53211- 14 14 14 195 195 195 250 250 250 253 253 253
53212-253 253 253 253 253 253 253 253 253 253 253 253
53213-253 253 253 253 253 253 253 253 253 253 253 253
53214-253 253 253 253 253 253 253 253 253 253 253 253
53215-253 253 253 253 253 253 253 253 253 253 253 253
53216-250 250 250 242 242 242 54 54 54 2 2 6
53217- 2 2 6 2 2 6 2 2 6 2 2 6
53218- 2 2 6 2 2 6 2 2 6 38 38 38
53219- 86 86 86 50 50 50 22 22 22 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
53224- 0 0 0 0 0 0 0 0 0 0 0 0
53225- 0 0 0 0 0 0 0 0 0 0 0 0
53226- 0 0 0 0 0 0 0 0 0 0 0 0
53227- 0 0 0 0 0 0 0 0 0 0 0 0
53228- 0 0 0 0 0 0 0 0 0 0 0 0
53229- 6 6 6 14 14 14 38 38 38 82 82 82
53230- 34 34 34 2 2 6 2 2 6 2 2 6
53231- 42 42 42 195 195 195 246 246 246 253 253 253
53232-253 253 253 253 253 253 253 253 253 250 250 250
53233-242 242 242 242 242 242 250 250 250 253 253 253
53234-253 253 253 253 253 253 253 253 253 253 253 253
53235-253 253 253 250 250 250 246 246 246 238 238 238
53236-226 226 226 231 231 231 101 101 101 6 6 6
53237- 2 2 6 2 2 6 2 2 6 2 2 6
53238- 2 2 6 2 2 6 2 2 6 2 2 6
53239- 38 38 38 82 82 82 42 42 42 14 14 14
53240- 6 6 6 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 0 0 0
53243- 0 0 0 0 0 0 0 0 0 0 0 0
53244- 0 0 0 0 0 0 0 0 0 0 0 0
53245- 0 0 0 0 0 0 0 0 0 0 0 0
53246- 0 0 0 0 0 0 0 0 0 0 0 0
53247- 0 0 0 0 0 0 0 0 0 0 0 0
53248- 0 0 0 0 0 0 0 0 0 0 0 0
53249- 10 10 10 26 26 26 62 62 62 66 66 66
53250- 2 2 6 2 2 6 2 2 6 6 6 6
53251- 70 70 70 170 170 170 206 206 206 234 234 234
53252-246 246 246 250 250 250 250 250 250 238 238 238
53253-226 226 226 231 231 231 238 238 238 250 250 250
53254-250 250 250 250 250 250 246 246 246 231 231 231
53255-214 214 214 206 206 206 202 202 202 202 202 202
53256-198 198 198 202 202 202 182 182 182 18 18 18
53257- 2 2 6 2 2 6 2 2 6 2 2 6
53258- 2 2 6 2 2 6 2 2 6 2 2 6
53259- 2 2 6 62 62 62 66 66 66 30 30 30
53260- 10 10 10 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 0 0 0
53263- 0 0 0 0 0 0 0 0 0 0 0 0
53264- 0 0 0 0 0 0 0 0 0 0 0 0
53265- 0 0 0 0 0 0 0 0 0 0 0 0
53266- 0 0 0 0 0 0 0 0 0 0 0 0
53267- 0 0 0 0 0 0 0 0 0 0 0 0
53268- 0 0 0 0 0 0 0 0 0 0 0 0
53269- 14 14 14 42 42 42 82 82 82 18 18 18
53270- 2 2 6 2 2 6 2 2 6 10 10 10
53271- 94 94 94 182 182 182 218 218 218 242 242 242
53272-250 250 250 253 253 253 253 253 253 250 250 250
53273-234 234 234 253 253 253 253 253 253 253 253 253
53274-253 253 253 253 253 253 253 253 253 246 246 246
53275-238 238 238 226 226 226 210 210 210 202 202 202
53276-195 195 195 195 195 195 210 210 210 158 158 158
53277- 6 6 6 14 14 14 50 50 50 14 14 14
53278- 2 2 6 2 2 6 2 2 6 2 2 6
53279- 2 2 6 6 6 6 86 86 86 46 46 46
53280- 18 18 18 6 6 6 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 0 0 0 0 0 0
53283- 0 0 0 0 0 0 0 0 0 0 0 0
53284- 0 0 0 0 0 0 0 0 0 0 0 0
53285- 0 0 0 0 0 0 0 0 0 0 0 0
53286- 0 0 0 0 0 0 0 0 0 0 0 0
53287- 0 0 0 0 0 0 0 0 0 0 0 0
53288- 0 0 0 0 0 0 0 0 0 6 6 6
53289- 22 22 22 54 54 54 70 70 70 2 2 6
53290- 2 2 6 10 10 10 2 2 6 22 22 22
53291-166 166 166 231 231 231 250 250 250 253 253 253
53292-253 253 253 253 253 253 253 253 253 250 250 250
53293-242 242 242 253 253 253 253 253 253 253 253 253
53294-253 253 253 253 253 253 253 253 253 253 253 253
53295-253 253 253 253 253 253 253 253 253 246 246 246
53296-231 231 231 206 206 206 198 198 198 226 226 226
53297- 94 94 94 2 2 6 6 6 6 38 38 38
53298- 30 30 30 2 2 6 2 2 6 2 2 6
53299- 2 2 6 2 2 6 62 62 62 66 66 66
53300- 26 26 26 10 10 10 0 0 0 0 0 0
53301- 0 0 0 0 0 0 0 0 0 0 0 0
53302- 0 0 0 0 0 0 0 0 0 0 0 0
53303- 0 0 0 0 0 0 0 0 0 0 0 0
53304- 0 0 0 0 0 0 0 0 0 0 0 0
53305- 0 0 0 0 0 0 0 0 0 0 0 0
53306- 0 0 0 0 0 0 0 0 0 0 0 0
53307- 0 0 0 0 0 0 0 0 0 0 0 0
53308- 0 0 0 0 0 0 0 0 0 10 10 10
53309- 30 30 30 74 74 74 50 50 50 2 2 6
53310- 26 26 26 26 26 26 2 2 6 106 106 106
53311-238 238 238 253 253 253 253 253 253 253 253 253
53312-253 253 253 253 253 253 253 253 253 253 253 253
53313-253 253 253 253 253 253 253 253 253 253 253 253
53314-253 253 253 253 253 253 253 253 253 253 253 253
53315-253 253 253 253 253 253 253 253 253 253 253 253
53316-253 253 253 246 246 246 218 218 218 202 202 202
53317-210 210 210 14 14 14 2 2 6 2 2 6
53318- 30 30 30 22 22 22 2 2 6 2 2 6
53319- 2 2 6 2 2 6 18 18 18 86 86 86
53320- 42 42 42 14 14 14 0 0 0 0 0 0
53321- 0 0 0 0 0 0 0 0 0 0 0 0
53322- 0 0 0 0 0 0 0 0 0 0 0 0
53323- 0 0 0 0 0 0 0 0 0 0 0 0
53324- 0 0 0 0 0 0 0 0 0 0 0 0
53325- 0 0 0 0 0 0 0 0 0 0 0 0
53326- 0 0 0 0 0 0 0 0 0 0 0 0
53327- 0 0 0 0 0 0 0 0 0 0 0 0
53328- 0 0 0 0 0 0 0 0 0 14 14 14
53329- 42 42 42 90 90 90 22 22 22 2 2 6
53330- 42 42 42 2 2 6 18 18 18 218 218 218
53331-253 253 253 253 253 253 253 253 253 253 253 253
53332-253 253 253 253 253 253 253 253 253 253 253 253
53333-253 253 253 253 253 253 253 253 253 253 253 253
53334-253 253 253 253 253 253 253 253 253 253 253 253
53335-253 253 253 253 253 253 253 253 253 253 253 253
53336-253 253 253 253 253 253 250 250 250 221 221 221
53337-218 218 218 101 101 101 2 2 6 14 14 14
53338- 18 18 18 38 38 38 10 10 10 2 2 6
53339- 2 2 6 2 2 6 2 2 6 78 78 78
53340- 58 58 58 22 22 22 6 6 6 0 0 0
53341- 0 0 0 0 0 0 0 0 0 0 0 0
53342- 0 0 0 0 0 0 0 0 0 0 0 0
53343- 0 0 0 0 0 0 0 0 0 0 0 0
53344- 0 0 0 0 0 0 0 0 0 0 0 0
53345- 0 0 0 0 0 0 0 0 0 0 0 0
53346- 0 0 0 0 0 0 0 0 0 0 0 0
53347- 0 0 0 0 0 0 0 0 0 0 0 0
53348- 0 0 0 0 0 0 6 6 6 18 18 18
53349- 54 54 54 82 82 82 2 2 6 26 26 26
53350- 22 22 22 2 2 6 123 123 123 253 253 253
53351-253 253 253 253 253 253 253 253 253 253 253 253
53352-253 253 253 253 253 253 253 253 253 253 253 253
53353-253 253 253 253 253 253 253 253 253 253 253 253
53354-253 253 253 253 253 253 253 253 253 253 253 253
53355-253 253 253 253 253 253 253 253 253 253 253 253
53356-253 253 253 253 253 253 253 253 253 250 250 250
53357-238 238 238 198 198 198 6 6 6 38 38 38
53358- 58 58 58 26 26 26 38 38 38 2 2 6
53359- 2 2 6 2 2 6 2 2 6 46 46 46
53360- 78 78 78 30 30 30 10 10 10 0 0 0
53361- 0 0 0 0 0 0 0 0 0 0 0 0
53362- 0 0 0 0 0 0 0 0 0 0 0 0
53363- 0 0 0 0 0 0 0 0 0 0 0 0
53364- 0 0 0 0 0 0 0 0 0 0 0 0
53365- 0 0 0 0 0 0 0 0 0 0 0 0
53366- 0 0 0 0 0 0 0 0 0 0 0 0
53367- 0 0 0 0 0 0 0 0 0 0 0 0
53368- 0 0 0 0 0 0 10 10 10 30 30 30
53369- 74 74 74 58 58 58 2 2 6 42 42 42
53370- 2 2 6 22 22 22 231 231 231 253 253 253
53371-253 253 253 253 253 253 253 253 253 253 253 253
53372-253 253 253 253 253 253 253 253 253 250 250 250
53373-253 253 253 253 253 253 253 253 253 253 253 253
53374-253 253 253 253 253 253 253 253 253 253 253 253
53375-253 253 253 253 253 253 253 253 253 253 253 253
53376-253 253 253 253 253 253 253 253 253 253 253 253
53377-253 253 253 246 246 246 46 46 46 38 38 38
53378- 42 42 42 14 14 14 38 38 38 14 14 14
53379- 2 2 6 2 2 6 2 2 6 6 6 6
53380- 86 86 86 46 46 46 14 14 14 0 0 0
53381- 0 0 0 0 0 0 0 0 0 0 0 0
53382- 0 0 0 0 0 0 0 0 0 0 0 0
53383- 0 0 0 0 0 0 0 0 0 0 0 0
53384- 0 0 0 0 0 0 0 0 0 0 0 0
53385- 0 0 0 0 0 0 0 0 0 0 0 0
53386- 0 0 0 0 0 0 0 0 0 0 0 0
53387- 0 0 0 0 0 0 0 0 0 0 0 0
53388- 0 0 0 6 6 6 14 14 14 42 42 42
53389- 90 90 90 18 18 18 18 18 18 26 26 26
53390- 2 2 6 116 116 116 253 253 253 253 253 253
53391-253 253 253 253 253 253 253 253 253 253 253 253
53392-253 253 253 253 253 253 250 250 250 238 238 238
53393-253 253 253 253 253 253 253 253 253 253 253 253
53394-253 253 253 253 253 253 253 253 253 253 253 253
53395-253 253 253 253 253 253 253 253 253 253 253 253
53396-253 253 253 253 253 253 253 253 253 253 253 253
53397-253 253 253 253 253 253 94 94 94 6 6 6
53398- 2 2 6 2 2 6 10 10 10 34 34 34
53399- 2 2 6 2 2 6 2 2 6 2 2 6
53400- 74 74 74 58 58 58 22 22 22 6 6 6
53401- 0 0 0 0 0 0 0 0 0 0 0 0
53402- 0 0 0 0 0 0 0 0 0 0 0 0
53403- 0 0 0 0 0 0 0 0 0 0 0 0
53404- 0 0 0 0 0 0 0 0 0 0 0 0
53405- 0 0 0 0 0 0 0 0 0 0 0 0
53406- 0 0 0 0 0 0 0 0 0 0 0 0
53407- 0 0 0 0 0 0 0 0 0 0 0 0
53408- 0 0 0 10 10 10 26 26 26 66 66 66
53409- 82 82 82 2 2 6 38 38 38 6 6 6
53410- 14 14 14 210 210 210 253 253 253 253 253 253
53411-253 253 253 253 253 253 253 253 253 253 253 253
53412-253 253 253 253 253 253 246 246 246 242 242 242
53413-253 253 253 253 253 253 253 253 253 253 253 253
53414-253 253 253 253 253 253 253 253 253 253 253 253
53415-253 253 253 253 253 253 253 253 253 253 253 253
53416-253 253 253 253 253 253 253 253 253 253 253 253
53417-253 253 253 253 253 253 144 144 144 2 2 6
53418- 2 2 6 2 2 6 2 2 6 46 46 46
53419- 2 2 6 2 2 6 2 2 6 2 2 6
53420- 42 42 42 74 74 74 30 30 30 10 10 10
53421- 0 0 0 0 0 0 0 0 0 0 0 0
53422- 0 0 0 0 0 0 0 0 0 0 0 0
53423- 0 0 0 0 0 0 0 0 0 0 0 0
53424- 0 0 0 0 0 0 0 0 0 0 0 0
53425- 0 0 0 0 0 0 0 0 0 0 0 0
53426- 0 0 0 0 0 0 0 0 0 0 0 0
53427- 0 0 0 0 0 0 0 0 0 0 0 0
53428- 6 6 6 14 14 14 42 42 42 90 90 90
53429- 26 26 26 6 6 6 42 42 42 2 2 6
53430- 74 74 74 250 250 250 253 253 253 253 253 253
53431-253 253 253 253 253 253 253 253 253 253 253 253
53432-253 253 253 253 253 253 242 242 242 242 242 242
53433-253 253 253 253 253 253 253 253 253 253 253 253
53434-253 253 253 253 253 253 253 253 253 253 253 253
53435-253 253 253 253 253 253 253 253 253 253 253 253
53436-253 253 253 253 253 253 253 253 253 253 253 253
53437-253 253 253 253 253 253 182 182 182 2 2 6
53438- 2 2 6 2 2 6 2 2 6 46 46 46
53439- 2 2 6 2 2 6 2 2 6 2 2 6
53440- 10 10 10 86 86 86 38 38 38 10 10 10
53441- 0 0 0 0 0 0 0 0 0 0 0 0
53442- 0 0 0 0 0 0 0 0 0 0 0 0
53443- 0 0 0 0 0 0 0 0 0 0 0 0
53444- 0 0 0 0 0 0 0 0 0 0 0 0
53445- 0 0 0 0 0 0 0 0 0 0 0 0
53446- 0 0 0 0 0 0 0 0 0 0 0 0
53447- 0 0 0 0 0 0 0 0 0 0 0 0
53448- 10 10 10 26 26 26 66 66 66 82 82 82
53449- 2 2 6 22 22 22 18 18 18 2 2 6
53450-149 149 149 253 253 253 253 253 253 253 253 253
53451-253 253 253 253 253 253 253 253 253 253 253 253
53452-253 253 253 253 253 253 234 234 234 242 242 242
53453-253 253 253 253 253 253 253 253 253 253 253 253
53454-253 253 253 253 253 253 253 253 253 253 253 253
53455-253 253 253 253 253 253 253 253 253 253 253 253
53456-253 253 253 253 253 253 253 253 253 253 253 253
53457-253 253 253 253 253 253 206 206 206 2 2 6
53458- 2 2 6 2 2 6 2 2 6 38 38 38
53459- 2 2 6 2 2 6 2 2 6 2 2 6
53460- 6 6 6 86 86 86 46 46 46 14 14 14
53461- 0 0 0 0 0 0 0 0 0 0 0 0
53462- 0 0 0 0 0 0 0 0 0 0 0 0
53463- 0 0 0 0 0 0 0 0 0 0 0 0
53464- 0 0 0 0 0 0 0 0 0 0 0 0
53465- 0 0 0 0 0 0 0 0 0 0 0 0
53466- 0 0 0 0 0 0 0 0 0 0 0 0
53467- 0 0 0 0 0 0 0 0 0 6 6 6
53468- 18 18 18 46 46 46 86 86 86 18 18 18
53469- 2 2 6 34 34 34 10 10 10 6 6 6
53470-210 210 210 253 253 253 253 253 253 253 253 253
53471-253 253 253 253 253 253 253 253 253 253 253 253
53472-253 253 253 253 253 253 234 234 234 242 242 242
53473-253 253 253 253 253 253 253 253 253 253 253 253
53474-253 253 253 253 253 253 253 253 253 253 253 253
53475-253 253 253 253 253 253 253 253 253 253 253 253
53476-253 253 253 253 253 253 253 253 253 253 253 253
53477-253 253 253 253 253 253 221 221 221 6 6 6
53478- 2 2 6 2 2 6 6 6 6 30 30 30
53479- 2 2 6 2 2 6 2 2 6 2 2 6
53480- 2 2 6 82 82 82 54 54 54 18 18 18
53481- 6 6 6 0 0 0 0 0 0 0 0 0
53482- 0 0 0 0 0 0 0 0 0 0 0 0
53483- 0 0 0 0 0 0 0 0 0 0 0 0
53484- 0 0 0 0 0 0 0 0 0 0 0 0
53485- 0 0 0 0 0 0 0 0 0 0 0 0
53486- 0 0 0 0 0 0 0 0 0 0 0 0
53487- 0 0 0 0 0 0 0 0 0 10 10 10
53488- 26 26 26 66 66 66 62 62 62 2 2 6
53489- 2 2 6 38 38 38 10 10 10 26 26 26
53490-238 238 238 253 253 253 253 253 253 253 253 253
53491-253 253 253 253 253 253 253 253 253 253 253 253
53492-253 253 253 253 253 253 231 231 231 238 238 238
53493-253 253 253 253 253 253 253 253 253 253 253 253
53494-253 253 253 253 253 253 253 253 253 253 253 253
53495-253 253 253 253 253 253 253 253 253 253 253 253
53496-253 253 253 253 253 253 253 253 253 253 253 253
53497-253 253 253 253 253 253 231 231 231 6 6 6
53498- 2 2 6 2 2 6 10 10 10 30 30 30
53499- 2 2 6 2 2 6 2 2 6 2 2 6
53500- 2 2 6 66 66 66 58 58 58 22 22 22
53501- 6 6 6 0 0 0 0 0 0 0 0 0
53502- 0 0 0 0 0 0 0 0 0 0 0 0
53503- 0 0 0 0 0 0 0 0 0 0 0 0
53504- 0 0 0 0 0 0 0 0 0 0 0 0
53505- 0 0 0 0 0 0 0 0 0 0 0 0
53506- 0 0 0 0 0 0 0 0 0 0 0 0
53507- 0 0 0 0 0 0 0 0 0 10 10 10
53508- 38 38 38 78 78 78 6 6 6 2 2 6
53509- 2 2 6 46 46 46 14 14 14 42 42 42
53510-246 246 246 253 253 253 253 253 253 253 253 253
53511-253 253 253 253 253 253 253 253 253 253 253 253
53512-253 253 253 253 253 253 231 231 231 242 242 242
53513-253 253 253 253 253 253 253 253 253 253 253 253
53514-253 253 253 253 253 253 253 253 253 253 253 253
53515-253 253 253 253 253 253 253 253 253 253 253 253
53516-253 253 253 253 253 253 253 253 253 253 253 253
53517-253 253 253 253 253 253 234 234 234 10 10 10
53518- 2 2 6 2 2 6 22 22 22 14 14 14
53519- 2 2 6 2 2 6 2 2 6 2 2 6
53520- 2 2 6 66 66 66 62 62 62 22 22 22
53521- 6 6 6 0 0 0 0 0 0 0 0 0
53522- 0 0 0 0 0 0 0 0 0 0 0 0
53523- 0 0 0 0 0 0 0 0 0 0 0 0
53524- 0 0 0 0 0 0 0 0 0 0 0 0
53525- 0 0 0 0 0 0 0 0 0 0 0 0
53526- 0 0 0 0 0 0 0 0 0 0 0 0
53527- 0 0 0 0 0 0 6 6 6 18 18 18
53528- 50 50 50 74 74 74 2 2 6 2 2 6
53529- 14 14 14 70 70 70 34 34 34 62 62 62
53530-250 250 250 253 253 253 253 253 253 253 253 253
53531-253 253 253 253 253 253 253 253 253 253 253 253
53532-253 253 253 253 253 253 231 231 231 246 246 246
53533-253 253 253 253 253 253 253 253 253 253 253 253
53534-253 253 253 253 253 253 253 253 253 253 253 253
53535-253 253 253 253 253 253 253 253 253 253 253 253
53536-253 253 253 253 253 253 253 253 253 253 253 253
53537-253 253 253 253 253 253 234 234 234 14 14 14
53538- 2 2 6 2 2 6 30 30 30 2 2 6
53539- 2 2 6 2 2 6 2 2 6 2 2 6
53540- 2 2 6 66 66 66 62 62 62 22 22 22
53541- 6 6 6 0 0 0 0 0 0 0 0 0
53542- 0 0 0 0 0 0 0 0 0 0 0 0
53543- 0 0 0 0 0 0 0 0 0 0 0 0
53544- 0 0 0 0 0 0 0 0 0 0 0 0
53545- 0 0 0 0 0 0 0 0 0 0 0 0
53546- 0 0 0 0 0 0 0 0 0 0 0 0
53547- 0 0 0 0 0 0 6 6 6 18 18 18
53548- 54 54 54 62 62 62 2 2 6 2 2 6
53549- 2 2 6 30 30 30 46 46 46 70 70 70
53550-250 250 250 253 253 253 253 253 253 253 253 253
53551-253 253 253 253 253 253 253 253 253 253 253 253
53552-253 253 253 253 253 253 231 231 231 246 246 246
53553-253 253 253 253 253 253 253 253 253 253 253 253
53554-253 253 253 253 253 253 253 253 253 253 253 253
53555-253 253 253 253 253 253 253 253 253 253 253 253
53556-253 253 253 253 253 253 253 253 253 253 253 253
53557-253 253 253 253 253 253 226 226 226 10 10 10
53558- 2 2 6 6 6 6 30 30 30 2 2 6
53559- 2 2 6 2 2 6 2 2 6 2 2 6
53560- 2 2 6 66 66 66 58 58 58 22 22 22
53561- 6 6 6 0 0 0 0 0 0 0 0 0
53562- 0 0 0 0 0 0 0 0 0 0 0 0
53563- 0 0 0 0 0 0 0 0 0 0 0 0
53564- 0 0 0 0 0 0 0 0 0 0 0 0
53565- 0 0 0 0 0 0 0 0 0 0 0 0
53566- 0 0 0 0 0 0 0 0 0 0 0 0
53567- 0 0 0 0 0 0 6 6 6 22 22 22
53568- 58 58 58 62 62 62 2 2 6 2 2 6
53569- 2 2 6 2 2 6 30 30 30 78 78 78
53570-250 250 250 253 253 253 253 253 253 253 253 253
53571-253 253 253 253 253 253 253 253 253 253 253 253
53572-253 253 253 253 253 253 231 231 231 246 246 246
53573-253 253 253 253 253 253 253 253 253 253 253 253
53574-253 253 253 253 253 253 253 253 253 253 253 253
53575-253 253 253 253 253 253 253 253 253 253 253 253
53576-253 253 253 253 253 253 253 253 253 253 253 253
53577-253 253 253 253 253 253 206 206 206 2 2 6
53578- 22 22 22 34 34 34 18 14 6 22 22 22
53579- 26 26 26 18 18 18 6 6 6 2 2 6
53580- 2 2 6 82 82 82 54 54 54 18 18 18
53581- 6 6 6 0 0 0 0 0 0 0 0 0
53582- 0 0 0 0 0 0 0 0 0 0 0 0
53583- 0 0 0 0 0 0 0 0 0 0 0 0
53584- 0 0 0 0 0 0 0 0 0 0 0 0
53585- 0 0 0 0 0 0 0 0 0 0 0 0
53586- 0 0 0 0 0 0 0 0 0 0 0 0
53587- 0 0 0 0 0 0 6 6 6 26 26 26
53588- 62 62 62 106 106 106 74 54 14 185 133 11
53589-210 162 10 121 92 8 6 6 6 62 62 62
53590-238 238 238 253 253 253 253 253 253 253 253 253
53591-253 253 253 253 253 253 253 253 253 253 253 253
53592-253 253 253 253 253 253 231 231 231 246 246 246
53593-253 253 253 253 253 253 253 253 253 253 253 253
53594-253 253 253 253 253 253 253 253 253 253 253 253
53595-253 253 253 253 253 253 253 253 253 253 253 253
53596-253 253 253 253 253 253 253 253 253 253 253 253
53597-253 253 253 253 253 253 158 158 158 18 18 18
53598- 14 14 14 2 2 6 2 2 6 2 2 6
53599- 6 6 6 18 18 18 66 66 66 38 38 38
53600- 6 6 6 94 94 94 50 50 50 18 18 18
53601- 6 6 6 0 0 0 0 0 0 0 0 0
53602- 0 0 0 0 0 0 0 0 0 0 0 0
53603- 0 0 0 0 0 0 0 0 0 0 0 0
53604- 0 0 0 0 0 0 0 0 0 0 0 0
53605- 0 0 0 0 0 0 0 0 0 0 0 0
53606- 0 0 0 0 0 0 0 0 0 6 6 6
53607- 10 10 10 10 10 10 18 18 18 38 38 38
53608- 78 78 78 142 134 106 216 158 10 242 186 14
53609-246 190 14 246 190 14 156 118 10 10 10 10
53610- 90 90 90 238 238 238 253 253 253 253 253 253
53611-253 253 253 253 253 253 253 253 253 253 253 253
53612-253 253 253 253 253 253 231 231 231 250 250 250
53613-253 253 253 253 253 253 253 253 253 253 253 253
53614-253 253 253 253 253 253 253 253 253 253 253 253
53615-253 253 253 253 253 253 253 253 253 253 253 253
53616-253 253 253 253 253 253 253 253 253 246 230 190
53617-238 204 91 238 204 91 181 142 44 37 26 9
53618- 2 2 6 2 2 6 2 2 6 2 2 6
53619- 2 2 6 2 2 6 38 38 38 46 46 46
53620- 26 26 26 106 106 106 54 54 54 18 18 18
53621- 6 6 6 0 0 0 0 0 0 0 0 0
53622- 0 0 0 0 0 0 0 0 0 0 0 0
53623- 0 0 0 0 0 0 0 0 0 0 0 0
53624- 0 0 0 0 0 0 0 0 0 0 0 0
53625- 0 0 0 0 0 0 0 0 0 0 0 0
53626- 0 0 0 6 6 6 14 14 14 22 22 22
53627- 30 30 30 38 38 38 50 50 50 70 70 70
53628-106 106 106 190 142 34 226 170 11 242 186 14
53629-246 190 14 246 190 14 246 190 14 154 114 10
53630- 6 6 6 74 74 74 226 226 226 253 253 253
53631-253 253 253 253 253 253 253 253 253 253 253 253
53632-253 253 253 253 253 253 231 231 231 250 250 250
53633-253 253 253 253 253 253 253 253 253 253 253 253
53634-253 253 253 253 253 253 253 253 253 253 253 253
53635-253 253 253 253 253 253 253 253 253 253 253 253
53636-253 253 253 253 253 253 253 253 253 228 184 62
53637-241 196 14 241 208 19 232 195 16 38 30 10
53638- 2 2 6 2 2 6 2 2 6 2 2 6
53639- 2 2 6 6 6 6 30 30 30 26 26 26
53640-203 166 17 154 142 90 66 66 66 26 26 26
53641- 6 6 6 0 0 0 0 0 0 0 0 0
53642- 0 0 0 0 0 0 0 0 0 0 0 0
53643- 0 0 0 0 0 0 0 0 0 0 0 0
53644- 0 0 0 0 0 0 0 0 0 0 0 0
53645- 0 0 0 0 0 0 0 0 0 0 0 0
53646- 6 6 6 18 18 18 38 38 38 58 58 58
53647- 78 78 78 86 86 86 101 101 101 123 123 123
53648-175 146 61 210 150 10 234 174 13 246 186 14
53649-246 190 14 246 190 14 246 190 14 238 190 10
53650-102 78 10 2 2 6 46 46 46 198 198 198
53651-253 253 253 253 253 253 253 253 253 253 253 253
53652-253 253 253 253 253 253 234 234 234 242 242 242
53653-253 253 253 253 253 253 253 253 253 253 253 253
53654-253 253 253 253 253 253 253 253 253 253 253 253
53655-253 253 253 253 253 253 253 253 253 253 253 253
53656-253 253 253 253 253 253 253 253 253 224 178 62
53657-242 186 14 241 196 14 210 166 10 22 18 6
53658- 2 2 6 2 2 6 2 2 6 2 2 6
53659- 2 2 6 2 2 6 6 6 6 121 92 8
53660-238 202 15 232 195 16 82 82 82 34 34 34
53661- 10 10 10 0 0 0 0 0 0 0 0 0
53662- 0 0 0 0 0 0 0 0 0 0 0 0
53663- 0 0 0 0 0 0 0 0 0 0 0 0
53664- 0 0 0 0 0 0 0 0 0 0 0 0
53665- 0 0 0 0 0 0 0 0 0 0 0 0
53666- 14 14 14 38 38 38 70 70 70 154 122 46
53667-190 142 34 200 144 11 197 138 11 197 138 11
53668-213 154 11 226 170 11 242 186 14 246 190 14
53669-246 190 14 246 190 14 246 190 14 246 190 14
53670-225 175 15 46 32 6 2 2 6 22 22 22
53671-158 158 158 250 250 250 253 253 253 253 253 253
53672-253 253 253 253 253 253 253 253 253 253 253 253
53673-253 253 253 253 253 253 253 253 253 253 253 253
53674-253 253 253 253 253 253 253 253 253 253 253 253
53675-253 253 253 253 253 253 253 253 253 253 253 253
53676-253 253 253 250 250 250 242 242 242 224 178 62
53677-239 182 13 236 186 11 213 154 11 46 32 6
53678- 2 2 6 2 2 6 2 2 6 2 2 6
53679- 2 2 6 2 2 6 61 42 6 225 175 15
53680-238 190 10 236 186 11 112 100 78 42 42 42
53681- 14 14 14 0 0 0 0 0 0 0 0 0
53682- 0 0 0 0 0 0 0 0 0 0 0 0
53683- 0 0 0 0 0 0 0 0 0 0 0 0
53684- 0 0 0 0 0 0 0 0 0 0 0 0
53685- 0 0 0 0 0 0 0 0 0 6 6 6
53686- 22 22 22 54 54 54 154 122 46 213 154 11
53687-226 170 11 230 174 11 226 170 11 226 170 11
53688-236 178 12 242 186 14 246 190 14 246 190 14
53689-246 190 14 246 190 14 246 190 14 246 190 14
53690-241 196 14 184 144 12 10 10 10 2 2 6
53691- 6 6 6 116 116 116 242 242 242 253 253 253
53692-253 253 253 253 253 253 253 253 253 253 253 253
53693-253 253 253 253 253 253 253 253 253 253 253 253
53694-253 253 253 253 253 253 253 253 253 253 253 253
53695-253 253 253 253 253 253 253 253 253 253 253 253
53696-253 253 253 231 231 231 198 198 198 214 170 54
53697-236 178 12 236 178 12 210 150 10 137 92 6
53698- 18 14 6 2 2 6 2 2 6 2 2 6
53699- 6 6 6 70 47 6 200 144 11 236 178 12
53700-239 182 13 239 182 13 124 112 88 58 58 58
53701- 22 22 22 6 6 6 0 0 0 0 0 0
53702- 0 0 0 0 0 0 0 0 0 0 0 0
53703- 0 0 0 0 0 0 0 0 0 0 0 0
53704- 0 0 0 0 0 0 0 0 0 0 0 0
53705- 0 0 0 0 0 0 0 0 0 10 10 10
53706- 30 30 30 70 70 70 180 133 36 226 170 11
53707-239 182 13 242 186 14 242 186 14 246 186 14
53708-246 190 14 246 190 14 246 190 14 246 190 14
53709-246 190 14 246 190 14 246 190 14 246 190 14
53710-246 190 14 232 195 16 98 70 6 2 2 6
53711- 2 2 6 2 2 6 66 66 66 221 221 221
53712-253 253 253 253 253 253 253 253 253 253 253 253
53713-253 253 253 253 253 253 253 253 253 253 253 253
53714-253 253 253 253 253 253 253 253 253 253 253 253
53715-253 253 253 253 253 253 253 253 253 253 253 253
53716-253 253 253 206 206 206 198 198 198 214 166 58
53717-230 174 11 230 174 11 216 158 10 192 133 9
53718-163 110 8 116 81 8 102 78 10 116 81 8
53719-167 114 7 197 138 11 226 170 11 239 182 13
53720-242 186 14 242 186 14 162 146 94 78 78 78
53721- 34 34 34 14 14 14 6 6 6 0 0 0
53722- 0 0 0 0 0 0 0 0 0 0 0 0
53723- 0 0 0 0 0 0 0 0 0 0 0 0
53724- 0 0 0 0 0 0 0 0 0 0 0 0
53725- 0 0 0 0 0 0 0 0 0 6 6 6
53726- 30 30 30 78 78 78 190 142 34 226 170 11
53727-239 182 13 246 190 14 246 190 14 246 190 14
53728-246 190 14 246 190 14 246 190 14 246 190 14
53729-246 190 14 246 190 14 246 190 14 246 190 14
53730-246 190 14 241 196 14 203 166 17 22 18 6
53731- 2 2 6 2 2 6 2 2 6 38 38 38
53732-218 218 218 253 253 253 253 253 253 253 253 253
53733-253 253 253 253 253 253 253 253 253 253 253 253
53734-253 253 253 253 253 253 253 253 253 253 253 253
53735-253 253 253 253 253 253 253 253 253 253 253 253
53736-250 250 250 206 206 206 198 198 198 202 162 69
53737-226 170 11 236 178 12 224 166 10 210 150 10
53738-200 144 11 197 138 11 192 133 9 197 138 11
53739-210 150 10 226 170 11 242 186 14 246 190 14
53740-246 190 14 246 186 14 225 175 15 124 112 88
53741- 62 62 62 30 30 30 14 14 14 6 6 6
53742- 0 0 0 0 0 0 0 0 0 0 0 0
53743- 0 0 0 0 0 0 0 0 0 0 0 0
53744- 0 0 0 0 0 0 0 0 0 0 0 0
53745- 0 0 0 0 0 0 0 0 0 10 10 10
53746- 30 30 30 78 78 78 174 135 50 224 166 10
53747-239 182 13 246 190 14 246 190 14 246 190 14
53748-246 190 14 246 190 14 246 190 14 246 190 14
53749-246 190 14 246 190 14 246 190 14 246 190 14
53750-246 190 14 246 190 14 241 196 14 139 102 15
53751- 2 2 6 2 2 6 2 2 6 2 2 6
53752- 78 78 78 250 250 250 253 253 253 253 253 253
53753-253 253 253 253 253 253 253 253 253 253 253 253
53754-253 253 253 253 253 253 253 253 253 253 253 253
53755-253 253 253 253 253 253 253 253 253 253 253 253
53756-250 250 250 214 214 214 198 198 198 190 150 46
53757-219 162 10 236 178 12 234 174 13 224 166 10
53758-216 158 10 213 154 11 213 154 11 216 158 10
53759-226 170 11 239 182 13 246 190 14 246 190 14
53760-246 190 14 246 190 14 242 186 14 206 162 42
53761-101 101 101 58 58 58 30 30 30 14 14 14
53762- 6 6 6 0 0 0 0 0 0 0 0 0
53763- 0 0 0 0 0 0 0 0 0 0 0 0
53764- 0 0 0 0 0 0 0 0 0 0 0 0
53765- 0 0 0 0 0 0 0 0 0 10 10 10
53766- 30 30 30 74 74 74 174 135 50 216 158 10
53767-236 178 12 246 190 14 246 190 14 246 190 14
53768-246 190 14 246 190 14 246 190 14 246 190 14
53769-246 190 14 246 190 14 246 190 14 246 190 14
53770-246 190 14 246 190 14 241 196 14 226 184 13
53771- 61 42 6 2 2 6 2 2 6 2 2 6
53772- 22 22 22 238 238 238 253 253 253 253 253 253
53773-253 253 253 253 253 253 253 253 253 253 253 253
53774-253 253 253 253 253 253 253 253 253 253 253 253
53775-253 253 253 253 253 253 253 253 253 253 253 253
53776-253 253 253 226 226 226 187 187 187 180 133 36
53777-216 158 10 236 178 12 239 182 13 236 178 12
53778-230 174 11 226 170 11 226 170 11 230 174 11
53779-236 178 12 242 186 14 246 190 14 246 190 14
53780-246 190 14 246 190 14 246 186 14 239 182 13
53781-206 162 42 106 106 106 66 66 66 34 34 34
53782- 14 14 14 6 6 6 0 0 0 0 0 0
53783- 0 0 0 0 0 0 0 0 0 0 0 0
53784- 0 0 0 0 0 0 0 0 0 0 0 0
53785- 0 0 0 0 0 0 0 0 0 6 6 6
53786- 26 26 26 70 70 70 163 133 67 213 154 11
53787-236 178 12 246 190 14 246 190 14 246 190 14
53788-246 190 14 246 190 14 246 190 14 246 190 14
53789-246 190 14 246 190 14 246 190 14 246 190 14
53790-246 190 14 246 190 14 246 190 14 241 196 14
53791-190 146 13 18 14 6 2 2 6 2 2 6
53792- 46 46 46 246 246 246 253 253 253 253 253 253
53793-253 253 253 253 253 253 253 253 253 253 253 253
53794-253 253 253 253 253 253 253 253 253 253 253 253
53795-253 253 253 253 253 253 253 253 253 253 253 253
53796-253 253 253 221 221 221 86 86 86 156 107 11
53797-216 158 10 236 178 12 242 186 14 246 186 14
53798-242 186 14 239 182 13 239 182 13 242 186 14
53799-242 186 14 246 186 14 246 190 14 246 190 14
53800-246 190 14 246 190 14 246 190 14 246 190 14
53801-242 186 14 225 175 15 142 122 72 66 66 66
53802- 30 30 30 10 10 10 0 0 0 0 0 0
53803- 0 0 0 0 0 0 0 0 0 0 0 0
53804- 0 0 0 0 0 0 0 0 0 0 0 0
53805- 0 0 0 0 0 0 0 0 0 6 6 6
53806- 26 26 26 70 70 70 163 133 67 210 150 10
53807-236 178 12 246 190 14 246 190 14 246 190 14
53808-246 190 14 246 190 14 246 190 14 246 190 14
53809-246 190 14 246 190 14 246 190 14 246 190 14
53810-246 190 14 246 190 14 246 190 14 246 190 14
53811-232 195 16 121 92 8 34 34 34 106 106 106
53812-221 221 221 253 253 253 253 253 253 253 253 253
53813-253 253 253 253 253 253 253 253 253 253 253 253
53814-253 253 253 253 253 253 253 253 253 253 253 253
53815-253 253 253 253 253 253 253 253 253 253 253 253
53816-242 242 242 82 82 82 18 14 6 163 110 8
53817-216 158 10 236 178 12 242 186 14 246 190 14
53818-246 190 14 246 190 14 246 190 14 246 190 14
53819-246 190 14 246 190 14 246 190 14 246 190 14
53820-246 190 14 246 190 14 246 190 14 246 190 14
53821-246 190 14 246 190 14 242 186 14 163 133 67
53822- 46 46 46 18 18 18 6 6 6 0 0 0
53823- 0 0 0 0 0 0 0 0 0 0 0 0
53824- 0 0 0 0 0 0 0 0 0 0 0 0
53825- 0 0 0 0 0 0 0 0 0 10 10 10
53826- 30 30 30 78 78 78 163 133 67 210 150 10
53827-236 178 12 246 186 14 246 190 14 246 190 14
53828-246 190 14 246 190 14 246 190 14 246 190 14
53829-246 190 14 246 190 14 246 190 14 246 190 14
53830-246 190 14 246 190 14 246 190 14 246 190 14
53831-241 196 14 215 174 15 190 178 144 253 253 253
53832-253 253 253 253 253 253 253 253 253 253 253 253
53833-253 253 253 253 253 253 253 253 253 253 253 253
53834-253 253 253 253 253 253 253 253 253 253 253 253
53835-253 253 253 253 253 253 253 253 253 218 218 218
53836- 58 58 58 2 2 6 22 18 6 167 114 7
53837-216 158 10 236 178 12 246 186 14 246 190 14
53838-246 190 14 246 190 14 246 190 14 246 190 14
53839-246 190 14 246 190 14 246 190 14 246 190 14
53840-246 190 14 246 190 14 246 190 14 246 190 14
53841-246 190 14 246 186 14 242 186 14 190 150 46
53842- 54 54 54 22 22 22 6 6 6 0 0 0
53843- 0 0 0 0 0 0 0 0 0 0 0 0
53844- 0 0 0 0 0 0 0 0 0 0 0 0
53845- 0 0 0 0 0 0 0 0 0 14 14 14
53846- 38 38 38 86 86 86 180 133 36 213 154 11
53847-236 178 12 246 186 14 246 190 14 246 190 14
53848-246 190 14 246 190 14 246 190 14 246 190 14
53849-246 190 14 246 190 14 246 190 14 246 190 14
53850-246 190 14 246 190 14 246 190 14 246 190 14
53851-246 190 14 232 195 16 190 146 13 214 214 214
53852-253 253 253 253 253 253 253 253 253 253 253 253
53853-253 253 253 253 253 253 253 253 253 253 253 253
53854-253 253 253 253 253 253 253 253 253 253 253 253
53855-253 253 253 250 250 250 170 170 170 26 26 26
53856- 2 2 6 2 2 6 37 26 9 163 110 8
53857-219 162 10 239 182 13 246 186 14 246 190 14
53858-246 190 14 246 190 14 246 190 14 246 190 14
53859-246 190 14 246 190 14 246 190 14 246 190 14
53860-246 190 14 246 190 14 246 190 14 246 190 14
53861-246 186 14 236 178 12 224 166 10 142 122 72
53862- 46 46 46 18 18 18 6 6 6 0 0 0
53863- 0 0 0 0 0 0 0 0 0 0 0 0
53864- 0 0 0 0 0 0 0 0 0 0 0 0
53865- 0 0 0 0 0 0 6 6 6 18 18 18
53866- 50 50 50 109 106 95 192 133 9 224 166 10
53867-242 186 14 246 190 14 246 190 14 246 190 14
53868-246 190 14 246 190 14 246 190 14 246 190 14
53869-246 190 14 246 190 14 246 190 14 246 190 14
53870-246 190 14 246 190 14 246 190 14 246 190 14
53871-242 186 14 226 184 13 210 162 10 142 110 46
53872-226 226 226 253 253 253 253 253 253 253 253 253
53873-253 253 253 253 253 253 253 253 253 253 253 253
53874-253 253 253 253 253 253 253 253 253 253 253 253
53875-198 198 198 66 66 66 2 2 6 2 2 6
53876- 2 2 6 2 2 6 50 34 6 156 107 11
53877-219 162 10 239 182 13 246 186 14 246 190 14
53878-246 190 14 246 190 14 246 190 14 246 190 14
53879-246 190 14 246 190 14 246 190 14 246 190 14
53880-246 190 14 246 190 14 246 190 14 242 186 14
53881-234 174 13 213 154 11 154 122 46 66 66 66
53882- 30 30 30 10 10 10 0 0 0 0 0 0
53883- 0 0 0 0 0 0 0 0 0 0 0 0
53884- 0 0 0 0 0 0 0 0 0 0 0 0
53885- 0 0 0 0 0 0 6 6 6 22 22 22
53886- 58 58 58 154 121 60 206 145 10 234 174 13
53887-242 186 14 246 186 14 246 190 14 246 190 14
53888-246 190 14 246 190 14 246 190 14 246 190 14
53889-246 190 14 246 190 14 246 190 14 246 190 14
53890-246 190 14 246 190 14 246 190 14 246 190 14
53891-246 186 14 236 178 12 210 162 10 163 110 8
53892- 61 42 6 138 138 138 218 218 218 250 250 250
53893-253 253 253 253 253 253 253 253 253 250 250 250
53894-242 242 242 210 210 210 144 144 144 66 66 66
53895- 6 6 6 2 2 6 2 2 6 2 2 6
53896- 2 2 6 2 2 6 61 42 6 163 110 8
53897-216 158 10 236 178 12 246 190 14 246 190 14
53898-246 190 14 246 190 14 246 190 14 246 190 14
53899-246 190 14 246 190 14 246 190 14 246 190 14
53900-246 190 14 239 182 13 230 174 11 216 158 10
53901-190 142 34 124 112 88 70 70 70 38 38 38
53902- 18 18 18 6 6 6 0 0 0 0 0 0
53903- 0 0 0 0 0 0 0 0 0 0 0 0
53904- 0 0 0 0 0 0 0 0 0 0 0 0
53905- 0 0 0 0 0 0 6 6 6 22 22 22
53906- 62 62 62 168 124 44 206 145 10 224 166 10
53907-236 178 12 239 182 13 242 186 14 242 186 14
53908-246 186 14 246 190 14 246 190 14 246 190 14
53909-246 190 14 246 190 14 246 190 14 246 190 14
53910-246 190 14 246 190 14 246 190 14 246 190 14
53911-246 190 14 236 178 12 216 158 10 175 118 6
53912- 80 54 7 2 2 6 6 6 6 30 30 30
53913- 54 54 54 62 62 62 50 50 50 38 38 38
53914- 14 14 14 2 2 6 2 2 6 2 2 6
53915- 2 2 6 2 2 6 2 2 6 2 2 6
53916- 2 2 6 6 6 6 80 54 7 167 114 7
53917-213 154 11 236 178 12 246 190 14 246 190 14
53918-246 190 14 246 190 14 246 190 14 246 190 14
53919-246 190 14 242 186 14 239 182 13 239 182 13
53920-230 174 11 210 150 10 174 135 50 124 112 88
53921- 82 82 82 54 54 54 34 34 34 18 18 18
53922- 6 6 6 0 0 0 0 0 0 0 0 0
53923- 0 0 0 0 0 0 0 0 0 0 0 0
53924- 0 0 0 0 0 0 0 0 0 0 0 0
53925- 0 0 0 0 0 0 6 6 6 18 18 18
53926- 50 50 50 158 118 36 192 133 9 200 144 11
53927-216 158 10 219 162 10 224 166 10 226 170 11
53928-230 174 11 236 178 12 239 182 13 239 182 13
53929-242 186 14 246 186 14 246 190 14 246 190 14
53930-246 190 14 246 190 14 246 190 14 246 190 14
53931-246 186 14 230 174 11 210 150 10 163 110 8
53932-104 69 6 10 10 10 2 2 6 2 2 6
53933- 2 2 6 2 2 6 2 2 6 2 2 6
53934- 2 2 6 2 2 6 2 2 6 2 2 6
53935- 2 2 6 2 2 6 2 2 6 2 2 6
53936- 2 2 6 6 6 6 91 60 6 167 114 7
53937-206 145 10 230 174 11 242 186 14 246 190 14
53938-246 190 14 246 190 14 246 186 14 242 186 14
53939-239 182 13 230 174 11 224 166 10 213 154 11
53940-180 133 36 124 112 88 86 86 86 58 58 58
53941- 38 38 38 22 22 22 10 10 10 6 6 6
53942- 0 0 0 0 0 0 0 0 0 0 0 0
53943- 0 0 0 0 0 0 0 0 0 0 0 0
53944- 0 0 0 0 0 0 0 0 0 0 0 0
53945- 0 0 0 0 0 0 0 0 0 14 14 14
53946- 34 34 34 70 70 70 138 110 50 158 118 36
53947-167 114 7 180 123 7 192 133 9 197 138 11
53948-200 144 11 206 145 10 213 154 11 219 162 10
53949-224 166 10 230 174 11 239 182 13 242 186 14
53950-246 186 14 246 186 14 246 186 14 246 186 14
53951-239 182 13 216 158 10 185 133 11 152 99 6
53952-104 69 6 18 14 6 2 2 6 2 2 6
53953- 2 2 6 2 2 6 2 2 6 2 2 6
53954- 2 2 6 2 2 6 2 2 6 2 2 6
53955- 2 2 6 2 2 6 2 2 6 2 2 6
53956- 2 2 6 6 6 6 80 54 7 152 99 6
53957-192 133 9 219 162 10 236 178 12 239 182 13
53958-246 186 14 242 186 14 239 182 13 236 178 12
53959-224 166 10 206 145 10 192 133 9 154 121 60
53960- 94 94 94 62 62 62 42 42 42 22 22 22
53961- 14 14 14 6 6 6 0 0 0 0 0 0
53962- 0 0 0 0 0 0 0 0 0 0 0 0
53963- 0 0 0 0 0 0 0 0 0 0 0 0
53964- 0 0 0 0 0 0 0 0 0 0 0 0
53965- 0 0 0 0 0 0 0 0 0 6 6 6
53966- 18 18 18 34 34 34 58 58 58 78 78 78
53967-101 98 89 124 112 88 142 110 46 156 107 11
53968-163 110 8 167 114 7 175 118 6 180 123 7
53969-185 133 11 197 138 11 210 150 10 219 162 10
53970-226 170 11 236 178 12 236 178 12 234 174 13
53971-219 162 10 197 138 11 163 110 8 130 83 6
53972- 91 60 6 10 10 10 2 2 6 2 2 6
53973- 18 18 18 38 38 38 38 38 38 38 38 38
53974- 38 38 38 38 38 38 38 38 38 38 38 38
53975- 38 38 38 38 38 38 26 26 26 2 2 6
53976- 2 2 6 6 6 6 70 47 6 137 92 6
53977-175 118 6 200 144 11 219 162 10 230 174 11
53978-234 174 13 230 174 11 219 162 10 210 150 10
53979-192 133 9 163 110 8 124 112 88 82 82 82
53980- 50 50 50 30 30 30 14 14 14 6 6 6
53981- 0 0 0 0 0 0 0 0 0 0 0 0
53982- 0 0 0 0 0 0 0 0 0 0 0 0
53983- 0 0 0 0 0 0 0 0 0 0 0 0
53984- 0 0 0 0 0 0 0 0 0 0 0 0
53985- 0 0 0 0 0 0 0 0 0 0 0 0
53986- 6 6 6 14 14 14 22 22 22 34 34 34
53987- 42 42 42 58 58 58 74 74 74 86 86 86
53988-101 98 89 122 102 70 130 98 46 121 87 25
53989-137 92 6 152 99 6 163 110 8 180 123 7
53990-185 133 11 197 138 11 206 145 10 200 144 11
53991-180 123 7 156 107 11 130 83 6 104 69 6
53992- 50 34 6 54 54 54 110 110 110 101 98 89
53993- 86 86 86 82 82 82 78 78 78 78 78 78
53994- 78 78 78 78 78 78 78 78 78 78 78 78
53995- 78 78 78 82 82 82 86 86 86 94 94 94
53996-106 106 106 101 101 101 86 66 34 124 80 6
53997-156 107 11 180 123 7 192 133 9 200 144 11
53998-206 145 10 200 144 11 192 133 9 175 118 6
53999-139 102 15 109 106 95 70 70 70 42 42 42
54000- 22 22 22 10 10 10 0 0 0 0 0 0
54001- 0 0 0 0 0 0 0 0 0 0 0 0
54002- 0 0 0 0 0 0 0 0 0 0 0 0
54003- 0 0 0 0 0 0 0 0 0 0 0 0
54004- 0 0 0 0 0 0 0 0 0 0 0 0
54005- 0 0 0 0 0 0 0 0 0 0 0 0
54006- 0 0 0 0 0 0 6 6 6 10 10 10
54007- 14 14 14 22 22 22 30 30 30 38 38 38
54008- 50 50 50 62 62 62 74 74 74 90 90 90
54009-101 98 89 112 100 78 121 87 25 124 80 6
54010-137 92 6 152 99 6 152 99 6 152 99 6
54011-138 86 6 124 80 6 98 70 6 86 66 30
54012-101 98 89 82 82 82 58 58 58 46 46 46
54013- 38 38 38 34 34 34 34 34 34 34 34 34
54014- 34 34 34 34 34 34 34 34 34 34 34 34
54015- 34 34 34 34 34 34 38 38 38 42 42 42
54016- 54 54 54 82 82 82 94 86 76 91 60 6
54017-134 86 6 156 107 11 167 114 7 175 118 6
54018-175 118 6 167 114 7 152 99 6 121 87 25
54019-101 98 89 62 62 62 34 34 34 18 18 18
54020- 6 6 6 0 0 0 0 0 0 0 0 0
54021- 0 0 0 0 0 0 0 0 0 0 0 0
54022- 0 0 0 0 0 0 0 0 0 0 0 0
54023- 0 0 0 0 0 0 0 0 0 0 0 0
54024- 0 0 0 0 0 0 0 0 0 0 0 0
54025- 0 0 0 0 0 0 0 0 0 0 0 0
54026- 0 0 0 0 0 0 0 0 0 0 0 0
54027- 0 0 0 6 6 6 6 6 6 10 10 10
54028- 18 18 18 22 22 22 30 30 30 42 42 42
54029- 50 50 50 66 66 66 86 86 86 101 98 89
54030-106 86 58 98 70 6 104 69 6 104 69 6
54031-104 69 6 91 60 6 82 62 34 90 90 90
54032- 62 62 62 38 38 38 22 22 22 14 14 14
54033- 10 10 10 10 10 10 10 10 10 10 10 10
54034- 10 10 10 10 10 10 6 6 6 10 10 10
54035- 10 10 10 10 10 10 10 10 10 14 14 14
54036- 22 22 22 42 42 42 70 70 70 89 81 66
54037- 80 54 7 104 69 6 124 80 6 137 92 6
54038-134 86 6 116 81 8 100 82 52 86 86 86
54039- 58 58 58 30 30 30 14 14 14 6 6 6
54040- 0 0 0 0 0 0 0 0 0 0 0 0
54041- 0 0 0 0 0 0 0 0 0 0 0 0
54042- 0 0 0 0 0 0 0 0 0 0 0 0
54043- 0 0 0 0 0 0 0 0 0 0 0 0
54044- 0 0 0 0 0 0 0 0 0 0 0 0
54045- 0 0 0 0 0 0 0 0 0 0 0 0
54046- 0 0 0 0 0 0 0 0 0 0 0 0
54047- 0 0 0 0 0 0 0 0 0 0 0 0
54048- 0 0 0 6 6 6 10 10 10 14 14 14
54049- 18 18 18 26 26 26 38 38 38 54 54 54
54050- 70 70 70 86 86 86 94 86 76 89 81 66
54051- 89 81 66 86 86 86 74 74 74 50 50 50
54052- 30 30 30 14 14 14 6 6 6 0 0 0
54053- 0 0 0 0 0 0 0 0 0 0 0 0
54054- 0 0 0 0 0 0 0 0 0 0 0 0
54055- 0 0 0 0 0 0 0 0 0 0 0 0
54056- 6 6 6 18 18 18 34 34 34 58 58 58
54057- 82 82 82 89 81 66 89 81 66 89 81 66
54058- 94 86 66 94 86 76 74 74 74 50 50 50
54059- 26 26 26 14 14 14 6 6 6 0 0 0
54060- 0 0 0 0 0 0 0 0 0 0 0 0
54061- 0 0 0 0 0 0 0 0 0 0 0 0
54062- 0 0 0 0 0 0 0 0 0 0 0 0
54063- 0 0 0 0 0 0 0 0 0 0 0 0
54064- 0 0 0 0 0 0 0 0 0 0 0 0
54065- 0 0 0 0 0 0 0 0 0 0 0 0
54066- 0 0 0 0 0 0 0 0 0 0 0 0
54067- 0 0 0 0 0 0 0 0 0 0 0 0
54068- 0 0 0 0 0 0 0 0 0 0 0 0
54069- 6 6 6 6 6 6 14 14 14 18 18 18
54070- 30 30 30 38 38 38 46 46 46 54 54 54
54071- 50 50 50 42 42 42 30 30 30 18 18 18
54072- 10 10 10 0 0 0 0 0 0 0 0 0
54073- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 14 14 14 26 26 26
54077- 38 38 38 50 50 50 58 58 58 58 58 58
54078- 54 54 54 42 42 42 30 30 30 18 18 18
54079- 10 10 10 0 0 0 0 0 0 0 0 0
54080- 0 0 0 0 0 0 0 0 0 0 0 0
54081- 0 0 0 0 0 0 0 0 0 0 0 0
54082- 0 0 0 0 0 0 0 0 0 0 0 0
54083- 0 0 0 0 0 0 0 0 0 0 0 0
54084- 0 0 0 0 0 0 0 0 0 0 0 0
54085- 0 0 0 0 0 0 0 0 0 0 0 0
54086- 0 0 0 0 0 0 0 0 0 0 0 0
54087- 0 0 0 0 0 0 0 0 0 0 0 0
54088- 0 0 0 0 0 0 0 0 0 0 0 0
54089- 0 0 0 0 0 0 0 0 0 6 6 6
54090- 6 6 6 10 10 10 14 14 14 18 18 18
54091- 18 18 18 14 14 14 10 10 10 6 6 6
54092- 0 0 0 0 0 0 0 0 0 0 0 0
54093- 0 0 0 0 0 0 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 6 6 6
54097- 14 14 14 18 18 18 22 22 22 22 22 22
54098- 18 18 18 14 14 14 10 10 10 6 6 6
54099- 0 0 0 0 0 0 0 0 0 0 0 0
54100- 0 0 0 0 0 0 0 0 0 0 0 0
54101- 0 0 0 0 0 0 0 0 0 0 0 0
54102- 0 0 0 0 0 0 0 0 0 0 0 0
54103- 0 0 0 0 0 0 0 0 0 0 0 0
54104+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54105+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54106+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54107+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54108+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54109+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54110+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54111+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54112+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54113+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54114+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54115+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54116+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54117+4 4 4 4 4 4
54118+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54119+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54120+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54121+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54122+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54123+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54124+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54125+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54126+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54127+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54128+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54129+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54130+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54131+4 4 4 4 4 4
54132+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54133+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54134+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54135+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54136+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54138+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54139+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54140+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54141+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54142+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54143+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54144+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54145+4 4 4 4 4 4
54146+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54147+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54148+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54149+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54150+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54151+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54153+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54154+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54155+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54156+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54157+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54158+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54159+4 4 4 4 4 4
54160+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54161+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54162+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54163+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54164+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54165+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54166+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54167+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54168+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54169+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54170+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54171+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54172+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54173+4 4 4 4 4 4
54174+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54175+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54176+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54178+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54181+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54182+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54183+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54184+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54185+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54186+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54187+4 4 4 4 4 4
54188+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54189+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54190+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54191+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54192+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
54193+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
54194+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54195+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54196+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54197+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
54198+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54199+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
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
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 2 2 2 0 0 0 3 4 3 26 28 28
54207+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
54208+5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54211+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
54212+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
54213+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
54214+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54215+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+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
54221+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
54222+0 0 0 3 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
54225+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
54226+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
54227+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
54228+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
54229+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 5 5 5 5 5 5 2 2 2 0 0 0
54234+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
54235+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
54236+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 5 5 5 5 5 5
54239+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
54240+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
54241+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
54242+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
54243+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 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
54248+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
54249+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
54250+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
54251+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54252+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
54253+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
54254+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
54255+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
54256+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
54257+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 5 5 5
54261+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
54262+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
54263+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
54264+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
54265+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54266+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
54267+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
54268+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
54269+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
54270+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
54271+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 5 5 5 3 3 3
54275+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
54276+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
54277+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
54278+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
54279+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
54280+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
54281+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
54282+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
54283+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
54284+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
54285+4 4 4 4 4 4
54286+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54287+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54288+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
54289+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
54290+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
54291+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
54292+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
54293+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
54294+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
54295+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
54296+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
54297+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
54298+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
54299+4 4 4 4 4 4
54300+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54301+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54302+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
54303+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
54304+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
54305+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
54306+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
54307+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
54308+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
54309+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
54310+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
54311+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
54312+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54313+4 4 4 4 4 4
54314+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54315+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54316+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
54317+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
54318+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
54319+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
54320+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
54321+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
54322+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
54323+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
54324+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
54325+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
54326+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
54327+4 4 4 4 4 4
54328+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54329+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
54330+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
54331+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
54332+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
54333+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
54334+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
54335+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
54336+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
54337+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
54338+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
54339+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
54340+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
54341+4 4 4 4 4 4
54342+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54343+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
54344+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
54345+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
54346+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54347+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
54348+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
54349+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
54350+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
54351+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
54352+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
54353+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
54354+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
54355+0 0 0 4 4 4
54356+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54357+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
54358+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
54359+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
54360+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
54361+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
54362+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
54363+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
54364+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
54365+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
54366+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
54367+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
54368+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
54369+2 0 0 0 0 0
54370+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
54371+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
54372+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
54373+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
54374+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
54375+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
54376+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
54377+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
54378+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
54379+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
54380+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
54381+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
54382+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
54383+37 38 37 0 0 0
54384+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54385+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
54386+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
54387+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
54388+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
54389+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
54390+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
54391+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
54392+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
54393+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
54394+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
54395+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
54396+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
54397+85 115 134 4 0 0
54398+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
54399+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
54400+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
54401+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
54402+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
54403+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
54404+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
54405+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
54406+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
54407+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
54408+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
54409+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
54410+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
54411+60 73 81 4 0 0
54412+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
54413+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
54414+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
54415+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
54416+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
54417+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
54418+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
54419+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
54420+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
54421+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
54422+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
54423+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
54424+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
54425+16 19 21 4 0 0
54426+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
54427+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
54428+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
54429+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
54430+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
54431+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
54432+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
54433+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
54434+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
54435+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
54436+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
54437+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
54438+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
54439+4 0 0 4 3 3
54440+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
54441+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
54442+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
54443+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
54444+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
54445+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
54446+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
54447+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
54448+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
54449+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
54450+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
54451+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
54452+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
54453+3 2 2 4 4 4
54454+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
54455+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
54456+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
54457+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54458+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
54459+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
54460+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
54461+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
54462+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
54463+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
54464+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
54465+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
54466+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
54467+4 4 4 4 4 4
54468+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
54469+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
54470+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
54471+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
54472+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
54473+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
54474+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
54475+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
54476+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
54477+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
54478+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
54479+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
54480+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
54481+4 4 4 4 4 4
54482+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
54483+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
54484+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
54485+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
54486+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
54487+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
54488+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
54489+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
54490+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
54491+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
54492+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
54493+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
54494+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
54495+5 5 5 5 5 5
54496+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
54497+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
54498+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
54499+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
54500+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
54501+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54502+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
54503+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
54504+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
54505+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
54506+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
54507+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
54508+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
54509+5 5 5 4 4 4
54510+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
54511+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
54512+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
54513+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
54514+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54515+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
54516+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
54517+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
54518+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
54519+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
54520+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
54521+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
54522+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54523+4 4 4 4 4 4
54524+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
54525+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
54526+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
54527+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
54528+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
54529+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54530+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54531+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
54532+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
54533+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
54534+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
54535+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
54536+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54537+4 4 4 4 4 4
54538+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
54539+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
54540+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
54541+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
54542+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54543+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
54544+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
54545+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
54546+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
54547+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
54548+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
54549+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54550+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54551+4 4 4 4 4 4
54552+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
54553+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
54554+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
54555+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
54556+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54557+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54558+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54559+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
54560+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
54561+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
54562+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
54563+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54564+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54565+4 4 4 4 4 4
54566+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
54567+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
54568+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
54569+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
54570+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54571+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
54572+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
54573+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
54574+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
54575+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
54576+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54577+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54578+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54579+4 4 4 4 4 4
54580+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
54581+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
54582+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
54583+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
54584+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54585+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
54586+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
54587+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
54588+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
54589+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
54590+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
54591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54592+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54593+4 4 4 4 4 4
54594+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
54595+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
54596+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
54597+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
54598+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54599+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
54600+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
54601+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
54602+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
54603+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
54604+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
54605+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54606+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54607+4 4 4 4 4 4
54608+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
54609+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
54610+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
54611+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
54612+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
54613+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
54614+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
54615+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
54616+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
54617+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
54618+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54621+4 4 4 4 4 4
54622+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
54623+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
54624+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
54625+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
54626+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54627+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
54628+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
54629+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
54630+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
54631+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
54632+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54634+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54635+4 4 4 4 4 4
54636+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
54637+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
54638+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
54639+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
54640+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54641+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
54642+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
54643+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
54644+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
54645+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
54646+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54648+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54649+4 4 4 4 4 4
54650+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
54651+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
54652+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
54653+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
54654+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54655+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
54656+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
54657+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
54658+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
54659+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54660+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54662+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54663+4 4 4 4 4 4
54664+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
54665+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
54666+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
54667+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
54668+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
54669+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
54670+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
54671+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
54672+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54673+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54674+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54677+4 4 4 4 4 4
54678+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
54679+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
54680+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
54681+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
54682+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54683+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
54684+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
54685+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
54686+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54687+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54688+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54691+4 4 4 4 4 4
54692+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
54693+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
54694+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
54695+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
54696+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
54697+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
54698+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
54699+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
54700+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54701+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54702+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54705+4 4 4 4 4 4
54706+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
54707+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
54708+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54709+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
54710+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
54711+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
54712+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
54713+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
54714+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
54715+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54716+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54719+4 4 4 4 4 4
54720+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
54721+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
54722+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
54723+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
54724+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
54725+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
54726+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
54727+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
54728+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54729+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54730+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54733+4 4 4 4 4 4
54734+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
54735+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
54736+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54737+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
54738+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
54739+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
54740+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
54741+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
54742+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
54743+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54744+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54747+4 4 4 4 4 4
54748+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
54749+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
54750+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
54751+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
54752+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
54753+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
54754+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
54755+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
54756+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54757+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54758+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54761+4 4 4 4 4 4
54762+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54763+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
54764+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54765+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
54766+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
54767+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
54768+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
54769+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
54770+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54771+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54772+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54775+4 4 4 4 4 4
54776+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
54777+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
54778+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
54779+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
54780+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
54781+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
54782+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54783+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
54784+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54785+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54786+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54789+4 4 4 4 4 4
54790+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54791+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
54792+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
54793+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
54794+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
54795+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
54796+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54797+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
54798+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54799+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54800+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54803+4 4 4 4 4 4
54804+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
54805+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
54806+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
54807+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
54808+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
54809+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
54810+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
54811+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
54812+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
54813+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54814+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54817+4 4 4 4 4 4
54818+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54819+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
54820+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
54821+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
54822+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
54823+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
54824+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
54825+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
54826+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
54827+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54828+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54831+4 4 4 4 4 4
54832+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
54833+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
54834+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
54835+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
54836+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
54837+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
54838+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
54839+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
54840+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
54841+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54842+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54845+4 4 4 4 4 4
54846+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54847+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
54848+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
54849+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
54850+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
54851+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
54852+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
54853+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
54854+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
54855+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54856+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54859+4 4 4 4 4 4
54860+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
54861+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
54862+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
54863+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
54864+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
54865+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
54866+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
54867+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
54868+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
54869+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
54870+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54873+4 4 4 4 4 4
54874+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
54875+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54876+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
54877+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
54878+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
54879+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
54880+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
54881+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
54882+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
54883+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
54884+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54885+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54887+4 4 4 4 4 4
54888+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
54889+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54890+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
54891+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
54892+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
54893+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
54894+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54895+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
54896+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
54897+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
54898+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54899+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54900+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54901+4 4 4 4 4 4
54902+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
54903+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
54904+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
54905+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
54906+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
54907+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
54908+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
54909+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
54910+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
54911+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
54912+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54913+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54914+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54915+4 4 4 4 4 4
54916+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
54917+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
54918+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
54919+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
54920+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
54921+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
54922+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
54923+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
54924+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
54925+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
54926+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54927+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54928+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54929+4 4 4 4 4 4
54930+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54931+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
54932+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
54933+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
54934+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
54935+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
54936+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
54937+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
54938+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
54939+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
54940+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54941+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54942+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54943+4 4 4 4 4 4
54944+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
54945+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
54946+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
54947+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
54948+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
54949+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
54950+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
54951+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
54952+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
54953+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
54954+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54955+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54956+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54957+4 4 4 4 4 4
54958+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
54959+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
54960+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
54961+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
54962+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
54963+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
54964+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
54965+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
54966+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54967+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54968+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54969+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54970+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54971+4 4 4 4 4 4
54972+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
54973+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54974+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
54975+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
54976+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
54977+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
54978+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
54979+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
54980+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
54981+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54982+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54983+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54984+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54985+4 4 4 4 4 4
54986+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
54987+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
54988+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
54989+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
54990+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
54991+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
54992+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
54993+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
54994+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
54995+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54996+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54997+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54998+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54999+4 4 4 4 4 4
55000+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55001+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
55002+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
55003+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
55004+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
55005+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
55006+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
55007+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
55008+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55009+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55010+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55011+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55012+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55013+4 4 4 4 4 4
55014+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
55015+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
55016+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55017+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
55018+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
55019+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
55020+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
55021+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
55022+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55023+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55024+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55025+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55026+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55027+4 4 4 4 4 4
55028+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55029+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
55030+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
55031+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
55032+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
55033+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
55034+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
55035+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55036+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55037+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55038+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55039+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55040+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55041+4 4 4 4 4 4
55042+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55043+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
55044+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55045+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
55046+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
55047+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
55048+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
55049+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
55050+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55051+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55052+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55053+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55054+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55055+4 4 4 4 4 4
55056+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55057+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
55058+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
55059+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
55060+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
55061+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
55062+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
55063+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
55064+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55065+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55066+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55067+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55068+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55069+4 4 4 4 4 4
55070+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55071+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55072+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
55073+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55074+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
55075+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
55076+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
55077+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55078+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55079+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55080+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55081+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55082+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55083+4 4 4 4 4 4
55084+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55085+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55086+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55087+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
55088+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
55089+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
55090+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
55091+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55092+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55093+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55094+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55095+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55096+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55097+4 4 4 4 4 4
55098+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55099+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55100+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55101+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55102+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
55103+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
55104+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
55107+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55108+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55109+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55110+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55111+4 4 4 4 4 4
55112+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55113+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55114+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55115+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55116+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55117+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
55118+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 4 4 4 4 4 4
55121+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55122+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55123+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55124+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55125+4 4 4 4 4 4
55126+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55127+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55128+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55129+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55130+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55131+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55132+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55135+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55136+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55138+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55139+4 4 4 4 4 4
55140+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55141+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55142+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55143+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
55144+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
55145+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
55146+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55149+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55150+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55151+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55153+4 4 4 4 4 4
55154+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55155+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55156+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55157+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55158+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
55159+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55160+6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55163+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55164+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55165+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55166+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55167+4 4 4 4 4 4
55168+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55169+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55170+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55171+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55172+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
55173+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
55174+4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55178+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55181+4 4 4 4 4 4
55182+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55183+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55184+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55185+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55186+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
55187+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
55188+5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55191+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55192+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55194+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55195+4 4 4 4 4 4
55196+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55197+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55198+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55199+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55200+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
55201+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
55205+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55206+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55208+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55209+4 4 4 4 4 4
55210+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55211+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55212+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55213+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55214+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55215+5 5 5 4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55219+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55220+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55221+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55223+4 4 4 4 4 4
55224diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
55225index a01147f..5d896f8 100644
55226--- a/drivers/video/matrox/matroxfb_DAC1064.c
55227+++ b/drivers/video/matrox/matroxfb_DAC1064.c
55228@@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55229
55230 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55231 struct matrox_switch matrox_mystique = {
55232- MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55233+ .preinit = MGA1064_preinit,
55234+ .reset = MGA1064_reset,
55235+ .init = MGA1064_init,
55236+ .restore = MGA1064_restore,
55237 };
55238 EXPORT_SYMBOL(matrox_mystique);
55239 #endif
55240
55241 #ifdef CONFIG_FB_MATROX_G
55242 struct matrox_switch matrox_G100 = {
55243- MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55244+ .preinit = MGAG100_preinit,
55245+ .reset = MGAG100_reset,
55246+ .init = MGAG100_init,
55247+ .restore = MGAG100_restore,
55248 };
55249 EXPORT_SYMBOL(matrox_G100);
55250 #endif
55251diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
55252index 195ad7c..09743fc 100644
55253--- a/drivers/video/matrox/matroxfb_Ti3026.c
55254+++ b/drivers/video/matrox/matroxfb_Ti3026.c
55255@@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55256 }
55257
55258 struct matrox_switch matrox_millennium = {
55259- Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55260+ .preinit = Ti3026_preinit,
55261+ .reset = Ti3026_reset,
55262+ .init = Ti3026_init,
55263+ .restore = Ti3026_restore
55264 };
55265 EXPORT_SYMBOL(matrox_millennium);
55266 #endif
55267diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
55268index fe92eed..106e085 100644
55269--- a/drivers/video/mb862xx/mb862xxfb_accel.c
55270+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
55271@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55272 struct mb862xxfb_par *par = info->par;
55273
55274 if (info->var.bits_per_pixel == 32) {
55275- info->fbops->fb_fillrect = cfb_fillrect;
55276- info->fbops->fb_copyarea = cfb_copyarea;
55277- info->fbops->fb_imageblit = cfb_imageblit;
55278+ pax_open_kernel();
55279+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55280+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55281+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55282+ pax_close_kernel();
55283 } else {
55284 outreg(disp, GC_L0EM, 3);
55285- info->fbops->fb_fillrect = mb86290fb_fillrect;
55286- info->fbops->fb_copyarea = mb86290fb_copyarea;
55287- info->fbops->fb_imageblit = mb86290fb_imageblit;
55288+ pax_open_kernel();
55289+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55290+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55291+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55292+ pax_close_kernel();
55293 }
55294 outreg(draw, GDC_REG_DRAW_BASE, 0);
55295 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55296diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
55297index ff22871..b129bed 100644
55298--- a/drivers/video/nvidia/nvidia.c
55299+++ b/drivers/video/nvidia/nvidia.c
55300@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55301 info->fix.line_length = (info->var.xres_virtual *
55302 info->var.bits_per_pixel) >> 3;
55303 if (info->var.accel_flags) {
55304- info->fbops->fb_imageblit = nvidiafb_imageblit;
55305- info->fbops->fb_fillrect = nvidiafb_fillrect;
55306- info->fbops->fb_copyarea = nvidiafb_copyarea;
55307- info->fbops->fb_sync = nvidiafb_sync;
55308+ pax_open_kernel();
55309+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55310+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55311+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55312+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55313+ pax_close_kernel();
55314 info->pixmap.scan_align = 4;
55315 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55316 info->flags |= FBINFO_READS_FAST;
55317 NVResetGraphics(info);
55318 } else {
55319- info->fbops->fb_imageblit = cfb_imageblit;
55320- info->fbops->fb_fillrect = cfb_fillrect;
55321- info->fbops->fb_copyarea = cfb_copyarea;
55322- info->fbops->fb_sync = NULL;
55323+ pax_open_kernel();
55324+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55325+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55326+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55327+ *(void **)&info->fbops->fb_sync = NULL;
55328+ pax_close_kernel();
55329 info->pixmap.scan_align = 1;
55330 info->flags |= FBINFO_HWACCEL_DISABLED;
55331 info->flags &= ~FBINFO_READS_FAST;
55332@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55333 info->pixmap.size = 8 * 1024;
55334 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55335
55336- if (!hwcur)
55337- info->fbops->fb_cursor = NULL;
55338+ if (!hwcur) {
55339+ pax_open_kernel();
55340+ *(void **)&info->fbops->fb_cursor = NULL;
55341+ pax_close_kernel();
55342+ }
55343
55344 info->var.accel_flags = (!noaccel);
55345
55346diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
55347index 669a81f..e216d76 100644
55348--- a/drivers/video/omap2/dss/display.c
55349+++ b/drivers/video/omap2/dss/display.c
55350@@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55351 snprintf(dssdev->alias, sizeof(dssdev->alias),
55352 "display%d", disp_num_counter++);
55353
55354+ pax_open_kernel();
55355 if (drv && drv->get_resolution == NULL)
55356- drv->get_resolution = omapdss_default_get_resolution;
55357+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55358 if (drv && drv->get_recommended_bpp == NULL)
55359- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55360+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55361 if (drv && drv->get_timings == NULL)
55362- drv->get_timings = omapdss_default_get_timings;
55363+ *(void **)&drv->get_timings = omapdss_default_get_timings;
55364+ pax_close_kernel();
55365
55366 mutex_lock(&panel_list_mutex);
55367 list_add_tail(&dssdev->panel_list, &panel_list);
55368diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
55369index 83433cb..71e9b98 100644
55370--- a/drivers/video/s1d13xxxfb.c
55371+++ b/drivers/video/s1d13xxxfb.c
55372@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55373
55374 switch(prod_id) {
55375 case S1D13506_PROD_ID: /* activate acceleration */
55376- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55377- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55378+ pax_open_kernel();
55379+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55380+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55381+ pax_close_kernel();
55382 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55383 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55384 break;
55385diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
55386index d513ed6..90b0de9 100644
55387--- a/drivers/video/smscufx.c
55388+++ b/drivers/video/smscufx.c
55389@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55390 fb_deferred_io_cleanup(info);
55391 kfree(info->fbdefio);
55392 info->fbdefio = NULL;
55393- info->fbops->fb_mmap = ufx_ops_mmap;
55394+ pax_open_kernel();
55395+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55396+ pax_close_kernel();
55397 }
55398
55399 pr_debug("released /dev/fb%d user=%d count=%d",
55400diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
55401index 025f14e..20eb4db 100644
55402--- a/drivers/video/udlfb.c
55403+++ b/drivers/video/udlfb.c
55404@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55405 dlfb_urb_completion(urb);
55406
55407 error:
55408- atomic_add(bytes_sent, &dev->bytes_sent);
55409- atomic_add(bytes_identical, &dev->bytes_identical);
55410- atomic_add(width*height*2, &dev->bytes_rendered);
55411+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55412+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55413+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55414 end_cycles = get_cycles();
55415- atomic_add(((unsigned int) ((end_cycles - start_cycles)
55416+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55417 >> 10)), /* Kcycles */
55418 &dev->cpu_kcycles_used);
55419
55420@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55421 dlfb_urb_completion(urb);
55422
55423 error:
55424- atomic_add(bytes_sent, &dev->bytes_sent);
55425- atomic_add(bytes_identical, &dev->bytes_identical);
55426- atomic_add(bytes_rendered, &dev->bytes_rendered);
55427+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55428+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55429+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
55430 end_cycles = get_cycles();
55431- atomic_add(((unsigned int) ((end_cycles - start_cycles)
55432+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55433 >> 10)), /* Kcycles */
55434 &dev->cpu_kcycles_used);
55435 }
55436@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55437 fb_deferred_io_cleanup(info);
55438 kfree(info->fbdefio);
55439 info->fbdefio = NULL;
55440- info->fbops->fb_mmap = dlfb_ops_mmap;
55441+ pax_open_kernel();
55442+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55443+ pax_close_kernel();
55444 }
55445
55446 pr_warn("released /dev/fb%d user=%d count=%d\n",
55447@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55448 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55449 struct dlfb_data *dev = fb_info->par;
55450 return snprintf(buf, PAGE_SIZE, "%u\n",
55451- atomic_read(&dev->bytes_rendered));
55452+ atomic_read_unchecked(&dev->bytes_rendered));
55453 }
55454
55455 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55456@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55457 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55458 struct dlfb_data *dev = fb_info->par;
55459 return snprintf(buf, PAGE_SIZE, "%u\n",
55460- atomic_read(&dev->bytes_identical));
55461+ atomic_read_unchecked(&dev->bytes_identical));
55462 }
55463
55464 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55465@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55466 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55467 struct dlfb_data *dev = fb_info->par;
55468 return snprintf(buf, PAGE_SIZE, "%u\n",
55469- atomic_read(&dev->bytes_sent));
55470+ atomic_read_unchecked(&dev->bytes_sent));
55471 }
55472
55473 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55474@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55475 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55476 struct dlfb_data *dev = fb_info->par;
55477 return snprintf(buf, PAGE_SIZE, "%u\n",
55478- atomic_read(&dev->cpu_kcycles_used));
55479+ atomic_read_unchecked(&dev->cpu_kcycles_used));
55480 }
55481
55482 static ssize_t edid_show(
55483@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
55484 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55485 struct dlfb_data *dev = fb_info->par;
55486
55487- atomic_set(&dev->bytes_rendered, 0);
55488- atomic_set(&dev->bytes_identical, 0);
55489- atomic_set(&dev->bytes_sent, 0);
55490- atomic_set(&dev->cpu_kcycles_used, 0);
55491+ atomic_set_unchecked(&dev->bytes_rendered, 0);
55492+ atomic_set_unchecked(&dev->bytes_identical, 0);
55493+ atomic_set_unchecked(&dev->bytes_sent, 0);
55494+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
55495
55496 return count;
55497 }
55498diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
55499index 256fba7..6e75516 100644
55500--- a/drivers/video/uvesafb.c
55501+++ b/drivers/video/uvesafb.c
55502@@ -19,6 +19,7 @@
55503 #include <linux/io.h>
55504 #include <linux/mutex.h>
55505 #include <linux/slab.h>
55506+#include <linux/moduleloader.h>
55507 #include <video/edid.h>
55508 #include <video/uvesafb.h>
55509 #ifdef CONFIG_X86
55510@@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
55511 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
55512 par->pmi_setpal = par->ypan = 0;
55513 } else {
55514+
55515+#ifdef CONFIG_PAX_KERNEXEC
55516+#ifdef CONFIG_MODULES
55517+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
55518+#endif
55519+ if (!par->pmi_code) {
55520+ par->pmi_setpal = par->ypan = 0;
55521+ return 0;
55522+ }
55523+#endif
55524+
55525 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55526 + task->t.regs.edi);
55527+
55528+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55529+ pax_open_kernel();
55530+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55531+ pax_close_kernel();
55532+
55533+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55534+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55535+#else
55536 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55537 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55538+#endif
55539+
55540 printk(KERN_INFO "uvesafb: protected mode interface info at "
55541 "%04x:%04x\n",
55542 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55543@@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55544 par->ypan = ypan;
55545
55546 if (par->pmi_setpal || par->ypan) {
55547+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55548 if (__supported_pte_mask & _PAGE_NX) {
55549 par->pmi_setpal = par->ypan = 0;
55550 printk(KERN_WARNING "uvesafb: NX protection is active, "
55551 "better not use the PMI.\n");
55552- } else {
55553+ } else
55554+#endif
55555 uvesafb_vbe_getpmi(task, par);
55556- }
55557 }
55558 #else
55559 /* The protected mode interface is not available on non-x86. */
55560@@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55561 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55562
55563 /* Disable blanking if the user requested so. */
55564- if (!blank)
55565- info->fbops->fb_blank = NULL;
55566+ if (!blank) {
55567+ pax_open_kernel();
55568+ *(void **)&info->fbops->fb_blank = NULL;
55569+ pax_close_kernel();
55570+ }
55571
55572 /*
55573 * Find out how much IO memory is required for the mode with
55574@@ -1530,8 +1557,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55575 info->flags = FBINFO_FLAG_DEFAULT |
55576 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55577
55578- if (!par->ypan)
55579- info->fbops->fb_pan_display = NULL;
55580+ if (!par->ypan) {
55581+ pax_open_kernel();
55582+ *(void **)&info->fbops->fb_pan_display = NULL;
55583+ pax_close_kernel();
55584+ }
55585 }
55586
55587 static void uvesafb_init_mtrr(struct fb_info *info)
55588@@ -1792,6 +1822,11 @@ out_mode:
55589 out:
55590 kfree(par->vbe_modes);
55591
55592+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55593+ if (par->pmi_code)
55594+ module_free_exec(NULL, par->pmi_code);
55595+#endif
55596+
55597 framebuffer_release(info);
55598 return err;
55599 }
55600@@ -1816,6 +1851,12 @@ static int uvesafb_remove(struct platform_device *dev)
55601 kfree(par->vbe_modes);
55602 kfree(par->vbe_state_orig);
55603 kfree(par->vbe_state_saved);
55604+
55605+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55606+ if (par->pmi_code)
55607+ module_free_exec(NULL, par->pmi_code);
55608+#endif
55609+
55610 }
55611
55612 framebuffer_release(info);
55613diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
55614index 1c7da3b..56ea0bd 100644
55615--- a/drivers/video/vesafb.c
55616+++ b/drivers/video/vesafb.c
55617@@ -9,6 +9,7 @@
55618 */
55619
55620 #include <linux/module.h>
55621+#include <linux/moduleloader.h>
55622 #include <linux/kernel.h>
55623 #include <linux/errno.h>
55624 #include <linux/string.h>
55625@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55626 static int vram_total; /* Set total amount of memory */
55627 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55628 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55629-static void (*pmi_start)(void) __read_mostly;
55630-static void (*pmi_pal) (void) __read_mostly;
55631+static void (*pmi_start)(void) __read_only;
55632+static void (*pmi_pal) (void) __read_only;
55633 static int depth __read_mostly;
55634 static int vga_compat __read_mostly;
55635 /* --------------------------------------------------------------------- */
55636@@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
55637 unsigned int size_remap;
55638 unsigned int size_total;
55639 char *option = NULL;
55640+ void *pmi_code = NULL;
55641
55642 /* ignore error return of fb_get_options */
55643 fb_get_options("vesafb", &option);
55644@@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
55645 size_remap = size_total;
55646 vesafb_fix.smem_len = size_remap;
55647
55648-#ifndef __i386__
55649- screen_info.vesapm_seg = 0;
55650-#endif
55651-
55652 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55653 printk(KERN_WARNING
55654 "vesafb: cannot reserve video memory at 0x%lx\n",
55655@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55656 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55657 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55658
55659+#ifdef __i386__
55660+
55661+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55662+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
55663+ if (!pmi_code)
55664+#elif !defined(CONFIG_PAX_KERNEXEC)
55665+ if (0)
55666+#endif
55667+
55668+#endif
55669+ screen_info.vesapm_seg = 0;
55670+
55671 if (screen_info.vesapm_seg) {
55672- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55673- screen_info.vesapm_seg,screen_info.vesapm_off);
55674+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55675+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55676 }
55677
55678 if (screen_info.vesapm_seg < 0xc000)
55679@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55680
55681 if (ypan || pmi_setpal) {
55682 unsigned short *pmi_base;
55683+
55684 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55685- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55686- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55687+
55688+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55689+ pax_open_kernel();
55690+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55691+#else
55692+ pmi_code = pmi_base;
55693+#endif
55694+
55695+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55696+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55697+
55698+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55699+ pmi_start = ktva_ktla(pmi_start);
55700+ pmi_pal = ktva_ktla(pmi_pal);
55701+ pax_close_kernel();
55702+#endif
55703+
55704 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55705 if (pmi_base[3]) {
55706 printk(KERN_INFO "vesafb: pmi: ports = ");
55707@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55708 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55709 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55710
55711- if (!ypan)
55712- info->fbops->fb_pan_display = NULL;
55713+ if (!ypan) {
55714+ pax_open_kernel();
55715+ *(void **)&info->fbops->fb_pan_display = NULL;
55716+ pax_close_kernel();
55717+ }
55718
55719 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55720 err = -ENOMEM;
55721@@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55722 fb_info(info, "%s frame buffer device\n", info->fix.id);
55723 return 0;
55724 err:
55725+
55726+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55727+ module_free_exec(NULL, pmi_code);
55728+#endif
55729+
55730 if (info->screen_base)
55731 iounmap(info->screen_base);
55732 framebuffer_release(info);
55733diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
55734index 88714ae..16c2e11 100644
55735--- a/drivers/video/via/via_clock.h
55736+++ b/drivers/video/via/via_clock.h
55737@@ -56,7 +56,7 @@ struct via_clock {
55738
55739 void (*set_engine_pll_state)(u8 state);
55740 void (*set_engine_pll)(struct via_pll_config config);
55741-};
55742+} __no_const;
55743
55744
55745 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55746diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
55747index fef20db..d28b1ab 100644
55748--- a/drivers/xen/xenfs/xenstored.c
55749+++ b/drivers/xen/xenfs/xenstored.c
55750@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
55751 static int xsd_kva_open(struct inode *inode, struct file *file)
55752 {
55753 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
55754+#ifdef CONFIG_GRKERNSEC_HIDESYM
55755+ NULL);
55756+#else
55757 xen_store_interface);
55758+#endif
55759+
55760 if (!file->private_data)
55761 return -ENOMEM;
55762 return 0;
55763diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
55764index 9ff073f..05cef23 100644
55765--- a/fs/9p/vfs_addr.c
55766+++ b/fs/9p/vfs_addr.c
55767@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
55768
55769 retval = v9fs_file_write_internal(inode,
55770 v9inode->writeback_fid,
55771- (__force const char __user *)buffer,
55772+ (const char __force_user *)buffer,
55773 len, &offset, 0);
55774 if (retval > 0)
55775 retval = 0;
55776diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
55777index 4e65aa9..043dc9a 100644
55778--- a/fs/9p/vfs_inode.c
55779+++ b/fs/9p/vfs_inode.c
55780@@ -1306,7 +1306,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
55781 void
55782 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
55783 {
55784- char *s = nd_get_link(nd);
55785+ const char *s = nd_get_link(nd);
55786
55787 p9_debug(P9_DEBUG_VFS, " %s %s\n",
55788 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
55789diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
55790index 370b24c..ff0be7b 100644
55791--- a/fs/Kconfig.binfmt
55792+++ b/fs/Kconfig.binfmt
55793@@ -103,7 +103,7 @@ config HAVE_AOUT
55794
55795 config BINFMT_AOUT
55796 tristate "Kernel support for a.out and ECOFF binaries"
55797- depends on HAVE_AOUT
55798+ depends on HAVE_AOUT && BROKEN
55799 ---help---
55800 A.out (Assembler.OUTput) is a set of formats for libraries and
55801 executables used in the earliest versions of UNIX. Linux used
55802diff --git a/fs/afs/inode.c b/fs/afs/inode.c
55803index ce25d75..dc09eeb 100644
55804--- a/fs/afs/inode.c
55805+++ b/fs/afs/inode.c
55806@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55807 struct afs_vnode *vnode;
55808 struct super_block *sb;
55809 struct inode *inode;
55810- static atomic_t afs_autocell_ino;
55811+ static atomic_unchecked_t afs_autocell_ino;
55812
55813 _enter("{%x:%u},%*.*s,",
55814 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
55815@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55816 data.fid.unique = 0;
55817 data.fid.vnode = 0;
55818
55819- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
55820+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
55821 afs_iget5_autocell_test, afs_iget5_set,
55822 &data);
55823 if (!inode) {
55824diff --git a/fs/aio.c b/fs/aio.c
55825index 062a5f6..e5618e0 100644
55826--- a/fs/aio.c
55827+++ b/fs/aio.c
55828@@ -374,7 +374,7 @@ static int aio_setup_ring(struct kioctx *ctx)
55829 size += sizeof(struct io_event) * nr_events;
55830
55831 nr_pages = PFN_UP(size);
55832- if (nr_pages < 0)
55833+ if (nr_pages <= 0)
55834 return -EINVAL;
55835
55836 file = aio_private_file(ctx, nr_pages);
55837diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c
55838index 2408473..80ef38c 100644
55839--- a/fs/anon_inodes.c
55840+++ b/fs/anon_inodes.c
55841@@ -41,19 +41,8 @@ static const struct dentry_operations anon_inodefs_dentry_operations = {
55842 static struct dentry *anon_inodefs_mount(struct file_system_type *fs_type,
55843 int flags, const char *dev_name, void *data)
55844 {
55845- struct dentry *root;
55846- root = mount_pseudo(fs_type, "anon_inode:", NULL,
55847+ return mount_pseudo(fs_type, "anon_inode:", NULL,
55848 &anon_inodefs_dentry_operations, ANON_INODE_FS_MAGIC);
55849- if (!IS_ERR(root)) {
55850- struct super_block *s = root->d_sb;
55851- anon_inode_inode = alloc_anon_inode(s);
55852- if (IS_ERR(anon_inode_inode)) {
55853- dput(root);
55854- deactivate_locked_super(s);
55855- root = ERR_CAST(anon_inode_inode);
55856- }
55857- }
55858- return root;
55859 }
55860
55861 static struct file_system_type anon_inode_fs_type = {
55862@@ -175,22 +164,15 @@ EXPORT_SYMBOL_GPL(anon_inode_getfd);
55863
55864 static int __init anon_inode_init(void)
55865 {
55866- int error;
55867-
55868- error = register_filesystem(&anon_inode_fs_type);
55869- if (error)
55870- goto err_exit;
55871 anon_inode_mnt = kern_mount(&anon_inode_fs_type);
55872- if (IS_ERR(anon_inode_mnt)) {
55873- error = PTR_ERR(anon_inode_mnt);
55874- goto err_unregister_filesystem;
55875- }
55876+ if (IS_ERR(anon_inode_mnt))
55877+ panic("anon_inode_init() kernel mount failed (%ld)\n", PTR_ERR(anon_inode_mnt));
55878+
55879+ anon_inode_inode = alloc_anon_inode(anon_inode_mnt->mnt_sb);
55880+ if (IS_ERR(anon_inode_inode))
55881+ panic("anon_inode_init() inode allocation failed (%ld)\n", PTR_ERR(anon_inode_inode));
55882+
55883 return 0;
55884-
55885-err_unregister_filesystem:
55886- unregister_filesystem(&anon_inode_fs_type);
55887-err_exit:
55888- panic(KERN_ERR "anon_inode_init() failed (%d)\n", error);
55889 }
55890
55891 fs_initcall(anon_inode_init);
55892diff --git a/fs/attr.c b/fs/attr.c
55893index 5d4e59d..fd02418 100644
55894--- a/fs/attr.c
55895+++ b/fs/attr.c
55896@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
55897 unsigned long limit;
55898
55899 limit = rlimit(RLIMIT_FSIZE);
55900+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
55901 if (limit != RLIM_INFINITY && offset > limit)
55902 goto out_sig;
55903 if (offset > inode->i_sb->s_maxbytes)
55904diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
55905index 689e40d..515cac5 100644
55906--- a/fs/autofs4/waitq.c
55907+++ b/fs/autofs4/waitq.c
55908@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
55909 {
55910 unsigned long sigpipe, flags;
55911 mm_segment_t fs;
55912- const char *data = (const char *)addr;
55913+ const char __user *data = (const char __force_user *)addr;
55914 ssize_t wr = 0;
55915
55916 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
55917@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
55918 return 1;
55919 }
55920
55921+#ifdef CONFIG_GRKERNSEC_HIDESYM
55922+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
55923+#endif
55924+
55925 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55926 enum autofs_notify notify)
55927 {
55928@@ -373,7 +377,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55929
55930 /* If this is a direct mount request create a dummy name */
55931 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
55932+#ifdef CONFIG_GRKERNSEC_HIDESYM
55933+ /* this name does get written to userland via autofs4_write() */
55934+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
55935+#else
55936 qstr.len = sprintf(name, "%p", dentry);
55937+#endif
55938 else {
55939 qstr.len = autofs4_getpath(sbi, dentry, &name);
55940 if (!qstr.len) {
55941diff --git a/fs/befs/endian.h b/fs/befs/endian.h
55942index 2722387..56059b5 100644
55943--- a/fs/befs/endian.h
55944+++ b/fs/befs/endian.h
55945@@ -11,7 +11,7 @@
55946
55947 #include <asm/byteorder.h>
55948
55949-static inline u64
55950+static inline u64 __intentional_overflow(-1)
55951 fs64_to_cpu(const struct super_block *sb, fs64 n)
55952 {
55953 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55954@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
55955 return (__force fs64)cpu_to_be64(n);
55956 }
55957
55958-static inline u32
55959+static inline u32 __intentional_overflow(-1)
55960 fs32_to_cpu(const struct super_block *sb, fs32 n)
55961 {
55962 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55963@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
55964 return (__force fs32)cpu_to_be32(n);
55965 }
55966
55967-static inline u16
55968+static inline u16 __intentional_overflow(-1)
55969 fs16_to_cpu(const struct super_block *sb, fs16 n)
55970 {
55971 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55972diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
55973index ca0ba15..0fa3257 100644
55974--- a/fs/binfmt_aout.c
55975+++ b/fs/binfmt_aout.c
55976@@ -16,6 +16,7 @@
55977 #include <linux/string.h>
55978 #include <linux/fs.h>
55979 #include <linux/file.h>
55980+#include <linux/security.h>
55981 #include <linux/stat.h>
55982 #include <linux/fcntl.h>
55983 #include <linux/ptrace.h>
55984@@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
55985 #endif
55986 # define START_STACK(u) ((void __user *)u.start_stack)
55987
55988+ memset(&dump, 0, sizeof(dump));
55989+
55990 fs = get_fs();
55991 set_fs(KERNEL_DS);
55992 has_dumped = 1;
55993@@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
55994
55995 /* If the size of the dump file exceeds the rlimit, then see what would happen
55996 if we wrote the stack, but not the data area. */
55997+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
55998 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
55999 dump.u_dsize = 0;
56000
56001 /* Make sure we have enough room to write the stack and data areas. */
56002+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
56003 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
56004 dump.u_ssize = 0;
56005
56006@@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
56007 rlim = rlimit(RLIMIT_DATA);
56008 if (rlim >= RLIM_INFINITY)
56009 rlim = ~0;
56010+
56011+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
56012 if (ex.a_data + ex.a_bss > rlim)
56013 return -ENOMEM;
56014
56015@@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
56016
56017 install_exec_creds(bprm);
56018
56019+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56020+ current->mm->pax_flags = 0UL;
56021+#endif
56022+
56023+#ifdef CONFIG_PAX_PAGEEXEC
56024+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
56025+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
56026+
56027+#ifdef CONFIG_PAX_EMUTRAMP
56028+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
56029+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
56030+#endif
56031+
56032+#ifdef CONFIG_PAX_MPROTECT
56033+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
56034+ current->mm->pax_flags |= MF_PAX_MPROTECT;
56035+#endif
56036+
56037+ }
56038+#endif
56039+
56040 if (N_MAGIC(ex) == OMAGIC) {
56041 unsigned long text_addr, map_size;
56042 loff_t pos;
56043@@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
56044 }
56045
56046 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
56047- PROT_READ | PROT_WRITE | PROT_EXEC,
56048+ PROT_READ | PROT_WRITE,
56049 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
56050 fd_offset + ex.a_text);
56051 if (error != N_DATADDR(ex)) {
56052diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
56053index 571a423..eed5754 100644
56054--- a/fs/binfmt_elf.c
56055+++ b/fs/binfmt_elf.c
56056@@ -34,6 +34,7 @@
56057 #include <linux/utsname.h>
56058 #include <linux/coredump.h>
56059 #include <linux/sched.h>
56060+#include <linux/xattr.h>
56061 #include <asm/uaccess.h>
56062 #include <asm/param.h>
56063 #include <asm/page.h>
56064@@ -48,7 +49,7 @@
56065 static int load_elf_binary(struct linux_binprm *bprm);
56066 static int load_elf_library(struct file *);
56067 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
56068- int, int, unsigned long);
56069+ int, int, unsigned long) __intentional_overflow(-1);
56070
56071 /*
56072 * If we don't support core dumping, then supply a NULL so we
56073@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
56074 #define elf_core_dump NULL
56075 #endif
56076
56077+#ifdef CONFIG_PAX_MPROTECT
56078+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
56079+#endif
56080+
56081+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56082+static void elf_handle_mmap(struct file *file);
56083+#endif
56084+
56085 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
56086 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
56087 #else
56088@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
56089 .load_binary = load_elf_binary,
56090 .load_shlib = load_elf_library,
56091 .core_dump = elf_core_dump,
56092+
56093+#ifdef CONFIG_PAX_MPROTECT
56094+ .handle_mprotect= elf_handle_mprotect,
56095+#endif
56096+
56097+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56098+ .handle_mmap = elf_handle_mmap,
56099+#endif
56100+
56101 .min_coredump = ELF_EXEC_PAGESIZE,
56102 };
56103
56104@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
56105
56106 static int set_brk(unsigned long start, unsigned long end)
56107 {
56108+ unsigned long e = end;
56109+
56110 start = ELF_PAGEALIGN(start);
56111 end = ELF_PAGEALIGN(end);
56112 if (end > start) {
56113@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
56114 if (BAD_ADDR(addr))
56115 return addr;
56116 }
56117- current->mm->start_brk = current->mm->brk = end;
56118+ current->mm->start_brk = current->mm->brk = e;
56119 return 0;
56120 }
56121
56122@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56123 elf_addr_t __user *u_rand_bytes;
56124 const char *k_platform = ELF_PLATFORM;
56125 const char *k_base_platform = ELF_BASE_PLATFORM;
56126- unsigned char k_rand_bytes[16];
56127+ u32 k_rand_bytes[4];
56128 int items;
56129 elf_addr_t *elf_info;
56130 int ei_index = 0;
56131 const struct cred *cred = current_cred();
56132 struct vm_area_struct *vma;
56133+ unsigned long saved_auxv[AT_VECTOR_SIZE];
56134
56135 /*
56136 * In some cases (e.g. Hyper-Threading), we want to avoid L1
56137@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56138 * Generate 16 random bytes for userspace PRNG seeding.
56139 */
56140 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
56141- u_rand_bytes = (elf_addr_t __user *)
56142- STACK_ALLOC(p, sizeof(k_rand_bytes));
56143+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
56144+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
56145+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
56146+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
56147+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
56148+ u_rand_bytes = (elf_addr_t __user *) p;
56149 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
56150 return -EFAULT;
56151
56152@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56153 return -EFAULT;
56154 current->mm->env_end = p;
56155
56156+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
56157+
56158 /* Put the elf_info on the stack in the right place. */
56159 sp = (elf_addr_t __user *)envp + 1;
56160- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
56161+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
56162 return -EFAULT;
56163 return 0;
56164 }
56165@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
56166 an ELF header */
56167
56168 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56169- struct file *interpreter, unsigned long *interp_map_addr,
56170- unsigned long no_base)
56171+ struct file *interpreter, unsigned long no_base)
56172 {
56173 struct elf_phdr *elf_phdata;
56174 struct elf_phdr *eppnt;
56175- unsigned long load_addr = 0;
56176+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
56177 int load_addr_set = 0;
56178 unsigned long last_bss = 0, elf_bss = 0;
56179- unsigned long error = ~0UL;
56180+ unsigned long error = -EINVAL;
56181 unsigned long total_size;
56182 int retval, i, size;
56183
56184@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56185 goto out_close;
56186 }
56187
56188+#ifdef CONFIG_PAX_SEGMEXEC
56189+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
56190+ pax_task_size = SEGMEXEC_TASK_SIZE;
56191+#endif
56192+
56193 eppnt = elf_phdata;
56194 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
56195 if (eppnt->p_type == PT_LOAD) {
56196@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56197 map_addr = elf_map(interpreter, load_addr + vaddr,
56198 eppnt, elf_prot, elf_type, total_size);
56199 total_size = 0;
56200- if (!*interp_map_addr)
56201- *interp_map_addr = map_addr;
56202 error = map_addr;
56203 if (BAD_ADDR(map_addr))
56204 goto out_close;
56205@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56206 k = load_addr + eppnt->p_vaddr;
56207 if (BAD_ADDR(k) ||
56208 eppnt->p_filesz > eppnt->p_memsz ||
56209- eppnt->p_memsz > TASK_SIZE ||
56210- TASK_SIZE - eppnt->p_memsz < k) {
56211+ eppnt->p_memsz > pax_task_size ||
56212+ pax_task_size - eppnt->p_memsz < k) {
56213 error = -ENOMEM;
56214 goto out_close;
56215 }
56216@@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56217 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56218
56219 /* Map the last of the bss segment */
56220- error = vm_brk(elf_bss, last_bss - elf_bss);
56221- if (BAD_ADDR(error))
56222- goto out_close;
56223+ if (last_bss > elf_bss) {
56224+ error = vm_brk(elf_bss, last_bss - elf_bss);
56225+ if (BAD_ADDR(error))
56226+ goto out_close;
56227+ }
56228 }
56229
56230 error = load_addr;
56231@@ -538,6 +569,336 @@ out:
56232 return error;
56233 }
56234
56235+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56236+#ifdef CONFIG_PAX_SOFTMODE
56237+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56238+{
56239+ unsigned long pax_flags = 0UL;
56240+
56241+#ifdef CONFIG_PAX_PAGEEXEC
56242+ if (elf_phdata->p_flags & PF_PAGEEXEC)
56243+ pax_flags |= MF_PAX_PAGEEXEC;
56244+#endif
56245+
56246+#ifdef CONFIG_PAX_SEGMEXEC
56247+ if (elf_phdata->p_flags & PF_SEGMEXEC)
56248+ pax_flags |= MF_PAX_SEGMEXEC;
56249+#endif
56250+
56251+#ifdef CONFIG_PAX_EMUTRAMP
56252+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56253+ pax_flags |= MF_PAX_EMUTRAMP;
56254+#endif
56255+
56256+#ifdef CONFIG_PAX_MPROTECT
56257+ if (elf_phdata->p_flags & PF_MPROTECT)
56258+ pax_flags |= MF_PAX_MPROTECT;
56259+#endif
56260+
56261+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56262+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56263+ pax_flags |= MF_PAX_RANDMMAP;
56264+#endif
56265+
56266+ return pax_flags;
56267+}
56268+#endif
56269+
56270+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56271+{
56272+ unsigned long pax_flags = 0UL;
56273+
56274+#ifdef CONFIG_PAX_PAGEEXEC
56275+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56276+ pax_flags |= MF_PAX_PAGEEXEC;
56277+#endif
56278+
56279+#ifdef CONFIG_PAX_SEGMEXEC
56280+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56281+ pax_flags |= MF_PAX_SEGMEXEC;
56282+#endif
56283+
56284+#ifdef CONFIG_PAX_EMUTRAMP
56285+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56286+ pax_flags |= MF_PAX_EMUTRAMP;
56287+#endif
56288+
56289+#ifdef CONFIG_PAX_MPROTECT
56290+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56291+ pax_flags |= MF_PAX_MPROTECT;
56292+#endif
56293+
56294+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56295+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56296+ pax_flags |= MF_PAX_RANDMMAP;
56297+#endif
56298+
56299+ return pax_flags;
56300+}
56301+#endif
56302+
56303+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56304+#ifdef CONFIG_PAX_SOFTMODE
56305+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56306+{
56307+ unsigned long pax_flags = 0UL;
56308+
56309+#ifdef CONFIG_PAX_PAGEEXEC
56310+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56311+ pax_flags |= MF_PAX_PAGEEXEC;
56312+#endif
56313+
56314+#ifdef CONFIG_PAX_SEGMEXEC
56315+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56316+ pax_flags |= MF_PAX_SEGMEXEC;
56317+#endif
56318+
56319+#ifdef CONFIG_PAX_EMUTRAMP
56320+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56321+ pax_flags |= MF_PAX_EMUTRAMP;
56322+#endif
56323+
56324+#ifdef CONFIG_PAX_MPROTECT
56325+ if (pax_flags_softmode & MF_PAX_MPROTECT)
56326+ pax_flags |= MF_PAX_MPROTECT;
56327+#endif
56328+
56329+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56330+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56331+ pax_flags |= MF_PAX_RANDMMAP;
56332+#endif
56333+
56334+ return pax_flags;
56335+}
56336+#endif
56337+
56338+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56339+{
56340+ unsigned long pax_flags = 0UL;
56341+
56342+#ifdef CONFIG_PAX_PAGEEXEC
56343+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56344+ pax_flags |= MF_PAX_PAGEEXEC;
56345+#endif
56346+
56347+#ifdef CONFIG_PAX_SEGMEXEC
56348+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56349+ pax_flags |= MF_PAX_SEGMEXEC;
56350+#endif
56351+
56352+#ifdef CONFIG_PAX_EMUTRAMP
56353+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56354+ pax_flags |= MF_PAX_EMUTRAMP;
56355+#endif
56356+
56357+#ifdef CONFIG_PAX_MPROTECT
56358+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56359+ pax_flags |= MF_PAX_MPROTECT;
56360+#endif
56361+
56362+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56363+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56364+ pax_flags |= MF_PAX_RANDMMAP;
56365+#endif
56366+
56367+ return pax_flags;
56368+}
56369+#endif
56370+
56371+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56372+static unsigned long pax_parse_defaults(void)
56373+{
56374+ unsigned long pax_flags = 0UL;
56375+
56376+#ifdef CONFIG_PAX_SOFTMODE
56377+ if (pax_softmode)
56378+ return pax_flags;
56379+#endif
56380+
56381+#ifdef CONFIG_PAX_PAGEEXEC
56382+ pax_flags |= MF_PAX_PAGEEXEC;
56383+#endif
56384+
56385+#ifdef CONFIG_PAX_SEGMEXEC
56386+ pax_flags |= MF_PAX_SEGMEXEC;
56387+#endif
56388+
56389+#ifdef CONFIG_PAX_MPROTECT
56390+ pax_flags |= MF_PAX_MPROTECT;
56391+#endif
56392+
56393+#ifdef CONFIG_PAX_RANDMMAP
56394+ if (randomize_va_space)
56395+ pax_flags |= MF_PAX_RANDMMAP;
56396+#endif
56397+
56398+ return pax_flags;
56399+}
56400+
56401+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56402+{
56403+ unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56404+
56405+#ifdef CONFIG_PAX_EI_PAX
56406+
56407+#ifdef CONFIG_PAX_SOFTMODE
56408+ if (pax_softmode)
56409+ return pax_flags;
56410+#endif
56411+
56412+ pax_flags = 0UL;
56413+
56414+#ifdef CONFIG_PAX_PAGEEXEC
56415+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56416+ pax_flags |= MF_PAX_PAGEEXEC;
56417+#endif
56418+
56419+#ifdef CONFIG_PAX_SEGMEXEC
56420+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56421+ pax_flags |= MF_PAX_SEGMEXEC;
56422+#endif
56423+
56424+#ifdef CONFIG_PAX_EMUTRAMP
56425+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
56426+ pax_flags |= MF_PAX_EMUTRAMP;
56427+#endif
56428+
56429+#ifdef CONFIG_PAX_MPROTECT
56430+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
56431+ pax_flags |= MF_PAX_MPROTECT;
56432+#endif
56433+
56434+#ifdef CONFIG_PAX_ASLR
56435+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
56436+ pax_flags |= MF_PAX_RANDMMAP;
56437+#endif
56438+
56439+#endif
56440+
56441+ return pax_flags;
56442+
56443+}
56444+
56445+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
56446+{
56447+
56448+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56449+ unsigned long i;
56450+
56451+ for (i = 0UL; i < elf_ex->e_phnum; i++)
56452+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
56453+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
56454+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
56455+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
56456+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
56457+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
56458+ return PAX_PARSE_FLAGS_FALLBACK;
56459+
56460+#ifdef CONFIG_PAX_SOFTMODE
56461+ if (pax_softmode)
56462+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
56463+ else
56464+#endif
56465+
56466+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
56467+ break;
56468+ }
56469+#endif
56470+
56471+ return PAX_PARSE_FLAGS_FALLBACK;
56472+}
56473+
56474+static unsigned long pax_parse_xattr_pax(struct file * const file)
56475+{
56476+
56477+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56478+ ssize_t xattr_size, i;
56479+ unsigned char xattr_value[sizeof("pemrs") - 1];
56480+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
56481+
56482+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
56483+ if (xattr_size < 0 || xattr_size > sizeof xattr_value)
56484+ return PAX_PARSE_FLAGS_FALLBACK;
56485+
56486+ for (i = 0; i < xattr_size; i++)
56487+ switch (xattr_value[i]) {
56488+ default:
56489+ return PAX_PARSE_FLAGS_FALLBACK;
56490+
56491+#define parse_flag(option1, option2, flag) \
56492+ case option1: \
56493+ if (pax_flags_hardmode & MF_PAX_##flag) \
56494+ return PAX_PARSE_FLAGS_FALLBACK;\
56495+ pax_flags_hardmode |= MF_PAX_##flag; \
56496+ break; \
56497+ case option2: \
56498+ if (pax_flags_softmode & MF_PAX_##flag) \
56499+ return PAX_PARSE_FLAGS_FALLBACK;\
56500+ pax_flags_softmode |= MF_PAX_##flag; \
56501+ break;
56502+
56503+ parse_flag('p', 'P', PAGEEXEC);
56504+ parse_flag('e', 'E', EMUTRAMP);
56505+ parse_flag('m', 'M', MPROTECT);
56506+ parse_flag('r', 'R', RANDMMAP);
56507+ parse_flag('s', 'S', SEGMEXEC);
56508+
56509+#undef parse_flag
56510+ }
56511+
56512+ if (pax_flags_hardmode & pax_flags_softmode)
56513+ return PAX_PARSE_FLAGS_FALLBACK;
56514+
56515+#ifdef CONFIG_PAX_SOFTMODE
56516+ if (pax_softmode)
56517+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
56518+ else
56519+#endif
56520+
56521+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
56522+#else
56523+ return PAX_PARSE_FLAGS_FALLBACK;
56524+#endif
56525+
56526+}
56527+
56528+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
56529+{
56530+ unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
56531+
56532+ pax_flags = pax_parse_defaults();
56533+ ei_pax_flags = pax_parse_ei_pax(elf_ex);
56534+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
56535+ xattr_pax_flags = pax_parse_xattr_pax(file);
56536+
56537+ if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56538+ xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56539+ pt_pax_flags != xattr_pax_flags)
56540+ return -EINVAL;
56541+ if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56542+ pax_flags = xattr_pax_flags;
56543+ else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56544+ pax_flags = pt_pax_flags;
56545+ else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56546+ pax_flags = ei_pax_flags;
56547+
56548+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
56549+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56550+ if ((__supported_pte_mask & _PAGE_NX))
56551+ pax_flags &= ~MF_PAX_SEGMEXEC;
56552+ else
56553+ pax_flags &= ~MF_PAX_PAGEEXEC;
56554+ }
56555+#endif
56556+
56557+ if (0 > pax_check_flags(&pax_flags))
56558+ return -EINVAL;
56559+
56560+ current->mm->pax_flags = pax_flags;
56561+ return 0;
56562+}
56563+#endif
56564+
56565 /*
56566 * These are the functions used to load ELF style executables and shared
56567 * libraries. There is no binary dependent code anywhere else.
56568@@ -554,6 +915,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
56569 {
56570 unsigned int random_variable = 0;
56571
56572+#ifdef CONFIG_PAX_RANDUSTACK
56573+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
56574+ return stack_top - current->mm->delta_stack;
56575+#endif
56576+
56577 if ((current->flags & PF_RANDOMIZE) &&
56578 !(current->personality & ADDR_NO_RANDOMIZE)) {
56579 random_variable = get_random_int() & STACK_RND_MASK;
56580@@ -572,7 +938,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
56581 unsigned long load_addr = 0, load_bias = 0;
56582 int load_addr_set = 0;
56583 char * elf_interpreter = NULL;
56584- unsigned long error;
56585+ unsigned long error = 0;
56586 struct elf_phdr *elf_ppnt, *elf_phdata;
56587 unsigned long elf_bss, elf_brk;
56588 int retval, i;
56589@@ -582,12 +948,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
56590 unsigned long start_code, end_code, start_data, end_data;
56591 unsigned long reloc_func_desc __maybe_unused = 0;
56592 int executable_stack = EXSTACK_DEFAULT;
56593- unsigned long def_flags = 0;
56594 struct pt_regs *regs = current_pt_regs();
56595 struct {
56596 struct elfhdr elf_ex;
56597 struct elfhdr interp_elf_ex;
56598 } *loc;
56599+ unsigned long pax_task_size;
56600
56601 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
56602 if (!loc) {
56603@@ -723,11 +1089,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
56604 goto out_free_dentry;
56605
56606 /* OK, This is the point of no return */
56607- current->mm->def_flags = def_flags;
56608+ current->mm->def_flags = 0;
56609
56610 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
56611 may depend on the personality. */
56612 SET_PERSONALITY(loc->elf_ex);
56613+
56614+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56615+ current->mm->pax_flags = 0UL;
56616+#endif
56617+
56618+#ifdef CONFIG_PAX_DLRESOLVE
56619+ current->mm->call_dl_resolve = 0UL;
56620+#endif
56621+
56622+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
56623+ current->mm->call_syscall = 0UL;
56624+#endif
56625+
56626+#ifdef CONFIG_PAX_ASLR
56627+ current->mm->delta_mmap = 0UL;
56628+ current->mm->delta_stack = 0UL;
56629+#endif
56630+
56631+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56632+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
56633+ send_sig(SIGKILL, current, 0);
56634+ goto out_free_dentry;
56635+ }
56636+#endif
56637+
56638+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56639+ pax_set_initial_flags(bprm);
56640+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
56641+ if (pax_set_initial_flags_func)
56642+ (pax_set_initial_flags_func)(bprm);
56643+#endif
56644+
56645+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56646+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
56647+ current->mm->context.user_cs_limit = PAGE_SIZE;
56648+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
56649+ }
56650+#endif
56651+
56652+#ifdef CONFIG_PAX_SEGMEXEC
56653+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
56654+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
56655+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
56656+ pax_task_size = SEGMEXEC_TASK_SIZE;
56657+ current->mm->def_flags |= VM_NOHUGEPAGE;
56658+ } else
56659+#endif
56660+
56661+ pax_task_size = TASK_SIZE;
56662+
56663+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
56664+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56665+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
56666+ put_cpu();
56667+ }
56668+#endif
56669+
56670+#ifdef CONFIG_PAX_ASLR
56671+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56672+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
56673+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
56674+ }
56675+#endif
56676+
56677+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
56678+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56679+ executable_stack = EXSTACK_DISABLE_X;
56680+ current->personality &= ~READ_IMPLIES_EXEC;
56681+ } else
56682+#endif
56683+
56684 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
56685 current->personality |= READ_IMPLIES_EXEC;
56686
56687@@ -817,6 +1254,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
56688 #else
56689 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
56690 #endif
56691+
56692+#ifdef CONFIG_PAX_RANDMMAP
56693+ /* PaX: randomize base address at the default exe base if requested */
56694+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
56695+#ifdef CONFIG_SPARC64
56696+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
56697+#else
56698+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
56699+#endif
56700+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
56701+ elf_flags |= MAP_FIXED;
56702+ }
56703+#endif
56704+
56705 }
56706
56707 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
56708@@ -849,9 +1300,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
56709 * allowed task size. Note that p_filesz must always be
56710 * <= p_memsz so it is only necessary to check p_memsz.
56711 */
56712- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56713- elf_ppnt->p_memsz > TASK_SIZE ||
56714- TASK_SIZE - elf_ppnt->p_memsz < k) {
56715+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56716+ elf_ppnt->p_memsz > pax_task_size ||
56717+ pax_task_size - elf_ppnt->p_memsz < k) {
56718 /* set_brk can never work. Avoid overflows. */
56719 send_sig(SIGKILL, current, 0);
56720 retval = -EINVAL;
56721@@ -890,17 +1341,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
56722 goto out_free_dentry;
56723 }
56724 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
56725- send_sig(SIGSEGV, current, 0);
56726- retval = -EFAULT; /* Nobody gets to see this, but.. */
56727- goto out_free_dentry;
56728+ /*
56729+ * This bss-zeroing can fail if the ELF
56730+ * file specifies odd protections. So
56731+ * we don't check the return value
56732+ */
56733 }
56734
56735+#ifdef CONFIG_PAX_RANDMMAP
56736+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56737+ unsigned long start, size, flags;
56738+ vm_flags_t vm_flags;
56739+
56740+ start = ELF_PAGEALIGN(elf_brk);
56741+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
56742+ flags = MAP_FIXED | MAP_PRIVATE;
56743+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
56744+
56745+ down_write(&current->mm->mmap_sem);
56746+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
56747+ retval = -ENOMEM;
56748+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
56749+// if (current->personality & ADDR_NO_RANDOMIZE)
56750+// vm_flags |= VM_READ | VM_MAYREAD;
56751+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
56752+ retval = IS_ERR_VALUE(start) ? start : 0;
56753+ }
56754+ up_write(&current->mm->mmap_sem);
56755+ if (retval == 0)
56756+ retval = set_brk(start + size, start + size + PAGE_SIZE);
56757+ if (retval < 0) {
56758+ send_sig(SIGKILL, current, 0);
56759+ goto out_free_dentry;
56760+ }
56761+ }
56762+#endif
56763+
56764 if (elf_interpreter) {
56765- unsigned long interp_map_addr = 0;
56766-
56767 elf_entry = load_elf_interp(&loc->interp_elf_ex,
56768 interpreter,
56769- &interp_map_addr,
56770 load_bias);
56771 if (!IS_ERR((void *)elf_entry)) {
56772 /*
56773@@ -1122,7 +1601,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
56774 * Decide what to dump of a segment, part, all or none.
56775 */
56776 static unsigned long vma_dump_size(struct vm_area_struct *vma,
56777- unsigned long mm_flags)
56778+ unsigned long mm_flags, long signr)
56779 {
56780 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
56781
56782@@ -1160,7 +1639,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
56783 if (vma->vm_file == NULL)
56784 return 0;
56785
56786- if (FILTER(MAPPED_PRIVATE))
56787+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
56788 goto whole;
56789
56790 /*
56791@@ -1367,9 +1846,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
56792 {
56793 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
56794 int i = 0;
56795- do
56796+ do {
56797 i += 2;
56798- while (auxv[i - 2] != AT_NULL);
56799+ } while (auxv[i - 2] != AT_NULL);
56800 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
56801 }
56802
56803@@ -1378,7 +1857,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
56804 {
56805 mm_segment_t old_fs = get_fs();
56806 set_fs(KERNEL_DS);
56807- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
56808+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
56809 set_fs(old_fs);
56810 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
56811 }
56812@@ -2002,14 +2481,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
56813 }
56814
56815 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
56816- unsigned long mm_flags)
56817+ struct coredump_params *cprm)
56818 {
56819 struct vm_area_struct *vma;
56820 size_t size = 0;
56821
56822 for (vma = first_vma(current, gate_vma); vma != NULL;
56823 vma = next_vma(vma, gate_vma))
56824- size += vma_dump_size(vma, mm_flags);
56825+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56826 return size;
56827 }
56828
56829@@ -2100,7 +2579,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56830
56831 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
56832
56833- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
56834+ offset += elf_core_vma_data_size(gate_vma, cprm);
56835 offset += elf_core_extra_data_size();
56836 e_shoff = offset;
56837
56838@@ -2128,7 +2607,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56839 phdr.p_offset = offset;
56840 phdr.p_vaddr = vma->vm_start;
56841 phdr.p_paddr = 0;
56842- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
56843+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56844 phdr.p_memsz = vma->vm_end - vma->vm_start;
56845 offset += phdr.p_filesz;
56846 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
56847@@ -2161,7 +2640,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56848 unsigned long addr;
56849 unsigned long end;
56850
56851- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
56852+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56853
56854 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
56855 struct page *page;
56856@@ -2202,6 +2681,167 @@ out:
56857
56858 #endif /* CONFIG_ELF_CORE */
56859
56860+#ifdef CONFIG_PAX_MPROTECT
56861+/* PaX: non-PIC ELF libraries need relocations on their executable segments
56862+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
56863+ * we'll remove VM_MAYWRITE for good on RELRO segments.
56864+ *
56865+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
56866+ * basis because we want to allow the common case and not the special ones.
56867+ */
56868+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
56869+{
56870+ struct elfhdr elf_h;
56871+ struct elf_phdr elf_p;
56872+ unsigned long i;
56873+ unsigned long oldflags;
56874+ bool is_textrel_rw, is_textrel_rx, is_relro;
56875+
56876+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
56877+ return;
56878+
56879+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
56880+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
56881+
56882+#ifdef CONFIG_PAX_ELFRELOCS
56883+ /* possible TEXTREL */
56884+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
56885+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
56886+#else
56887+ is_textrel_rw = false;
56888+ is_textrel_rx = false;
56889+#endif
56890+
56891+ /* possible RELRO */
56892+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
56893+
56894+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
56895+ return;
56896+
56897+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56898+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56899+
56900+#ifdef CONFIG_PAX_ETEXECRELOCS
56901+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56902+#else
56903+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
56904+#endif
56905+
56906+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56907+ !elf_check_arch(&elf_h) ||
56908+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56909+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56910+ return;
56911+
56912+ for (i = 0UL; i < elf_h.e_phnum; i++) {
56913+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56914+ return;
56915+ switch (elf_p.p_type) {
56916+ case PT_DYNAMIC:
56917+ if (!is_textrel_rw && !is_textrel_rx)
56918+ continue;
56919+ i = 0UL;
56920+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
56921+ elf_dyn dyn;
56922+
56923+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
56924+ break;
56925+ if (dyn.d_tag == DT_NULL)
56926+ break;
56927+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
56928+ gr_log_textrel(vma);
56929+ if (is_textrel_rw)
56930+ vma->vm_flags |= VM_MAYWRITE;
56931+ else
56932+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
56933+ vma->vm_flags &= ~VM_MAYWRITE;
56934+ break;
56935+ }
56936+ i++;
56937+ }
56938+ is_textrel_rw = false;
56939+ is_textrel_rx = false;
56940+ continue;
56941+
56942+ case PT_GNU_RELRO:
56943+ if (!is_relro)
56944+ continue;
56945+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
56946+ vma->vm_flags &= ~VM_MAYWRITE;
56947+ is_relro = false;
56948+ continue;
56949+
56950+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56951+ case PT_PAX_FLAGS: {
56952+ const char *msg_mprotect = "", *msg_emutramp = "";
56953+ char *buffer_lib, *buffer_exe;
56954+
56955+ if (elf_p.p_flags & PF_NOMPROTECT)
56956+ msg_mprotect = "MPROTECT disabled";
56957+
56958+#ifdef CONFIG_PAX_EMUTRAMP
56959+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
56960+ msg_emutramp = "EMUTRAMP enabled";
56961+#endif
56962+
56963+ if (!msg_mprotect[0] && !msg_emutramp[0])
56964+ continue;
56965+
56966+ if (!printk_ratelimit())
56967+ continue;
56968+
56969+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
56970+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
56971+ if (buffer_lib && buffer_exe) {
56972+ char *path_lib, *path_exe;
56973+
56974+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
56975+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
56976+
56977+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
56978+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
56979+
56980+ }
56981+ free_page((unsigned long)buffer_exe);
56982+ free_page((unsigned long)buffer_lib);
56983+ continue;
56984+ }
56985+#endif
56986+
56987+ }
56988+ }
56989+}
56990+#endif
56991+
56992+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56993+
56994+extern int grsec_enable_log_rwxmaps;
56995+
56996+static void elf_handle_mmap(struct file *file)
56997+{
56998+ struct elfhdr elf_h;
56999+ struct elf_phdr elf_p;
57000+ unsigned long i;
57001+
57002+ if (!grsec_enable_log_rwxmaps)
57003+ return;
57004+
57005+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57006+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57007+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
57008+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57009+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57010+ return;
57011+
57012+ for (i = 0UL; i < elf_h.e_phnum; i++) {
57013+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57014+ return;
57015+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
57016+ gr_log_ptgnustack(file);
57017+ }
57018+}
57019+#endif
57020+
57021 static int __init init_elf_binfmt(void)
57022 {
57023 register_binfmt(&elf_format);
57024diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
57025index d50bbe5..af3b649 100644
57026--- a/fs/binfmt_flat.c
57027+++ b/fs/binfmt_flat.c
57028@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
57029 realdatastart = (unsigned long) -ENOMEM;
57030 printk("Unable to allocate RAM for process data, errno %d\n",
57031 (int)-realdatastart);
57032+ down_write(&current->mm->mmap_sem);
57033 vm_munmap(textpos, text_len);
57034+ up_write(&current->mm->mmap_sem);
57035 ret = realdatastart;
57036 goto err;
57037 }
57038@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
57039 }
57040 if (IS_ERR_VALUE(result)) {
57041 printk("Unable to read data+bss, errno %d\n", (int)-result);
57042+ down_write(&current->mm->mmap_sem);
57043 vm_munmap(textpos, text_len);
57044 vm_munmap(realdatastart, len);
57045+ up_write(&current->mm->mmap_sem);
57046 ret = result;
57047 goto err;
57048 }
57049@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
57050 }
57051 if (IS_ERR_VALUE(result)) {
57052 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
57053+ down_write(&current->mm->mmap_sem);
57054 vm_munmap(textpos, text_len + data_len + extra +
57055 MAX_SHARED_LIBS * sizeof(unsigned long));
57056+ up_write(&current->mm->mmap_sem);
57057 ret = result;
57058 goto err;
57059 }
57060diff --git a/fs/bio.c b/fs/bio.c
57061index 33d79a4..c3c9893 100644
57062--- a/fs/bio.c
57063+++ b/fs/bio.c
57064@@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
57065 /*
57066 * Overflow, abort
57067 */
57068- if (end < start)
57069+ if (end < start || end - start > INT_MAX - nr_pages)
57070 return ERR_PTR(-EINVAL);
57071
57072 nr_pages += end - start;
57073@@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
57074 /*
57075 * Overflow, abort
57076 */
57077- if (end < start)
57078+ if (end < start || end - start > INT_MAX - nr_pages)
57079 return ERR_PTR(-EINVAL);
57080
57081 nr_pages += end - start;
57082@@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
57083 const int read = bio_data_dir(bio) == READ;
57084 struct bio_map_data *bmd = bio->bi_private;
57085 int i;
57086- char *p = bmd->sgvecs[0].iov_base;
57087+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
57088
57089 bio_for_each_segment_all(bvec, bio, i) {
57090 char *addr = page_address(bvec->bv_page);
57091diff --git a/fs/block_dev.c b/fs/block_dev.c
57092index 1e86823..8e34695 100644
57093--- a/fs/block_dev.c
57094+++ b/fs/block_dev.c
57095@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
57096 else if (bdev->bd_contains == bdev)
57097 return true; /* is a whole device which isn't held */
57098
57099- else if (whole->bd_holder == bd_may_claim)
57100+ else if (whole->bd_holder == (void *)bd_may_claim)
57101 return true; /* is a partition of a device that is being partitioned */
57102 else if (whole->bd_holder != NULL)
57103 return false; /* is a partition of a held device */
57104diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
57105index 3de01b4..6547c39 100644
57106--- a/fs/btrfs/ctree.c
57107+++ b/fs/btrfs/ctree.c
57108@@ -1217,9 +1217,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
57109 free_extent_buffer(buf);
57110 add_root_to_dirty_list(root);
57111 } else {
57112- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
57113- parent_start = parent->start;
57114- else
57115+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
57116+ if (parent)
57117+ parent_start = parent->start;
57118+ else
57119+ parent_start = 0;
57120+ } else
57121 parent_start = 0;
57122
57123 WARN_ON(trans->transid != btrfs_header_generation(parent));
57124diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
57125index 8d292fb..bc205c2 100644
57126--- a/fs/btrfs/delayed-inode.c
57127+++ b/fs/btrfs/delayed-inode.c
57128@@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
57129
57130 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
57131 {
57132- int seq = atomic_inc_return(&delayed_root->items_seq);
57133+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
57134 if ((atomic_dec_return(&delayed_root->items) <
57135 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
57136 waitqueue_active(&delayed_root->wait))
57137@@ -1379,7 +1379,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
57138 static int refs_newer(struct btrfs_delayed_root *delayed_root,
57139 int seq, int count)
57140 {
57141- int val = atomic_read(&delayed_root->items_seq);
57142+ int val = atomic_read_unchecked(&delayed_root->items_seq);
57143
57144 if (val < seq || val >= seq + count)
57145 return 1;
57146@@ -1396,7 +1396,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
57147 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
57148 return;
57149
57150- seq = atomic_read(&delayed_root->items_seq);
57151+ seq = atomic_read_unchecked(&delayed_root->items_seq);
57152
57153 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
57154 int ret;
57155diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
57156index a4b38f9..f86a509 100644
57157--- a/fs/btrfs/delayed-inode.h
57158+++ b/fs/btrfs/delayed-inode.h
57159@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
57160 */
57161 struct list_head prepare_list;
57162 atomic_t items; /* for delayed items */
57163- atomic_t items_seq; /* for delayed items */
57164+ atomic_unchecked_t items_seq; /* for delayed items */
57165 int nodes; /* for delayed nodes */
57166 wait_queue_head_t wait;
57167 };
57168@@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
57169 struct btrfs_delayed_root *delayed_root)
57170 {
57171 atomic_set(&delayed_root->items, 0);
57172- atomic_set(&delayed_root->items_seq, 0);
57173+ atomic_set_unchecked(&delayed_root->items_seq, 0);
57174 delayed_root->nodes = 0;
57175 spin_lock_init(&delayed_root->lock);
57176 init_waitqueue_head(&delayed_root->wait);
57177diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
57178index 9f831bb..14afde5 100644
57179--- a/fs/btrfs/ioctl.c
57180+++ b/fs/btrfs/ioctl.c
57181@@ -3457,9 +3457,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57182 for (i = 0; i < num_types; i++) {
57183 struct btrfs_space_info *tmp;
57184
57185+ /* Don't copy in more than we allocated */
57186 if (!slot_count)
57187 break;
57188
57189+ slot_count--;
57190+
57191 info = NULL;
57192 rcu_read_lock();
57193 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
57194@@ -3481,10 +3484,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57195 memcpy(dest, &space, sizeof(space));
57196 dest++;
57197 space_args.total_spaces++;
57198- slot_count--;
57199 }
57200- if (!slot_count)
57201- break;
57202 }
57203 up_read(&info->groups_sem);
57204 }
57205diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
57206index d71a11d..384e2c4 100644
57207--- a/fs/btrfs/super.c
57208+++ b/fs/btrfs/super.c
57209@@ -265,7 +265,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
57210 function, line, errstr);
57211 return;
57212 }
57213- ACCESS_ONCE(trans->transaction->aborted) = errno;
57214+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57215 /* Wake up anybody who may be waiting on this transaction */
57216 wake_up(&root->fs_info->transaction_wait);
57217 wake_up(&root->fs_info->transaction_blocked_wait);
57218diff --git a/fs/buffer.c b/fs/buffer.c
57219index aeeea65..7651d590 100644
57220--- a/fs/buffer.c
57221+++ b/fs/buffer.c
57222@@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57223 bh_cachep = kmem_cache_create("buffer_head",
57224 sizeof(struct buffer_head), 0,
57225 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57226- SLAB_MEM_SPREAD),
57227+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57228 NULL);
57229
57230 /*
57231diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57232index 622f469..e8d2d55 100644
57233--- a/fs/cachefiles/bind.c
57234+++ b/fs/cachefiles/bind.c
57235@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57236 args);
57237
57238 /* start by checking things over */
57239- ASSERT(cache->fstop_percent >= 0 &&
57240- cache->fstop_percent < cache->fcull_percent &&
57241+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
57242 cache->fcull_percent < cache->frun_percent &&
57243 cache->frun_percent < 100);
57244
57245- ASSERT(cache->bstop_percent >= 0 &&
57246- cache->bstop_percent < cache->bcull_percent &&
57247+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
57248 cache->bcull_percent < cache->brun_percent &&
57249 cache->brun_percent < 100);
57250
57251diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57252index 0a1467b..6a53245 100644
57253--- a/fs/cachefiles/daemon.c
57254+++ b/fs/cachefiles/daemon.c
57255@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57256 if (n > buflen)
57257 return -EMSGSIZE;
57258
57259- if (copy_to_user(_buffer, buffer, n) != 0)
57260+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57261 return -EFAULT;
57262
57263 return n;
57264@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57265 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57266 return -EIO;
57267
57268- if (datalen < 0 || datalen > PAGE_SIZE - 1)
57269+ if (datalen > PAGE_SIZE - 1)
57270 return -EOPNOTSUPP;
57271
57272 /* drag the command string into the kernel so we can parse it */
57273@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57274 if (args[0] != '%' || args[1] != '\0')
57275 return -EINVAL;
57276
57277- if (fstop < 0 || fstop >= cache->fcull_percent)
57278+ if (fstop >= cache->fcull_percent)
57279 return cachefiles_daemon_range_error(cache, args);
57280
57281 cache->fstop_percent = fstop;
57282@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57283 if (args[0] != '%' || args[1] != '\0')
57284 return -EINVAL;
57285
57286- if (bstop < 0 || bstop >= cache->bcull_percent)
57287+ if (bstop >= cache->bcull_percent)
57288 return cachefiles_daemon_range_error(cache, args);
57289
57290 cache->bstop_percent = bstop;
57291diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57292index 5349473..d6c0b93 100644
57293--- a/fs/cachefiles/internal.h
57294+++ b/fs/cachefiles/internal.h
57295@@ -59,7 +59,7 @@ struct cachefiles_cache {
57296 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57297 struct rb_root active_nodes; /* active nodes (can't be culled) */
57298 rwlock_t active_lock; /* lock for active_nodes */
57299- atomic_t gravecounter; /* graveyard uniquifier */
57300+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57301 unsigned frun_percent; /* when to stop culling (% files) */
57302 unsigned fcull_percent; /* when to start culling (% files) */
57303 unsigned fstop_percent; /* when to stop allocating (% files) */
57304@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57305 * proc.c
57306 */
57307 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57308-extern atomic_t cachefiles_lookup_histogram[HZ];
57309-extern atomic_t cachefiles_mkdir_histogram[HZ];
57310-extern atomic_t cachefiles_create_histogram[HZ];
57311+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57312+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57313+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57314
57315 extern int __init cachefiles_proc_init(void);
57316 extern void cachefiles_proc_cleanup(void);
57317 static inline
57318-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57319+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57320 {
57321 unsigned long jif = jiffies - start_jif;
57322 if (jif >= HZ)
57323 jif = HZ - 1;
57324- atomic_inc(&histogram[jif]);
57325+ atomic_inc_unchecked(&histogram[jif]);
57326 }
57327
57328 #else
57329diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57330index ca65f39..48921e3 100644
57331--- a/fs/cachefiles/namei.c
57332+++ b/fs/cachefiles/namei.c
57333@@ -317,7 +317,7 @@ try_again:
57334 /* first step is to make up a grave dentry in the graveyard */
57335 sprintf(nbuffer, "%08x%08x",
57336 (uint32_t) get_seconds(),
57337- (uint32_t) atomic_inc_return(&cache->gravecounter));
57338+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57339
57340 /* do the multiway lock magic */
57341 trap = lock_rename(cache->graveyard, dir);
57342diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57343index eccd339..4c1d995 100644
57344--- a/fs/cachefiles/proc.c
57345+++ b/fs/cachefiles/proc.c
57346@@ -14,9 +14,9 @@
57347 #include <linux/seq_file.h>
57348 #include "internal.h"
57349
57350-atomic_t cachefiles_lookup_histogram[HZ];
57351-atomic_t cachefiles_mkdir_histogram[HZ];
57352-atomic_t cachefiles_create_histogram[HZ];
57353+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57354+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57355+atomic_unchecked_t cachefiles_create_histogram[HZ];
57356
57357 /*
57358 * display the latency histogram
57359@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57360 return 0;
57361 default:
57362 index = (unsigned long) v - 3;
57363- x = atomic_read(&cachefiles_lookup_histogram[index]);
57364- y = atomic_read(&cachefiles_mkdir_histogram[index]);
57365- z = atomic_read(&cachefiles_create_histogram[index]);
57366+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57367+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57368+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57369 if (x == 0 && y == 0 && z == 0)
57370 return 0;
57371
57372diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57373index ebaff36..7e3ea26 100644
57374--- a/fs/cachefiles/rdwr.c
57375+++ b/fs/cachefiles/rdwr.c
57376@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57377 old_fs = get_fs();
57378 set_fs(KERNEL_DS);
57379 ret = file->f_op->write(
57380- file, (const void __user *) data, len, &pos);
57381+ file, (const void __force_user *) data, len, &pos);
57382 set_fs(old_fs);
57383 kunmap(page);
57384 file_end_write(file);
57385diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57386index 2a0bcae..34ec24e 100644
57387--- a/fs/ceph/dir.c
57388+++ b/fs/ceph/dir.c
57389@@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57390 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57391 struct ceph_mds_client *mdsc = fsc->mdsc;
57392 unsigned frag = fpos_frag(ctx->pos);
57393- int off = fpos_off(ctx->pos);
57394+ unsigned int off = fpos_off(ctx->pos);
57395 int err;
57396 u32 ftype;
57397 struct ceph_mds_reply_info_parsed *rinfo;
57398diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57399index 6a0951e..03fac6d 100644
57400--- a/fs/ceph/super.c
57401+++ b/fs/ceph/super.c
57402@@ -870,7 +870,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57403 /*
57404 * construct our own bdi so we can control readahead, etc.
57405 */
57406-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57407+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57408
57409 static int ceph_register_bdi(struct super_block *sb,
57410 struct ceph_fs_client *fsc)
57411@@ -887,7 +887,7 @@ static int ceph_register_bdi(struct super_block *sb,
57412 default_backing_dev_info.ra_pages;
57413
57414 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
57415- atomic_long_inc_return(&bdi_seq));
57416+ atomic_long_inc_return_unchecked(&bdi_seq));
57417 if (!err)
57418 sb->s_bdi = &fsc->backing_dev_info;
57419 return err;
57420diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
57421index f3ac415..3d2420c 100644
57422--- a/fs/cifs/cifs_debug.c
57423+++ b/fs/cifs/cifs_debug.c
57424@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57425
57426 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
57427 #ifdef CONFIG_CIFS_STATS2
57428- atomic_set(&totBufAllocCount, 0);
57429- atomic_set(&totSmBufAllocCount, 0);
57430+ atomic_set_unchecked(&totBufAllocCount, 0);
57431+ atomic_set_unchecked(&totSmBufAllocCount, 0);
57432 #endif /* CONFIG_CIFS_STATS2 */
57433 spin_lock(&cifs_tcp_ses_lock);
57434 list_for_each(tmp1, &cifs_tcp_ses_list) {
57435@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57436 tcon = list_entry(tmp3,
57437 struct cifs_tcon,
57438 tcon_list);
57439- atomic_set(&tcon->num_smbs_sent, 0);
57440+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
57441 if (server->ops->clear_stats)
57442 server->ops->clear_stats(tcon);
57443 }
57444@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57445 smBufAllocCount.counter, cifs_min_small);
57446 #ifdef CONFIG_CIFS_STATS2
57447 seq_printf(m, "Total Large %d Small %d Allocations\n",
57448- atomic_read(&totBufAllocCount),
57449- atomic_read(&totSmBufAllocCount));
57450+ atomic_read_unchecked(&totBufAllocCount),
57451+ atomic_read_unchecked(&totSmBufAllocCount));
57452 #endif /* CONFIG_CIFS_STATS2 */
57453
57454 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
57455@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57456 if (tcon->need_reconnect)
57457 seq_puts(m, "\tDISCONNECTED ");
57458 seq_printf(m, "\nSMBs: %d",
57459- atomic_read(&tcon->num_smbs_sent));
57460+ atomic_read_unchecked(&tcon->num_smbs_sent));
57461 if (server->ops->print_stats)
57462 server->ops->print_stats(m, tcon);
57463 }
57464diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
57465index 849f613..eae6dec 100644
57466--- a/fs/cifs/cifsfs.c
57467+++ b/fs/cifs/cifsfs.c
57468@@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
57469 */
57470 cifs_req_cachep = kmem_cache_create("cifs_request",
57471 CIFSMaxBufSize + max_hdr_size, 0,
57472- SLAB_HWCACHE_ALIGN, NULL);
57473+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
57474 if (cifs_req_cachep == NULL)
57475 return -ENOMEM;
57476
57477@@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
57478 efficient to alloc 1 per page off the slab compared to 17K (5page)
57479 alloc of large cifs buffers even when page debugging is on */
57480 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
57481- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
57482+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
57483 NULL);
57484 if (cifs_sm_req_cachep == NULL) {
57485 mempool_destroy(cifs_req_poolp);
57486@@ -1168,8 +1168,8 @@ init_cifs(void)
57487 atomic_set(&bufAllocCount, 0);
57488 atomic_set(&smBufAllocCount, 0);
57489 #ifdef CONFIG_CIFS_STATS2
57490- atomic_set(&totBufAllocCount, 0);
57491- atomic_set(&totSmBufAllocCount, 0);
57492+ atomic_set_unchecked(&totBufAllocCount, 0);
57493+ atomic_set_unchecked(&totSmBufAllocCount, 0);
57494 #endif /* CONFIG_CIFS_STATS2 */
57495
57496 atomic_set(&midCount, 0);
57497diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
57498index 579c6d5..95b6d03353 100644
57499--- a/fs/cifs/cifsglob.h
57500+++ b/fs/cifs/cifsglob.h
57501@@ -797,35 +797,35 @@ struct cifs_tcon {
57502 __u16 Flags; /* optional support bits */
57503 enum statusEnum tidStatus;
57504 #ifdef CONFIG_CIFS_STATS
57505- atomic_t num_smbs_sent;
57506+ atomic_unchecked_t num_smbs_sent;
57507 union {
57508 struct {
57509- atomic_t num_writes;
57510- atomic_t num_reads;
57511- atomic_t num_flushes;
57512- atomic_t num_oplock_brks;
57513- atomic_t num_opens;
57514- atomic_t num_closes;
57515- atomic_t num_deletes;
57516- atomic_t num_mkdirs;
57517- atomic_t num_posixopens;
57518- atomic_t num_posixmkdirs;
57519- atomic_t num_rmdirs;
57520- atomic_t num_renames;
57521- atomic_t num_t2renames;
57522- atomic_t num_ffirst;
57523- atomic_t num_fnext;
57524- atomic_t num_fclose;
57525- atomic_t num_hardlinks;
57526- atomic_t num_symlinks;
57527- atomic_t num_locks;
57528- atomic_t num_acl_get;
57529- atomic_t num_acl_set;
57530+ atomic_unchecked_t num_writes;
57531+ atomic_unchecked_t num_reads;
57532+ atomic_unchecked_t num_flushes;
57533+ atomic_unchecked_t num_oplock_brks;
57534+ atomic_unchecked_t num_opens;
57535+ atomic_unchecked_t num_closes;
57536+ atomic_unchecked_t num_deletes;
57537+ atomic_unchecked_t num_mkdirs;
57538+ atomic_unchecked_t num_posixopens;
57539+ atomic_unchecked_t num_posixmkdirs;
57540+ atomic_unchecked_t num_rmdirs;
57541+ atomic_unchecked_t num_renames;
57542+ atomic_unchecked_t num_t2renames;
57543+ atomic_unchecked_t num_ffirst;
57544+ atomic_unchecked_t num_fnext;
57545+ atomic_unchecked_t num_fclose;
57546+ atomic_unchecked_t num_hardlinks;
57547+ atomic_unchecked_t num_symlinks;
57548+ atomic_unchecked_t num_locks;
57549+ atomic_unchecked_t num_acl_get;
57550+ atomic_unchecked_t num_acl_set;
57551 } cifs_stats;
57552 #ifdef CONFIG_CIFS_SMB2
57553 struct {
57554- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57555- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57556+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57557+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57558 } smb2_stats;
57559 #endif /* CONFIG_CIFS_SMB2 */
57560 } stats;
57561@@ -1155,7 +1155,7 @@ convert_delimiter(char *path, char delim)
57562 }
57563
57564 #ifdef CONFIG_CIFS_STATS
57565-#define cifs_stats_inc atomic_inc
57566+#define cifs_stats_inc atomic_inc_unchecked
57567
57568 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
57569 unsigned int bytes)
57570@@ -1521,8 +1521,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
57571 /* Various Debug counters */
57572 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
57573 #ifdef CONFIG_CIFS_STATS2
57574-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
57575-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
57576+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
57577+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
57578 #endif
57579 GLOBAL_EXTERN atomic_t smBufAllocCount;
57580 GLOBAL_EXTERN atomic_t midCount;
57581diff --git a/fs/cifs/file.c b/fs/cifs/file.c
57582index a1c9ead..63e4c62 100644
57583--- a/fs/cifs/file.c
57584+++ b/fs/cifs/file.c
57585@@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
57586 index = mapping->writeback_index; /* Start from prev offset */
57587 end = -1;
57588 } else {
57589- index = wbc->range_start >> PAGE_CACHE_SHIFT;
57590- end = wbc->range_end >> PAGE_CACHE_SHIFT;
57591- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
57592+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
57593 range_whole = true;
57594+ index = 0;
57595+ end = ULONG_MAX;
57596+ } else {
57597+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
57598+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
57599+ }
57600 scanned = true;
57601 }
57602 retry:
57603diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
57604index 2f9f379..43f8025 100644
57605--- a/fs/cifs/misc.c
57606+++ b/fs/cifs/misc.c
57607@@ -170,7 +170,7 @@ cifs_buf_get(void)
57608 memset(ret_buf, 0, buf_size + 3);
57609 atomic_inc(&bufAllocCount);
57610 #ifdef CONFIG_CIFS_STATS2
57611- atomic_inc(&totBufAllocCount);
57612+ atomic_inc_unchecked(&totBufAllocCount);
57613 #endif /* CONFIG_CIFS_STATS2 */
57614 }
57615
57616@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
57617 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
57618 atomic_inc(&smBufAllocCount);
57619 #ifdef CONFIG_CIFS_STATS2
57620- atomic_inc(&totSmBufAllocCount);
57621+ atomic_inc_unchecked(&totSmBufAllocCount);
57622 #endif /* CONFIG_CIFS_STATS2 */
57623
57624 }
57625diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
57626index ffc9ef9..b3c992b 100644
57627--- a/fs/cifs/smb1ops.c
57628+++ b/fs/cifs/smb1ops.c
57629@@ -609,27 +609,27 @@ static void
57630 cifs_clear_stats(struct cifs_tcon *tcon)
57631 {
57632 #ifdef CONFIG_CIFS_STATS
57633- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
57634- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
57635- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
57636- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57637- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
57638- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
57639- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57640- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
57641- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
57642- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
57643- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
57644- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
57645- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
57646- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
57647- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
57648- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
57649- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
57650- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
57651- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
57652- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
57653- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
57654+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
57655+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
57656+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
57657+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57658+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
57659+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
57660+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57661+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
57662+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
57663+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
57664+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
57665+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
57666+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
57667+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
57668+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
57669+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
57670+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
57671+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
57672+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
57673+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
57674+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
57675 #endif
57676 }
57677
57678@@ -638,36 +638,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57679 {
57680 #ifdef CONFIG_CIFS_STATS
57681 seq_printf(m, " Oplocks breaks: %d",
57682- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
57683+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
57684 seq_printf(m, "\nReads: %d Bytes: %llu",
57685- atomic_read(&tcon->stats.cifs_stats.num_reads),
57686+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
57687 (long long)(tcon->bytes_read));
57688 seq_printf(m, "\nWrites: %d Bytes: %llu",
57689- atomic_read(&tcon->stats.cifs_stats.num_writes),
57690+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
57691 (long long)(tcon->bytes_written));
57692 seq_printf(m, "\nFlushes: %d",
57693- atomic_read(&tcon->stats.cifs_stats.num_flushes));
57694+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
57695 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
57696- atomic_read(&tcon->stats.cifs_stats.num_locks),
57697- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
57698- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
57699+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
57700+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
57701+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
57702 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
57703- atomic_read(&tcon->stats.cifs_stats.num_opens),
57704- atomic_read(&tcon->stats.cifs_stats.num_closes),
57705- atomic_read(&tcon->stats.cifs_stats.num_deletes));
57706+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
57707+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
57708+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
57709 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
57710- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
57711- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
57712+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
57713+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
57714 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
57715- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
57716- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
57717+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
57718+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
57719 seq_printf(m, "\nRenames: %d T2 Renames %d",
57720- atomic_read(&tcon->stats.cifs_stats.num_renames),
57721- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
57722+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
57723+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
57724 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
57725- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
57726- atomic_read(&tcon->stats.cifs_stats.num_fnext),
57727- atomic_read(&tcon->stats.cifs_stats.num_fclose));
57728+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
57729+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
57730+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
57731 #endif
57732 }
57733
57734diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
57735index 192f51a..539307e 100644
57736--- a/fs/cifs/smb2ops.c
57737+++ b/fs/cifs/smb2ops.c
57738@@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
57739 #ifdef CONFIG_CIFS_STATS
57740 int i;
57741 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
57742- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57743- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57744+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57745+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57746 }
57747 #endif
57748 }
57749@@ -405,65 +405,65 @@ static void
57750 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57751 {
57752 #ifdef CONFIG_CIFS_STATS
57753- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57754- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57755+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57756+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57757 seq_printf(m, "\nNegotiates: %d sent %d failed",
57758- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
57759- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
57760+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
57761+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
57762 seq_printf(m, "\nSessionSetups: %d sent %d failed",
57763- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
57764- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
57765+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
57766+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
57767 seq_printf(m, "\nLogoffs: %d sent %d failed",
57768- atomic_read(&sent[SMB2_LOGOFF_HE]),
57769- atomic_read(&failed[SMB2_LOGOFF_HE]));
57770+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
57771+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
57772 seq_printf(m, "\nTreeConnects: %d sent %d failed",
57773- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
57774- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
57775+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
57776+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
57777 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
57778- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
57779- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
57780+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
57781+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
57782 seq_printf(m, "\nCreates: %d sent %d failed",
57783- atomic_read(&sent[SMB2_CREATE_HE]),
57784- atomic_read(&failed[SMB2_CREATE_HE]));
57785+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
57786+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
57787 seq_printf(m, "\nCloses: %d sent %d failed",
57788- atomic_read(&sent[SMB2_CLOSE_HE]),
57789- atomic_read(&failed[SMB2_CLOSE_HE]));
57790+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
57791+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
57792 seq_printf(m, "\nFlushes: %d sent %d failed",
57793- atomic_read(&sent[SMB2_FLUSH_HE]),
57794- atomic_read(&failed[SMB2_FLUSH_HE]));
57795+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
57796+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
57797 seq_printf(m, "\nReads: %d sent %d failed",
57798- atomic_read(&sent[SMB2_READ_HE]),
57799- atomic_read(&failed[SMB2_READ_HE]));
57800+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
57801+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
57802 seq_printf(m, "\nWrites: %d sent %d failed",
57803- atomic_read(&sent[SMB2_WRITE_HE]),
57804- atomic_read(&failed[SMB2_WRITE_HE]));
57805+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
57806+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
57807 seq_printf(m, "\nLocks: %d sent %d failed",
57808- atomic_read(&sent[SMB2_LOCK_HE]),
57809- atomic_read(&failed[SMB2_LOCK_HE]));
57810+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
57811+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
57812 seq_printf(m, "\nIOCTLs: %d sent %d failed",
57813- atomic_read(&sent[SMB2_IOCTL_HE]),
57814- atomic_read(&failed[SMB2_IOCTL_HE]));
57815+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
57816+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
57817 seq_printf(m, "\nCancels: %d sent %d failed",
57818- atomic_read(&sent[SMB2_CANCEL_HE]),
57819- atomic_read(&failed[SMB2_CANCEL_HE]));
57820+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
57821+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
57822 seq_printf(m, "\nEchos: %d sent %d failed",
57823- atomic_read(&sent[SMB2_ECHO_HE]),
57824- atomic_read(&failed[SMB2_ECHO_HE]));
57825+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
57826+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
57827 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
57828- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
57829- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
57830+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
57831+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
57832 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
57833- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
57834- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
57835+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
57836+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
57837 seq_printf(m, "\nQueryInfos: %d sent %d failed",
57838- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
57839- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
57840+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
57841+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
57842 seq_printf(m, "\nSetInfos: %d sent %d failed",
57843- atomic_read(&sent[SMB2_SET_INFO_HE]),
57844- atomic_read(&failed[SMB2_SET_INFO_HE]));
57845+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
57846+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
57847 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
57848- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
57849- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
57850+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
57851+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
57852 #endif
57853 }
57854
57855diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
57856index 787e171..31dcd0a 100644
57857--- a/fs/cifs/smb2pdu.c
57858+++ b/fs/cifs/smb2pdu.c
57859@@ -2093,8 +2093,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
57860 default:
57861 cifs_dbg(VFS, "info level %u isn't supported\n",
57862 srch_inf->info_level);
57863- rc = -EINVAL;
57864- goto qdir_exit;
57865+ return -EINVAL;
57866 }
57867
57868 req->FileIndex = cpu_to_le32(index);
57869diff --git a/fs/coda/cache.c b/fs/coda/cache.c
57870index 1da168c..8bc7ff6 100644
57871--- a/fs/coda/cache.c
57872+++ b/fs/coda/cache.c
57873@@ -24,7 +24,7 @@
57874 #include "coda_linux.h"
57875 #include "coda_cache.h"
57876
57877-static atomic_t permission_epoch = ATOMIC_INIT(0);
57878+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
57879
57880 /* replace or extend an acl cache hit */
57881 void coda_cache_enter(struct inode *inode, int mask)
57882@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
57883 struct coda_inode_info *cii = ITOC(inode);
57884
57885 spin_lock(&cii->c_lock);
57886- cii->c_cached_epoch = atomic_read(&permission_epoch);
57887+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
57888 if (!uid_eq(cii->c_uid, current_fsuid())) {
57889 cii->c_uid = current_fsuid();
57890 cii->c_cached_perm = mask;
57891@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
57892 {
57893 struct coda_inode_info *cii = ITOC(inode);
57894 spin_lock(&cii->c_lock);
57895- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
57896+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
57897 spin_unlock(&cii->c_lock);
57898 }
57899
57900 /* remove all acl caches */
57901 void coda_cache_clear_all(struct super_block *sb)
57902 {
57903- atomic_inc(&permission_epoch);
57904+ atomic_inc_unchecked(&permission_epoch);
57905 }
57906
57907
57908@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
57909 spin_lock(&cii->c_lock);
57910 hit = (mask & cii->c_cached_perm) == mask &&
57911 uid_eq(cii->c_uid, current_fsuid()) &&
57912- cii->c_cached_epoch == atomic_read(&permission_epoch);
57913+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
57914 spin_unlock(&cii->c_lock);
57915
57916 return hit;
57917diff --git a/fs/compat.c b/fs/compat.c
57918index 6af20de..fec3fbb 100644
57919--- a/fs/compat.c
57920+++ b/fs/compat.c
57921@@ -54,7 +54,7 @@
57922 #include <asm/ioctls.h>
57923 #include "internal.h"
57924
57925-int compat_log = 1;
57926+int compat_log = 0;
57927
57928 int compat_printk(const char *fmt, ...)
57929 {
57930@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
57931
57932 set_fs(KERNEL_DS);
57933 /* The __user pointer cast is valid because of the set_fs() */
57934- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
57935+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
57936 set_fs(oldfs);
57937 /* truncating is ok because it's a user address */
57938 if (!ret)
57939@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
57940 goto out;
57941
57942 ret = -EINVAL;
57943- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
57944+ if (nr_segs > UIO_MAXIOV)
57945 goto out;
57946 if (nr_segs > fast_segs) {
57947 ret = -ENOMEM;
57948@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
57949 struct compat_readdir_callback {
57950 struct dir_context ctx;
57951 struct compat_old_linux_dirent __user *dirent;
57952+ struct file * file;
57953 int result;
57954 };
57955
57956@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
57957 buf->result = -EOVERFLOW;
57958 return -EOVERFLOW;
57959 }
57960+
57961+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57962+ return 0;
57963+
57964 buf->result++;
57965 dirent = buf->dirent;
57966 if (!access_ok(VERIFY_WRITE, dirent,
57967@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
57968 if (!f.file)
57969 return -EBADF;
57970
57971+ buf.file = f.file;
57972 error = iterate_dir(f.file, &buf.ctx);
57973 if (buf.result)
57974 error = buf.result;
57975@@ -901,6 +907,7 @@ struct compat_getdents_callback {
57976 struct dir_context ctx;
57977 struct compat_linux_dirent __user *current_dir;
57978 struct compat_linux_dirent __user *previous;
57979+ struct file * file;
57980 int count;
57981 int error;
57982 };
57983@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
57984 buf->error = -EOVERFLOW;
57985 return -EOVERFLOW;
57986 }
57987+
57988+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57989+ return 0;
57990+
57991 dirent = buf->previous;
57992 if (dirent) {
57993 if (__put_user(offset, &dirent->d_off))
57994@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
57995 if (!f.file)
57996 return -EBADF;
57997
57998+ buf.file = f.file;
57999 error = iterate_dir(f.file, &buf.ctx);
58000 if (error >= 0)
58001 error = buf.error;
58002@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
58003 struct dir_context ctx;
58004 struct linux_dirent64 __user *current_dir;
58005 struct linux_dirent64 __user *previous;
58006+ struct file * file;
58007 int count;
58008 int error;
58009 };
58010@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
58011 buf->error = -EINVAL; /* only used if we fail.. */
58012 if (reclen > buf->count)
58013 return -EINVAL;
58014+
58015+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58016+ return 0;
58017+
58018 dirent = buf->previous;
58019
58020 if (dirent) {
58021@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
58022 if (!f.file)
58023 return -EBADF;
58024
58025+ buf.file = f.file;
58026 error = iterate_dir(f.file, &buf.ctx);
58027 if (error >= 0)
58028 error = buf.error;
58029diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
58030index a81147e..20bf2b5 100644
58031--- a/fs/compat_binfmt_elf.c
58032+++ b/fs/compat_binfmt_elf.c
58033@@ -30,11 +30,13 @@
58034 #undef elf_phdr
58035 #undef elf_shdr
58036 #undef elf_note
58037+#undef elf_dyn
58038 #undef elf_addr_t
58039 #define elfhdr elf32_hdr
58040 #define elf_phdr elf32_phdr
58041 #define elf_shdr elf32_shdr
58042 #define elf_note elf32_note
58043+#define elf_dyn Elf32_Dyn
58044 #define elf_addr_t Elf32_Addr
58045
58046 /*
58047diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
58048index dc52e13..ec61057 100644
58049--- a/fs/compat_ioctl.c
58050+++ b/fs/compat_ioctl.c
58051@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
58052 return -EFAULT;
58053 if (__get_user(udata, &ss32->iomem_base))
58054 return -EFAULT;
58055- ss.iomem_base = compat_ptr(udata);
58056+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
58057 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
58058 __get_user(ss.port_high, &ss32->port_high))
58059 return -EFAULT;
58060@@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
58061 for (i = 0; i < nmsgs; i++) {
58062 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
58063 return -EFAULT;
58064- if (get_user(datap, &umsgs[i].buf) ||
58065- put_user(compat_ptr(datap), &tmsgs[i].buf))
58066+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
58067+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
58068 return -EFAULT;
58069 }
58070 return sys_ioctl(fd, cmd, (unsigned long)tdata);
58071@@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
58072 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
58073 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
58074 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
58075- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
58076+ copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
58077 return -EFAULT;
58078
58079 return ioctl_preallocate(file, p);
58080@@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
58081 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
58082 {
58083 unsigned int a, b;
58084- a = *(unsigned int *)p;
58085- b = *(unsigned int *)q;
58086+ a = *(const unsigned int *)p;
58087+ b = *(const unsigned int *)q;
58088 if (a > b)
58089 return 1;
58090 if (a < b)
58091diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
58092index e081acb..911df21 100644
58093--- a/fs/configfs/dir.c
58094+++ b/fs/configfs/dir.c
58095@@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58096 }
58097 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
58098 struct configfs_dirent *next;
58099- const char *name;
58100+ const unsigned char * name;
58101+ char d_name[sizeof(next->s_dentry->d_iname)];
58102 int len;
58103 struct inode *inode = NULL;
58104
58105@@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58106 continue;
58107
58108 name = configfs_get_name(next);
58109- len = strlen(name);
58110+ if (next->s_dentry && name == next->s_dentry->d_iname) {
58111+ len = next->s_dentry->d_name.len;
58112+ memcpy(d_name, name, len);
58113+ name = d_name;
58114+ } else
58115+ len = strlen(name);
58116
58117 /*
58118 * We'll have a dentry and an inode for
58119diff --git a/fs/coredump.c b/fs/coredump.c
58120index bc3fbcd..6031650 100644
58121--- a/fs/coredump.c
58122+++ b/fs/coredump.c
58123@@ -438,8 +438,8 @@ static void wait_for_dump_helpers(struct file *file)
58124 struct pipe_inode_info *pipe = file->private_data;
58125
58126 pipe_lock(pipe);
58127- pipe->readers++;
58128- pipe->writers--;
58129+ atomic_inc(&pipe->readers);
58130+ atomic_dec(&pipe->writers);
58131 wake_up_interruptible_sync(&pipe->wait);
58132 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58133 pipe_unlock(pipe);
58134@@ -448,11 +448,11 @@ static void wait_for_dump_helpers(struct file *file)
58135 * We actually want wait_event_freezable() but then we need
58136 * to clear TIF_SIGPENDING and improve dump_interrupted().
58137 */
58138- wait_event_interruptible(pipe->wait, pipe->readers == 1);
58139+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
58140
58141 pipe_lock(pipe);
58142- pipe->readers--;
58143- pipe->writers++;
58144+ atomic_dec(&pipe->readers);
58145+ atomic_inc(&pipe->writers);
58146 pipe_unlock(pipe);
58147 }
58148
58149@@ -499,7 +499,9 @@ void do_coredump(const siginfo_t *siginfo)
58150 struct files_struct *displaced;
58151 bool need_nonrelative = false;
58152 bool core_dumped = false;
58153- static atomic_t core_dump_count = ATOMIC_INIT(0);
58154+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
58155+ long signr = siginfo->si_signo;
58156+ int dumpable;
58157 struct coredump_params cprm = {
58158 .siginfo = siginfo,
58159 .regs = signal_pt_regs(),
58160@@ -512,12 +514,17 @@ void do_coredump(const siginfo_t *siginfo)
58161 .mm_flags = mm->flags,
58162 };
58163
58164- audit_core_dumps(siginfo->si_signo);
58165+ audit_core_dumps(signr);
58166+
58167+ dumpable = __get_dumpable(cprm.mm_flags);
58168+
58169+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
58170+ gr_handle_brute_attach(dumpable);
58171
58172 binfmt = mm->binfmt;
58173 if (!binfmt || !binfmt->core_dump)
58174 goto fail;
58175- if (!__get_dumpable(cprm.mm_flags))
58176+ if (!dumpable)
58177 goto fail;
58178
58179 cred = prepare_creds();
58180@@ -536,7 +543,7 @@ void do_coredump(const siginfo_t *siginfo)
58181 need_nonrelative = true;
58182 }
58183
58184- retval = coredump_wait(siginfo->si_signo, &core_state);
58185+ retval = coredump_wait(signr, &core_state);
58186 if (retval < 0)
58187 goto fail_creds;
58188
58189@@ -579,7 +586,7 @@ void do_coredump(const siginfo_t *siginfo)
58190 }
58191 cprm.limit = RLIM_INFINITY;
58192
58193- dump_count = atomic_inc_return(&core_dump_count);
58194+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
58195 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
58196 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
58197 task_tgid_vnr(current), current->comm);
58198@@ -611,6 +618,8 @@ void do_coredump(const siginfo_t *siginfo)
58199 } else {
58200 struct inode *inode;
58201
58202+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58203+
58204 if (cprm.limit < binfmt->min_coredump)
58205 goto fail_unlock;
58206
58207@@ -669,7 +678,7 @@ close_fail:
58208 filp_close(cprm.file, NULL);
58209 fail_dropcount:
58210 if (ispipe)
58211- atomic_dec(&core_dump_count);
58212+ atomic_dec_unchecked(&core_dump_count);
58213 fail_unlock:
58214 kfree(cn.corename);
58215 coredump_finish(mm, core_dumped);
58216@@ -690,6 +699,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58217 struct file *file = cprm->file;
58218 loff_t pos = file->f_pos;
58219 ssize_t n;
58220+
58221+ gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58222 if (cprm->written + nr > cprm->limit)
58223 return 0;
58224 while (nr) {
58225diff --git a/fs/dcache.c b/fs/dcache.c
58226index f7ad6d7..d852932 100644
58227--- a/fs/dcache.c
58228+++ b/fs/dcache.c
58229@@ -1495,7 +1495,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58230 */
58231 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58232 if (name->len > DNAME_INLINE_LEN-1) {
58233- dname = kmalloc(name->len + 1, GFP_KERNEL);
58234+ dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58235 if (!dname) {
58236 kmem_cache_free(dentry_cache, dentry);
58237 return NULL;
58238@@ -3428,7 +3428,8 @@ void __init vfs_caches_init(unsigned long mempages)
58239 mempages -= reserve;
58240
58241 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58242- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58243+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58244+ SLAB_NO_SANITIZE, NULL);
58245
58246 dcache_init();
58247 inode_init();
58248diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58249index 9c0444c..628490c 100644
58250--- a/fs/debugfs/inode.c
58251+++ b/fs/debugfs/inode.c
58252@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58253 */
58254 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58255 {
58256+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58257+ return __create_file(name, S_IFDIR | S_IRWXU,
58258+#else
58259 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58260+#endif
58261 parent, NULL, NULL);
58262 }
58263 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58264diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58265index c36c448..fc96710 100644
58266--- a/fs/ecryptfs/inode.c
58267+++ b/fs/ecryptfs/inode.c
58268@@ -675,7 +675,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
58269 old_fs = get_fs();
58270 set_fs(get_ds());
58271 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58272- (char __user *)lower_buf,
58273+ (char __force_user *)lower_buf,
58274 PATH_MAX);
58275 set_fs(old_fs);
58276 if (rc < 0)
58277diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58278index e4141f2..d8263e8 100644
58279--- a/fs/ecryptfs/miscdev.c
58280+++ b/fs/ecryptfs/miscdev.c
58281@@ -304,7 +304,7 @@ check_list:
58282 goto out_unlock_msg_ctx;
58283 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58284 if (msg_ctx->msg) {
58285- if (copy_to_user(&buf[i], packet_length, packet_length_size))
58286+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58287 goto out_unlock_msg_ctx;
58288 i += packet_length_size;
58289 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58290diff --git a/fs/exec.c b/fs/exec.c
58291index 7ea097f..0158d8a 100644
58292--- a/fs/exec.c
58293+++ b/fs/exec.c
58294@@ -55,8 +55,20 @@
58295 #include <linux/pipe_fs_i.h>
58296 #include <linux/oom.h>
58297 #include <linux/compat.h>
58298+#include <linux/random.h>
58299+#include <linux/seq_file.h>
58300+#include <linux/coredump.h>
58301+#include <linux/mman.h>
58302+
58303+#ifdef CONFIG_PAX_REFCOUNT
58304+#include <linux/kallsyms.h>
58305+#include <linux/kdebug.h>
58306+#endif
58307+
58308+#include <trace/events/fs.h>
58309
58310 #include <asm/uaccess.h>
58311+#include <asm/sections.h>
58312 #include <asm/mmu_context.h>
58313 #include <asm/tlb.h>
58314
58315@@ -66,19 +78,34 @@
58316
58317 #include <trace/events/sched.h>
58318
58319+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58320+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58321+{
58322+ 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");
58323+}
58324+#endif
58325+
58326+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58327+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58328+EXPORT_SYMBOL(pax_set_initial_flags_func);
58329+#endif
58330+
58331 int suid_dumpable = 0;
58332
58333 static LIST_HEAD(formats);
58334 static DEFINE_RWLOCK(binfmt_lock);
58335
58336+extern int gr_process_kernel_exec_ban(void);
58337+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58338+
58339 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58340 {
58341 BUG_ON(!fmt);
58342 if (WARN_ON(!fmt->load_binary))
58343 return;
58344 write_lock(&binfmt_lock);
58345- insert ? list_add(&fmt->lh, &formats) :
58346- list_add_tail(&fmt->lh, &formats);
58347+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58348+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58349 write_unlock(&binfmt_lock);
58350 }
58351
58352@@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
58353 void unregister_binfmt(struct linux_binfmt * fmt)
58354 {
58355 write_lock(&binfmt_lock);
58356- list_del(&fmt->lh);
58357+ pax_list_del((struct list_head *)&fmt->lh);
58358 write_unlock(&binfmt_lock);
58359 }
58360
58361@@ -181,18 +208,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58362 int write)
58363 {
58364 struct page *page;
58365- int ret;
58366
58367-#ifdef CONFIG_STACK_GROWSUP
58368- if (write) {
58369- ret = expand_downwards(bprm->vma, pos);
58370- if (ret < 0)
58371- return NULL;
58372- }
58373-#endif
58374- ret = get_user_pages(current, bprm->mm, pos,
58375- 1, write, 1, &page, NULL);
58376- if (ret <= 0)
58377+ if (0 > expand_downwards(bprm->vma, pos))
58378+ return NULL;
58379+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58380 return NULL;
58381
58382 if (write) {
58383@@ -208,6 +227,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58384 if (size <= ARG_MAX)
58385 return page;
58386
58387+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58388+ // only allow 512KB for argv+env on suid/sgid binaries
58389+ // to prevent easy ASLR exhaustion
58390+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58391+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
58392+ (size > (512 * 1024))) {
58393+ put_page(page);
58394+ return NULL;
58395+ }
58396+#endif
58397+
58398 /*
58399 * Limit to 1/4-th the stack size for the argv+env strings.
58400 * This ensures that:
58401@@ -267,6 +297,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58402 vma->vm_end = STACK_TOP_MAX;
58403 vma->vm_start = vma->vm_end - PAGE_SIZE;
58404 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58405+
58406+#ifdef CONFIG_PAX_SEGMEXEC
58407+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58408+#endif
58409+
58410 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
58411 INIT_LIST_HEAD(&vma->anon_vma_chain);
58412
58413@@ -277,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58414 mm->stack_vm = mm->total_vm = 1;
58415 up_write(&mm->mmap_sem);
58416 bprm->p = vma->vm_end - sizeof(void *);
58417+
58418+#ifdef CONFIG_PAX_RANDUSTACK
58419+ if (randomize_va_space)
58420+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
58421+#endif
58422+
58423 return 0;
58424 err:
58425 up_write(&mm->mmap_sem);
58426@@ -397,7 +438,7 @@ struct user_arg_ptr {
58427 } ptr;
58428 };
58429
58430-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58431+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58432 {
58433 const char __user *native;
58434
58435@@ -406,14 +447,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58436 compat_uptr_t compat;
58437
58438 if (get_user(compat, argv.ptr.compat + nr))
58439- return ERR_PTR(-EFAULT);
58440+ return (const char __force_user *)ERR_PTR(-EFAULT);
58441
58442 return compat_ptr(compat);
58443 }
58444 #endif
58445
58446 if (get_user(native, argv.ptr.native + nr))
58447- return ERR_PTR(-EFAULT);
58448+ return (const char __force_user *)ERR_PTR(-EFAULT);
58449
58450 return native;
58451 }
58452@@ -432,7 +473,7 @@ static int count(struct user_arg_ptr argv, int max)
58453 if (!p)
58454 break;
58455
58456- if (IS_ERR(p))
58457+ if (IS_ERR((const char __force_kernel *)p))
58458 return -EFAULT;
58459
58460 if (i >= max)
58461@@ -467,7 +508,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
58462
58463 ret = -EFAULT;
58464 str = get_user_arg_ptr(argv, argc);
58465- if (IS_ERR(str))
58466+ if (IS_ERR((const char __force_kernel *)str))
58467 goto out;
58468
58469 len = strnlen_user(str, MAX_ARG_STRLEN);
58470@@ -549,7 +590,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
58471 int r;
58472 mm_segment_t oldfs = get_fs();
58473 struct user_arg_ptr argv = {
58474- .ptr.native = (const char __user *const __user *)__argv,
58475+ .ptr.native = (const char __user * const __force_user *)__argv,
58476 };
58477
58478 set_fs(KERNEL_DS);
58479@@ -584,7 +625,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58480 unsigned long new_end = old_end - shift;
58481 struct mmu_gather tlb;
58482
58483- BUG_ON(new_start > new_end);
58484+ if (new_start >= new_end || new_start < mmap_min_addr)
58485+ return -ENOMEM;
58486
58487 /*
58488 * ensure there are no vmas between where we want to go
58489@@ -593,6 +635,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58490 if (vma != find_vma(mm, new_start))
58491 return -EFAULT;
58492
58493+#ifdef CONFIG_PAX_SEGMEXEC
58494+ BUG_ON(pax_find_mirror_vma(vma));
58495+#endif
58496+
58497 /*
58498 * cover the whole range: [new_start, old_end)
58499 */
58500@@ -673,10 +719,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58501 stack_top = arch_align_stack(stack_top);
58502 stack_top = PAGE_ALIGN(stack_top);
58503
58504- if (unlikely(stack_top < mmap_min_addr) ||
58505- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
58506- return -ENOMEM;
58507-
58508 stack_shift = vma->vm_end - stack_top;
58509
58510 bprm->p -= stack_shift;
58511@@ -688,8 +730,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
58512 bprm->exec -= stack_shift;
58513
58514 down_write(&mm->mmap_sem);
58515+
58516+ /* Move stack pages down in memory. */
58517+ if (stack_shift) {
58518+ ret = shift_arg_pages(vma, stack_shift);
58519+ if (ret)
58520+ goto out_unlock;
58521+ }
58522+
58523 vm_flags = VM_STACK_FLAGS;
58524
58525+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58526+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58527+ vm_flags &= ~VM_EXEC;
58528+
58529+#ifdef CONFIG_PAX_MPROTECT
58530+ if (mm->pax_flags & MF_PAX_MPROTECT)
58531+ vm_flags &= ~VM_MAYEXEC;
58532+#endif
58533+
58534+ }
58535+#endif
58536+
58537 /*
58538 * Adjust stack execute permissions; explicitly enable for
58539 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
58540@@ -708,13 +770,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58541 goto out_unlock;
58542 BUG_ON(prev != vma);
58543
58544- /* Move stack pages down in memory. */
58545- if (stack_shift) {
58546- ret = shift_arg_pages(vma, stack_shift);
58547- if (ret)
58548- goto out_unlock;
58549- }
58550-
58551 /* mprotect_fixup is overkill to remove the temporary stack flags */
58552 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
58553
58554@@ -738,6 +793,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
58555 #endif
58556 current->mm->start_stack = bprm->p;
58557 ret = expand_stack(vma, stack_base);
58558+
58559+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
58560+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
58561+ unsigned long size;
58562+ vm_flags_t vm_flags;
58563+
58564+ size = STACK_TOP - vma->vm_end;
58565+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
58566+
58567+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
58568+
58569+#ifdef CONFIG_X86
58570+ if (!ret) {
58571+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
58572+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
58573+ }
58574+#endif
58575+
58576+ }
58577+#endif
58578+
58579 if (ret)
58580 ret = -EFAULT;
58581
58582@@ -774,6 +850,8 @@ struct file *open_exec(const char *name)
58583
58584 fsnotify_open(file);
58585
58586+ trace_open_exec(name);
58587+
58588 err = deny_write_access(file);
58589 if (err)
58590 goto exit;
58591@@ -797,7 +875,7 @@ int kernel_read(struct file *file, loff_t offset,
58592 old_fs = get_fs();
58593 set_fs(get_ds());
58594 /* The cast to a user pointer is valid due to the set_fs() */
58595- result = vfs_read(file, (void __user *)addr, count, &pos);
58596+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
58597 set_fs(old_fs);
58598 return result;
58599 }
58600@@ -1253,7 +1331,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
58601 }
58602 rcu_read_unlock();
58603
58604- if (p->fs->users > n_fs) {
58605+ if (atomic_read(&p->fs->users) > n_fs) {
58606 bprm->unsafe |= LSM_UNSAFE_SHARE;
58607 } else {
58608 res = -EAGAIN;
58609@@ -1443,6 +1521,31 @@ static int exec_binprm(struct linux_binprm *bprm)
58610 return ret;
58611 }
58612
58613+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58614+static DEFINE_PER_CPU(u64, exec_counter);
58615+static int __init init_exec_counters(void)
58616+{
58617+ unsigned int cpu;
58618+
58619+ for_each_possible_cpu(cpu) {
58620+ per_cpu(exec_counter, cpu) = (u64)cpu;
58621+ }
58622+
58623+ return 0;
58624+}
58625+early_initcall(init_exec_counters);
58626+static inline void increment_exec_counter(void)
58627+{
58628+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
58629+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
58630+}
58631+#else
58632+static inline void increment_exec_counter(void) {}
58633+#endif
58634+
58635+extern void gr_handle_exec_args(struct linux_binprm *bprm,
58636+ struct user_arg_ptr argv);
58637+
58638 /*
58639 * sys_execve() executes a new program.
58640 */
58641@@ -1450,12 +1553,19 @@ static int do_execve_common(const char *filename,
58642 struct user_arg_ptr argv,
58643 struct user_arg_ptr envp)
58644 {
58645+#ifdef CONFIG_GRKERNSEC
58646+ struct file *old_exec_file;
58647+ struct acl_subject_label *old_acl;
58648+ struct rlimit old_rlim[RLIM_NLIMITS];
58649+#endif
58650 struct linux_binprm *bprm;
58651 struct file *file;
58652 struct files_struct *displaced;
58653 bool clear_in_exec;
58654 int retval;
58655
58656+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
58657+
58658 /*
58659 * We move the actual failure in case of RLIMIT_NPROC excess from
58660 * set*uid() to execve() because too many poorly written programs
58661@@ -1496,12 +1606,22 @@ static int do_execve_common(const char *filename,
58662 if (IS_ERR(file))
58663 goto out_unmark;
58664
58665+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
58666+ retval = -EPERM;
58667+ goto out_file;
58668+ }
58669+
58670 sched_exec();
58671
58672 bprm->file = file;
58673 bprm->filename = filename;
58674 bprm->interp = filename;
58675
58676+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
58677+ retval = -EACCES;
58678+ goto out_file;
58679+ }
58680+
58681 retval = bprm_mm_init(bprm);
58682 if (retval)
58683 goto out_file;
58684@@ -1518,24 +1638,70 @@ static int do_execve_common(const char *filename,
58685 if (retval < 0)
58686 goto out;
58687
58688+#ifdef CONFIG_GRKERNSEC
58689+ old_acl = current->acl;
58690+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
58691+ old_exec_file = current->exec_file;
58692+ get_file(file);
58693+ current->exec_file = file;
58694+#endif
58695+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58696+ /* limit suid stack to 8MB
58697+ * we saved the old limits above and will restore them if this exec fails
58698+ */
58699+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
58700+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
58701+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
58702+#endif
58703+
58704+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
58705+ retval = -EPERM;
58706+ goto out_fail;
58707+ }
58708+
58709+ if (!gr_tpe_allow(file)) {
58710+ retval = -EACCES;
58711+ goto out_fail;
58712+ }
58713+
58714+ if (gr_check_crash_exec(file)) {
58715+ retval = -EACCES;
58716+ goto out_fail;
58717+ }
58718+
58719+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
58720+ bprm->unsafe);
58721+ if (retval < 0)
58722+ goto out_fail;
58723+
58724 retval = copy_strings_kernel(1, &bprm->filename, bprm);
58725 if (retval < 0)
58726- goto out;
58727+ goto out_fail;
58728
58729 bprm->exec = bprm->p;
58730 retval = copy_strings(bprm->envc, envp, bprm);
58731 if (retval < 0)
58732- goto out;
58733+ goto out_fail;
58734
58735 retval = copy_strings(bprm->argc, argv, bprm);
58736 if (retval < 0)
58737- goto out;
58738+ goto out_fail;
58739+
58740+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
58741+
58742+ gr_handle_exec_args(bprm, argv);
58743
58744 retval = exec_binprm(bprm);
58745 if (retval < 0)
58746- goto out;
58747+ goto out_fail;
58748+#ifdef CONFIG_GRKERNSEC
58749+ if (old_exec_file)
58750+ fput(old_exec_file);
58751+#endif
58752
58753 /* execve succeeded */
58754+
58755+ increment_exec_counter();
58756 current->fs->in_exec = 0;
58757 current->in_execve = 0;
58758 acct_update_integrals(current);
58759@@ -1545,6 +1711,14 @@ static int do_execve_common(const char *filename,
58760 put_files_struct(displaced);
58761 return retval;
58762
58763+out_fail:
58764+#ifdef CONFIG_GRKERNSEC
58765+ current->acl = old_acl;
58766+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
58767+ fput(current->exec_file);
58768+ current->exec_file = old_exec_file;
58769+#endif
58770+
58771 out:
58772 if (bprm->mm) {
58773 acct_arg_size(bprm, 0);
58774@@ -1699,3 +1873,295 @@ asmlinkage long compat_sys_execve(const char __user * filename,
58775 return error;
58776 }
58777 #endif
58778+
58779+int pax_check_flags(unsigned long *flags)
58780+{
58781+ int retval = 0;
58782+
58783+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
58784+ if (*flags & MF_PAX_SEGMEXEC)
58785+ {
58786+ *flags &= ~MF_PAX_SEGMEXEC;
58787+ retval = -EINVAL;
58788+ }
58789+#endif
58790+
58791+ if ((*flags & MF_PAX_PAGEEXEC)
58792+
58793+#ifdef CONFIG_PAX_PAGEEXEC
58794+ && (*flags & MF_PAX_SEGMEXEC)
58795+#endif
58796+
58797+ )
58798+ {
58799+ *flags &= ~MF_PAX_PAGEEXEC;
58800+ retval = -EINVAL;
58801+ }
58802+
58803+ if ((*flags & MF_PAX_MPROTECT)
58804+
58805+#ifdef CONFIG_PAX_MPROTECT
58806+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58807+#endif
58808+
58809+ )
58810+ {
58811+ *flags &= ~MF_PAX_MPROTECT;
58812+ retval = -EINVAL;
58813+ }
58814+
58815+ if ((*flags & MF_PAX_EMUTRAMP)
58816+
58817+#ifdef CONFIG_PAX_EMUTRAMP
58818+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58819+#endif
58820+
58821+ )
58822+ {
58823+ *flags &= ~MF_PAX_EMUTRAMP;
58824+ retval = -EINVAL;
58825+ }
58826+
58827+ return retval;
58828+}
58829+
58830+EXPORT_SYMBOL(pax_check_flags);
58831+
58832+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58833+char *pax_get_path(const struct path *path, char *buf, int buflen)
58834+{
58835+ char *pathname = d_path(path, buf, buflen);
58836+
58837+ if (IS_ERR(pathname))
58838+ goto toolong;
58839+
58840+ pathname = mangle_path(buf, pathname, "\t\n\\");
58841+ if (!pathname)
58842+ goto toolong;
58843+
58844+ *pathname = 0;
58845+ return buf;
58846+
58847+toolong:
58848+ return "<path too long>";
58849+}
58850+EXPORT_SYMBOL(pax_get_path);
58851+
58852+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
58853+{
58854+ struct task_struct *tsk = current;
58855+ struct mm_struct *mm = current->mm;
58856+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
58857+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
58858+ char *path_exec = NULL;
58859+ char *path_fault = NULL;
58860+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
58861+ siginfo_t info = { };
58862+
58863+ if (buffer_exec && buffer_fault) {
58864+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
58865+
58866+ down_read(&mm->mmap_sem);
58867+ vma = mm->mmap;
58868+ while (vma && (!vma_exec || !vma_fault)) {
58869+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
58870+ vma_exec = vma;
58871+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
58872+ vma_fault = vma;
58873+ vma = vma->vm_next;
58874+ }
58875+ if (vma_exec)
58876+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
58877+ if (vma_fault) {
58878+ start = vma_fault->vm_start;
58879+ end = vma_fault->vm_end;
58880+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
58881+ if (vma_fault->vm_file)
58882+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
58883+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
58884+ path_fault = "<heap>";
58885+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
58886+ path_fault = "<stack>";
58887+ else
58888+ path_fault = "<anonymous mapping>";
58889+ }
58890+ up_read(&mm->mmap_sem);
58891+ }
58892+ if (tsk->signal->curr_ip)
58893+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
58894+ else
58895+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
58896+ 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),
58897+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
58898+ free_page((unsigned long)buffer_exec);
58899+ free_page((unsigned long)buffer_fault);
58900+ pax_report_insns(regs, pc, sp);
58901+ info.si_signo = SIGKILL;
58902+ info.si_errno = 0;
58903+ info.si_code = SI_KERNEL;
58904+ info.si_pid = 0;
58905+ info.si_uid = 0;
58906+ do_coredump(&info);
58907+}
58908+#endif
58909+
58910+#ifdef CONFIG_PAX_REFCOUNT
58911+void pax_report_refcount_overflow(struct pt_regs *regs)
58912+{
58913+ if (current->signal->curr_ip)
58914+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
58915+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
58916+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58917+ else
58918+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
58919+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58920+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
58921+ preempt_disable();
58922+ show_regs(regs);
58923+ preempt_enable();
58924+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
58925+}
58926+#endif
58927+
58928+#ifdef CONFIG_PAX_USERCOPY
58929+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
58930+static noinline int check_stack_object(const void *obj, unsigned long len)
58931+{
58932+ const void * const stack = task_stack_page(current);
58933+ const void * const stackend = stack + THREAD_SIZE;
58934+
58935+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
58936+ const void *frame = NULL;
58937+ const void *oldframe;
58938+#endif
58939+
58940+ if (obj + len < obj)
58941+ return -1;
58942+
58943+ if (obj + len <= stack || stackend <= obj)
58944+ return 0;
58945+
58946+ if (obj < stack || stackend < obj + len)
58947+ return -1;
58948+
58949+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
58950+ oldframe = __builtin_frame_address(1);
58951+ if (oldframe)
58952+ frame = __builtin_frame_address(2);
58953+ /*
58954+ low ----------------------------------------------> high
58955+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
58956+ ^----------------^
58957+ allow copies only within here
58958+ */
58959+ while (stack <= frame && frame < stackend) {
58960+ /* if obj + len extends past the last frame, this
58961+ check won't pass and the next frame will be 0,
58962+ causing us to bail out and correctly report
58963+ the copy as invalid
58964+ */
58965+ if (obj + len <= frame)
58966+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
58967+ oldframe = frame;
58968+ frame = *(const void * const *)frame;
58969+ }
58970+ return -1;
58971+#else
58972+ return 1;
58973+#endif
58974+}
58975+
58976+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
58977+{
58978+ if (current->signal->curr_ip)
58979+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
58980+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
58981+ else
58982+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
58983+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
58984+ dump_stack();
58985+ gr_handle_kernel_exploit();
58986+ do_group_exit(SIGKILL);
58987+}
58988+#endif
58989+
58990+#ifdef CONFIG_PAX_USERCOPY
58991+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
58992+{
58993+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
58994+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
58995+#ifdef CONFIG_MODULES
58996+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
58997+#else
58998+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
58999+#endif
59000+
59001+#else
59002+ unsigned long textlow = (unsigned long)_stext;
59003+ unsigned long texthigh = (unsigned long)_etext;
59004+
59005+#ifdef CONFIG_X86_64
59006+ /* check against linear mapping as well */
59007+ if (high > (unsigned long)__va(__pa(textlow)) &&
59008+ low <= (unsigned long)__va(__pa(texthigh)))
59009+ return true;
59010+#endif
59011+
59012+#endif
59013+
59014+ if (high <= textlow || low > texthigh)
59015+ return false;
59016+ else
59017+ return true;
59018+}
59019+#endif
59020+
59021+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
59022+{
59023+
59024+#ifdef CONFIG_PAX_USERCOPY
59025+ const char *type;
59026+
59027+ if (!n)
59028+ return;
59029+
59030+ type = check_heap_object(ptr, n);
59031+ if (!type) {
59032+ int ret = check_stack_object(ptr, n);
59033+ if (ret == 1 || ret == 2)
59034+ return;
59035+ if (ret == 0) {
59036+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
59037+ type = "<kernel text>";
59038+ else
59039+ return;
59040+ } else
59041+ type = "<process stack>";
59042+ }
59043+
59044+ pax_report_usercopy(ptr, n, to_user, type);
59045+#endif
59046+
59047+}
59048+EXPORT_SYMBOL(__check_object_size);
59049+
59050+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
59051+void pax_track_stack(void)
59052+{
59053+ unsigned long sp = (unsigned long)&sp;
59054+ if (sp < current_thread_info()->lowest_stack &&
59055+ sp > (unsigned long)task_stack_page(current))
59056+ current_thread_info()->lowest_stack = sp;
59057+}
59058+EXPORT_SYMBOL(pax_track_stack);
59059+#endif
59060+
59061+#ifdef CONFIG_PAX_SIZE_OVERFLOW
59062+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
59063+{
59064+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
59065+ dump_stack();
59066+ do_group_exit(SIGKILL);
59067+}
59068+EXPORT_SYMBOL(report_size_overflow);
59069+#endif
59070diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
59071index 9f9992b..8b59411 100644
59072--- a/fs/ext2/balloc.c
59073+++ b/fs/ext2/balloc.c
59074@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
59075
59076 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59077 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59078- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59079+ if (free_blocks < root_blocks + 1 &&
59080 !uid_eq(sbi->s_resuid, current_fsuid()) &&
59081 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59082- !in_group_p (sbi->s_resgid))) {
59083+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59084 return 0;
59085 }
59086 return 1;
59087diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
59088index 2d7557d..14e38f94 100644
59089--- a/fs/ext2/xattr.c
59090+++ b/fs/ext2/xattr.c
59091@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
59092 struct buffer_head *bh = NULL;
59093 struct ext2_xattr_entry *entry;
59094 char *end;
59095- size_t rest = buffer_size;
59096+ size_t rest = buffer_size, total_size = 0;
59097 int error;
59098
59099 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
59100@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
59101 buffer += size;
59102 }
59103 rest -= size;
59104+ total_size += size;
59105 }
59106 }
59107- error = buffer_size - rest; /* total size */
59108+ error = total_size;
59109
59110 cleanup:
59111 brelse(bh);
59112diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
59113index 22548f5..41521d8 100644
59114--- a/fs/ext3/balloc.c
59115+++ b/fs/ext3/balloc.c
59116@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
59117
59118 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59119 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59120- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59121+ if (free_blocks < root_blocks + 1 &&
59122 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
59123 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59124- !in_group_p (sbi->s_resgid))) {
59125+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59126 return 0;
59127 }
59128 return 1;
59129diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
59130index b1fc963..881228c 100644
59131--- a/fs/ext3/xattr.c
59132+++ b/fs/ext3/xattr.c
59133@@ -330,7 +330,7 @@ static int
59134 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59135 char *buffer, size_t buffer_size)
59136 {
59137- size_t rest = buffer_size;
59138+ size_t rest = buffer_size, total_size = 0;
59139
59140 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
59141 const struct xattr_handler *handler =
59142@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59143 buffer += size;
59144 }
59145 rest -= size;
59146+ total_size += size;
59147 }
59148 }
59149- return buffer_size - rest;
59150+ return total_size;
59151 }
59152
59153 static int
59154diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
59155index 6ea7b14..8fa16d9 100644
59156--- a/fs/ext4/balloc.c
59157+++ b/fs/ext4/balloc.c
59158@@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
59159 /* Hm, nope. Are (enough) root reserved clusters available? */
59160 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
59161 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
59162- capable(CAP_SYS_RESOURCE) ||
59163- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
59164+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
59165+ capable_nolog(CAP_SYS_RESOURCE)) {
59166
59167 if (free_clusters >= (nclusters + dirty_clusters +
59168 resv_clusters))
59169diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
59170index d3a534f..242c50a 100644
59171--- a/fs/ext4/ext4.h
59172+++ b/fs/ext4/ext4.h
59173@@ -1269,19 +1269,19 @@ struct ext4_sb_info {
59174 unsigned long s_mb_last_start;
59175
59176 /* stats for buddy allocator */
59177- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
59178- atomic_t s_bal_success; /* we found long enough chunks */
59179- atomic_t s_bal_allocated; /* in blocks */
59180- atomic_t s_bal_ex_scanned; /* total extents scanned */
59181- atomic_t s_bal_goals; /* goal hits */
59182- atomic_t s_bal_breaks; /* too long searches */
59183- atomic_t s_bal_2orders; /* 2^order hits */
59184+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
59185+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
59186+ atomic_unchecked_t s_bal_allocated; /* in blocks */
59187+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
59188+ atomic_unchecked_t s_bal_goals; /* goal hits */
59189+ atomic_unchecked_t s_bal_breaks; /* too long searches */
59190+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
59191 spinlock_t s_bal_lock;
59192 unsigned long s_mb_buddies_generated;
59193 unsigned long long s_mb_generation_time;
59194- atomic_t s_mb_lost_chunks;
59195- atomic_t s_mb_preallocated;
59196- atomic_t s_mb_discarded;
59197+ atomic_unchecked_t s_mb_lost_chunks;
59198+ atomic_unchecked_t s_mb_preallocated;
59199+ atomic_unchecked_t s_mb_discarded;
59200 atomic_t s_lock_busy;
59201
59202 /* locality groups */
59203diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59204index 04a5c75..09894fa 100644
59205--- a/fs/ext4/mballoc.c
59206+++ b/fs/ext4/mballoc.c
59207@@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59208 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59209
59210 if (EXT4_SB(sb)->s_mb_stats)
59211- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59212+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59213
59214 break;
59215 }
59216@@ -2189,7 +2189,7 @@ repeat:
59217 ac->ac_status = AC_STATUS_CONTINUE;
59218 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59219 cr = 3;
59220- atomic_inc(&sbi->s_mb_lost_chunks);
59221+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59222 goto repeat;
59223 }
59224 }
59225@@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
59226 if (sbi->s_mb_stats) {
59227 ext4_msg(sb, KERN_INFO,
59228 "mballoc: %u blocks %u reqs (%u success)",
59229- atomic_read(&sbi->s_bal_allocated),
59230- atomic_read(&sbi->s_bal_reqs),
59231- atomic_read(&sbi->s_bal_success));
59232+ atomic_read_unchecked(&sbi->s_bal_allocated),
59233+ atomic_read_unchecked(&sbi->s_bal_reqs),
59234+ atomic_read_unchecked(&sbi->s_bal_success));
59235 ext4_msg(sb, KERN_INFO,
59236 "mballoc: %u extents scanned, %u goal hits, "
59237 "%u 2^N hits, %u breaks, %u lost",
59238- atomic_read(&sbi->s_bal_ex_scanned),
59239- atomic_read(&sbi->s_bal_goals),
59240- atomic_read(&sbi->s_bal_2orders),
59241- atomic_read(&sbi->s_bal_breaks),
59242- atomic_read(&sbi->s_mb_lost_chunks));
59243+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59244+ atomic_read_unchecked(&sbi->s_bal_goals),
59245+ atomic_read_unchecked(&sbi->s_bal_2orders),
59246+ atomic_read_unchecked(&sbi->s_bal_breaks),
59247+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59248 ext4_msg(sb, KERN_INFO,
59249 "mballoc: %lu generated and it took %Lu",
59250 sbi->s_mb_buddies_generated,
59251 sbi->s_mb_generation_time);
59252 ext4_msg(sb, KERN_INFO,
59253 "mballoc: %u preallocated, %u discarded",
59254- atomic_read(&sbi->s_mb_preallocated),
59255- atomic_read(&sbi->s_mb_discarded));
59256+ atomic_read_unchecked(&sbi->s_mb_preallocated),
59257+ atomic_read_unchecked(&sbi->s_mb_discarded));
59258 }
59259
59260 free_percpu(sbi->s_locality_groups);
59261@@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59262 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59263
59264 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59265- atomic_inc(&sbi->s_bal_reqs);
59266- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59267+ atomic_inc_unchecked(&sbi->s_bal_reqs);
59268+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59269 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59270- atomic_inc(&sbi->s_bal_success);
59271- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59272+ atomic_inc_unchecked(&sbi->s_bal_success);
59273+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59274 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59275 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59276- atomic_inc(&sbi->s_bal_goals);
59277+ atomic_inc_unchecked(&sbi->s_bal_goals);
59278 if (ac->ac_found > sbi->s_mb_max_to_scan)
59279- atomic_inc(&sbi->s_bal_breaks);
59280+ atomic_inc_unchecked(&sbi->s_bal_breaks);
59281 }
59282
59283 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59284@@ -3583,7 +3583,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59285 trace_ext4_mb_new_inode_pa(ac, pa);
59286
59287 ext4_mb_use_inode_pa(ac, pa);
59288- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59289+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59290
59291 ei = EXT4_I(ac->ac_inode);
59292 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59293@@ -3643,7 +3643,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59294 trace_ext4_mb_new_group_pa(ac, pa);
59295
59296 ext4_mb_use_group_pa(ac, pa);
59297- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59298+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59299
59300 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59301 lg = ac->ac_lg;
59302@@ -3732,7 +3732,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59303 * from the bitmap and continue.
59304 */
59305 }
59306- atomic_add(free, &sbi->s_mb_discarded);
59307+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
59308
59309 return err;
59310 }
59311@@ -3750,7 +3750,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59312 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59313 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59314 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59315- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59316+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59317 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59318
59319 return 0;
59320diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59321index 04434ad..6404663 100644
59322--- a/fs/ext4/mmp.c
59323+++ b/fs/ext4/mmp.c
59324@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59325 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59326 const char *function, unsigned int line, const char *msg)
59327 {
59328- __ext4_warning(sb, function, line, msg);
59329+ __ext4_warning(sb, function, line, "%s", msg);
59330 __ext4_warning(sb, function, line,
59331 "MMP failure info: last update time: %llu, last update "
59332 "node: %s, last update device: %s\n",
59333diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59334index 710fed2..a82e4e8 100644
59335--- a/fs/ext4/super.c
59336+++ b/fs/ext4/super.c
59337@@ -1270,7 +1270,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59338 }
59339
59340 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59341-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59342+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59343 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59344
59345 #ifdef CONFIG_QUOTA
59346@@ -2450,7 +2450,7 @@ struct ext4_attr {
59347 int offset;
59348 int deprecated_val;
59349 } u;
59350-};
59351+} __do_const;
59352
59353 static int parse_strtoull(const char *buf,
59354 unsigned long long max, unsigned long long *value)
59355diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59356index 1423c48..9c0c6dc 100644
59357--- a/fs/ext4/xattr.c
59358+++ b/fs/ext4/xattr.c
59359@@ -381,7 +381,7 @@ static int
59360 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59361 char *buffer, size_t buffer_size)
59362 {
59363- size_t rest = buffer_size;
59364+ size_t rest = buffer_size, total_size = 0;
59365
59366 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59367 const struct xattr_handler *handler =
59368@@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59369 buffer += size;
59370 }
59371 rest -= size;
59372+ total_size += size;
59373 }
59374 }
59375- return buffer_size - rest;
59376+ return total_size;
59377 }
59378
59379 static int
59380diff --git a/fs/fcntl.c b/fs/fcntl.c
59381index ef68665..5deacdc 100644
59382--- a/fs/fcntl.c
59383+++ b/fs/fcntl.c
59384@@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
59385 if (err)
59386 return err;
59387
59388+ if (gr_handle_chroot_fowner(pid, type))
59389+ return -ENOENT;
59390+ if (gr_check_protected_task_fowner(pid, type))
59391+ return -EACCES;
59392+
59393 f_modown(filp, pid, type, force);
59394 return 0;
59395 }
59396diff --git a/fs/fhandle.c b/fs/fhandle.c
59397index 999ff5c..41f4109 100644
59398--- a/fs/fhandle.c
59399+++ b/fs/fhandle.c
59400@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
59401 } else
59402 retval = 0;
59403 /* copy the mount id */
59404- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
59405- sizeof(*mnt_id)) ||
59406+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
59407 copy_to_user(ufh, handle,
59408 sizeof(struct file_handle) + handle_bytes))
59409 retval = -EFAULT;
59410diff --git a/fs/file.c b/fs/file.c
59411index 9de2026..8e334ca 100644
59412--- a/fs/file.c
59413+++ b/fs/file.c
59414@@ -16,6 +16,7 @@
59415 #include <linux/slab.h>
59416 #include <linux/vmalloc.h>
59417 #include <linux/file.h>
59418+#include <linux/security.h>
59419 #include <linux/fdtable.h>
59420 #include <linux/bitops.h>
59421 #include <linux/interrupt.h>
59422@@ -141,7 +142,7 @@ out:
59423 * Return <0 error code on error; 1 on successful completion.
59424 * The files->file_lock should be held on entry, and will be held on exit.
59425 */
59426-static int expand_fdtable(struct files_struct *files, int nr)
59427+static int expand_fdtable(struct files_struct *files, unsigned int nr)
59428 __releases(files->file_lock)
59429 __acquires(files->file_lock)
59430 {
59431@@ -186,7 +187,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
59432 * expanded and execution may have blocked.
59433 * The files->file_lock should be held on entry, and will be held on exit.
59434 */
59435-static int expand_files(struct files_struct *files, int nr)
59436+static int expand_files(struct files_struct *files, unsigned int nr)
59437 {
59438 struct fdtable *fdt;
59439
59440@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
59441 if (!file)
59442 return __close_fd(files, fd);
59443
59444+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
59445 if (fd >= rlimit(RLIMIT_NOFILE))
59446 return -EBADF;
59447
59448@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
59449 if (unlikely(oldfd == newfd))
59450 return -EINVAL;
59451
59452+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
59453 if (newfd >= rlimit(RLIMIT_NOFILE))
59454 return -EBADF;
59455
59456@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
59457 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
59458 {
59459 int err;
59460+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
59461 if (from >= rlimit(RLIMIT_NOFILE))
59462 return -EINVAL;
59463 err = alloc_fd(from, flags);
59464diff --git a/fs/filesystems.c b/fs/filesystems.c
59465index 92567d9..fcd8cbf 100644
59466--- a/fs/filesystems.c
59467+++ b/fs/filesystems.c
59468@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
59469 int len = dot ? dot - name : strlen(name);
59470
59471 fs = __get_fs_type(name, len);
59472+#ifdef CONFIG_GRKERNSEC_MODHARDEN
59473+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
59474+#else
59475 if (!fs && (request_module("fs-%.*s", len, name) == 0))
59476+#endif
59477 fs = __get_fs_type(name, len);
59478
59479 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
59480diff --git a/fs/fs_struct.c b/fs/fs_struct.c
59481index 7dca743..543d620 100644
59482--- a/fs/fs_struct.c
59483+++ b/fs/fs_struct.c
59484@@ -4,6 +4,7 @@
59485 #include <linux/path.h>
59486 #include <linux/slab.h>
59487 #include <linux/fs_struct.h>
59488+#include <linux/grsecurity.h>
59489 #include "internal.h"
59490
59491 /*
59492@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
59493 write_seqcount_begin(&fs->seq);
59494 old_root = fs->root;
59495 fs->root = *path;
59496+ gr_set_chroot_entries(current, path);
59497 write_seqcount_end(&fs->seq);
59498 spin_unlock(&fs->lock);
59499 if (old_root.dentry)
59500@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
59501 int hits = 0;
59502 spin_lock(&fs->lock);
59503 write_seqcount_begin(&fs->seq);
59504+ /* this root replacement is only done by pivot_root,
59505+ leave grsec's chroot tagging alone for this task
59506+ so that a pivoted root isn't treated as a chroot
59507+ */
59508 hits += replace_path(&fs->root, old_root, new_root);
59509 hits += replace_path(&fs->pwd, old_root, new_root);
59510 write_seqcount_end(&fs->seq);
59511@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
59512 task_lock(tsk);
59513 spin_lock(&fs->lock);
59514 tsk->fs = NULL;
59515- kill = !--fs->users;
59516+ gr_clear_chroot_entries(tsk);
59517+ kill = !atomic_dec_return(&fs->users);
59518 spin_unlock(&fs->lock);
59519 task_unlock(tsk);
59520 if (kill)
59521@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59522 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
59523 /* We don't need to lock fs - think why ;-) */
59524 if (fs) {
59525- fs->users = 1;
59526+ atomic_set(&fs->users, 1);
59527 fs->in_exec = 0;
59528 spin_lock_init(&fs->lock);
59529 seqcount_init(&fs->seq);
59530@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59531 spin_lock(&old->lock);
59532 fs->root = old->root;
59533 path_get(&fs->root);
59534+ /* instead of calling gr_set_chroot_entries here,
59535+ we call it from every caller of this function
59536+ */
59537 fs->pwd = old->pwd;
59538 path_get(&fs->pwd);
59539 spin_unlock(&old->lock);
59540@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
59541
59542 task_lock(current);
59543 spin_lock(&fs->lock);
59544- kill = !--fs->users;
59545+ kill = !atomic_dec_return(&fs->users);
59546 current->fs = new_fs;
59547+ gr_set_chroot_entries(current, &new_fs->root);
59548 spin_unlock(&fs->lock);
59549 task_unlock(current);
59550
59551@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
59552
59553 int current_umask(void)
59554 {
59555- return current->fs->umask;
59556+ return current->fs->umask | gr_acl_umask();
59557 }
59558 EXPORT_SYMBOL(current_umask);
59559
59560 /* to be mentioned only in INIT_TASK */
59561 struct fs_struct init_fs = {
59562- .users = 1,
59563+ .users = ATOMIC_INIT(1),
59564 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
59565 .seq = SEQCNT_ZERO(init_fs.seq),
59566 .umask = 0022,
59567diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
59568index 29d7feb..303644d 100644
59569--- a/fs/fscache/cookie.c
59570+++ b/fs/fscache/cookie.c
59571@@ -19,7 +19,7 @@
59572
59573 struct kmem_cache *fscache_cookie_jar;
59574
59575-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
59576+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
59577
59578 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
59579 static int fscache_alloc_object(struct fscache_cache *cache,
59580@@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
59581 parent ? (char *) parent->def->name : "<no-parent>",
59582 def->name, netfs_data, enable);
59583
59584- fscache_stat(&fscache_n_acquires);
59585+ fscache_stat_unchecked(&fscache_n_acquires);
59586
59587 /* if there's no parent cookie, then we don't create one here either */
59588 if (!parent) {
59589- fscache_stat(&fscache_n_acquires_null);
59590+ fscache_stat_unchecked(&fscache_n_acquires_null);
59591 _leave(" [no parent]");
59592 return NULL;
59593 }
59594@@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59595 /* allocate and initialise a cookie */
59596 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
59597 if (!cookie) {
59598- fscache_stat(&fscache_n_acquires_oom);
59599+ fscache_stat_unchecked(&fscache_n_acquires_oom);
59600 _leave(" [ENOMEM]");
59601 return NULL;
59602 }
59603@@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
59604
59605 switch (cookie->def->type) {
59606 case FSCACHE_COOKIE_TYPE_INDEX:
59607- fscache_stat(&fscache_n_cookie_index);
59608+ fscache_stat_unchecked(&fscache_n_cookie_index);
59609 break;
59610 case FSCACHE_COOKIE_TYPE_DATAFILE:
59611- fscache_stat(&fscache_n_cookie_data);
59612+ fscache_stat_unchecked(&fscache_n_cookie_data);
59613 break;
59614 default:
59615- fscache_stat(&fscache_n_cookie_special);
59616+ fscache_stat_unchecked(&fscache_n_cookie_special);
59617 break;
59618 }
59619
59620@@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59621 } else {
59622 atomic_dec(&parent->n_children);
59623 __fscache_cookie_put(cookie);
59624- fscache_stat(&fscache_n_acquires_nobufs);
59625+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
59626 _leave(" = NULL");
59627 return NULL;
59628 }
59629@@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59630 }
59631 }
59632
59633- fscache_stat(&fscache_n_acquires_ok);
59634+ fscache_stat_unchecked(&fscache_n_acquires_ok);
59635 _leave(" = %p", cookie);
59636 return cookie;
59637 }
59638@@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
59639 cache = fscache_select_cache_for_object(cookie->parent);
59640 if (!cache) {
59641 up_read(&fscache_addremove_sem);
59642- fscache_stat(&fscache_n_acquires_no_cache);
59643+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
59644 _leave(" = -ENOMEDIUM [no cache]");
59645 return -ENOMEDIUM;
59646 }
59647@@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
59648 object = cache->ops->alloc_object(cache, cookie);
59649 fscache_stat_d(&fscache_n_cop_alloc_object);
59650 if (IS_ERR(object)) {
59651- fscache_stat(&fscache_n_object_no_alloc);
59652+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
59653 ret = PTR_ERR(object);
59654 goto error;
59655 }
59656
59657- fscache_stat(&fscache_n_object_alloc);
59658+ fscache_stat_unchecked(&fscache_n_object_alloc);
59659
59660- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
59661+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
59662
59663 _debug("ALLOC OBJ%x: %s {%lx}",
59664 object->debug_id, cookie->def->name, object->events);
59665@@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
59666
59667 _enter("{%s}", cookie->def->name);
59668
59669- fscache_stat(&fscache_n_invalidates);
59670+ fscache_stat_unchecked(&fscache_n_invalidates);
59671
59672 /* Only permit invalidation of data files. Invalidating an index will
59673 * require the caller to release all its attachments to the tree rooted
59674@@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
59675 {
59676 struct fscache_object *object;
59677
59678- fscache_stat(&fscache_n_updates);
59679+ fscache_stat_unchecked(&fscache_n_updates);
59680
59681 if (!cookie) {
59682- fscache_stat(&fscache_n_updates_null);
59683+ fscache_stat_unchecked(&fscache_n_updates_null);
59684 _leave(" [no cookie]");
59685 return;
59686 }
59687@@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
59688 */
59689 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
59690 {
59691- fscache_stat(&fscache_n_relinquishes);
59692+ fscache_stat_unchecked(&fscache_n_relinquishes);
59693 if (retire)
59694- fscache_stat(&fscache_n_relinquishes_retire);
59695+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
59696
59697 if (!cookie) {
59698- fscache_stat(&fscache_n_relinquishes_null);
59699+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
59700 _leave(" [no cookie]");
59701 return;
59702 }
59703@@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
59704 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
59705 goto inconsistent;
59706
59707- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
59708+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
59709
59710 __fscache_use_cookie(cookie);
59711 if (fscache_submit_op(object, op) < 0)
59712diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
59713index 4226f66..0fb3f45 100644
59714--- a/fs/fscache/internal.h
59715+++ b/fs/fscache/internal.h
59716@@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
59717 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
59718 extern int fscache_wait_for_operation_activation(struct fscache_object *,
59719 struct fscache_operation *,
59720- atomic_t *,
59721- atomic_t *,
59722+ atomic_unchecked_t *,
59723+ atomic_unchecked_t *,
59724 void (*)(struct fscache_operation *));
59725 extern void fscache_invalidate_writes(struct fscache_cookie *);
59726
59727@@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
59728 * stats.c
59729 */
59730 #ifdef CONFIG_FSCACHE_STATS
59731-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59732-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59733+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59734+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59735
59736-extern atomic_t fscache_n_op_pend;
59737-extern atomic_t fscache_n_op_run;
59738-extern atomic_t fscache_n_op_enqueue;
59739-extern atomic_t fscache_n_op_deferred_release;
59740-extern atomic_t fscache_n_op_release;
59741-extern atomic_t fscache_n_op_gc;
59742-extern atomic_t fscache_n_op_cancelled;
59743-extern atomic_t fscache_n_op_rejected;
59744+extern atomic_unchecked_t fscache_n_op_pend;
59745+extern atomic_unchecked_t fscache_n_op_run;
59746+extern atomic_unchecked_t fscache_n_op_enqueue;
59747+extern atomic_unchecked_t fscache_n_op_deferred_release;
59748+extern atomic_unchecked_t fscache_n_op_release;
59749+extern atomic_unchecked_t fscache_n_op_gc;
59750+extern atomic_unchecked_t fscache_n_op_cancelled;
59751+extern atomic_unchecked_t fscache_n_op_rejected;
59752
59753-extern atomic_t fscache_n_attr_changed;
59754-extern atomic_t fscache_n_attr_changed_ok;
59755-extern atomic_t fscache_n_attr_changed_nobufs;
59756-extern atomic_t fscache_n_attr_changed_nomem;
59757-extern atomic_t fscache_n_attr_changed_calls;
59758+extern atomic_unchecked_t fscache_n_attr_changed;
59759+extern atomic_unchecked_t fscache_n_attr_changed_ok;
59760+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
59761+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
59762+extern atomic_unchecked_t fscache_n_attr_changed_calls;
59763
59764-extern atomic_t fscache_n_allocs;
59765-extern atomic_t fscache_n_allocs_ok;
59766-extern atomic_t fscache_n_allocs_wait;
59767-extern atomic_t fscache_n_allocs_nobufs;
59768-extern atomic_t fscache_n_allocs_intr;
59769-extern atomic_t fscache_n_allocs_object_dead;
59770-extern atomic_t fscache_n_alloc_ops;
59771-extern atomic_t fscache_n_alloc_op_waits;
59772+extern atomic_unchecked_t fscache_n_allocs;
59773+extern atomic_unchecked_t fscache_n_allocs_ok;
59774+extern atomic_unchecked_t fscache_n_allocs_wait;
59775+extern atomic_unchecked_t fscache_n_allocs_nobufs;
59776+extern atomic_unchecked_t fscache_n_allocs_intr;
59777+extern atomic_unchecked_t fscache_n_allocs_object_dead;
59778+extern atomic_unchecked_t fscache_n_alloc_ops;
59779+extern atomic_unchecked_t fscache_n_alloc_op_waits;
59780
59781-extern atomic_t fscache_n_retrievals;
59782-extern atomic_t fscache_n_retrievals_ok;
59783-extern atomic_t fscache_n_retrievals_wait;
59784-extern atomic_t fscache_n_retrievals_nodata;
59785-extern atomic_t fscache_n_retrievals_nobufs;
59786-extern atomic_t fscache_n_retrievals_intr;
59787-extern atomic_t fscache_n_retrievals_nomem;
59788-extern atomic_t fscache_n_retrievals_object_dead;
59789-extern atomic_t fscache_n_retrieval_ops;
59790-extern atomic_t fscache_n_retrieval_op_waits;
59791+extern atomic_unchecked_t fscache_n_retrievals;
59792+extern atomic_unchecked_t fscache_n_retrievals_ok;
59793+extern atomic_unchecked_t fscache_n_retrievals_wait;
59794+extern atomic_unchecked_t fscache_n_retrievals_nodata;
59795+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
59796+extern atomic_unchecked_t fscache_n_retrievals_intr;
59797+extern atomic_unchecked_t fscache_n_retrievals_nomem;
59798+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
59799+extern atomic_unchecked_t fscache_n_retrieval_ops;
59800+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
59801
59802-extern atomic_t fscache_n_stores;
59803-extern atomic_t fscache_n_stores_ok;
59804-extern atomic_t fscache_n_stores_again;
59805-extern atomic_t fscache_n_stores_nobufs;
59806-extern atomic_t fscache_n_stores_oom;
59807-extern atomic_t fscache_n_store_ops;
59808-extern atomic_t fscache_n_store_calls;
59809-extern atomic_t fscache_n_store_pages;
59810-extern atomic_t fscache_n_store_radix_deletes;
59811-extern atomic_t fscache_n_store_pages_over_limit;
59812+extern atomic_unchecked_t fscache_n_stores;
59813+extern atomic_unchecked_t fscache_n_stores_ok;
59814+extern atomic_unchecked_t fscache_n_stores_again;
59815+extern atomic_unchecked_t fscache_n_stores_nobufs;
59816+extern atomic_unchecked_t fscache_n_stores_oom;
59817+extern atomic_unchecked_t fscache_n_store_ops;
59818+extern atomic_unchecked_t fscache_n_store_calls;
59819+extern atomic_unchecked_t fscache_n_store_pages;
59820+extern atomic_unchecked_t fscache_n_store_radix_deletes;
59821+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
59822
59823-extern atomic_t fscache_n_store_vmscan_not_storing;
59824-extern atomic_t fscache_n_store_vmscan_gone;
59825-extern atomic_t fscache_n_store_vmscan_busy;
59826-extern atomic_t fscache_n_store_vmscan_cancelled;
59827-extern atomic_t fscache_n_store_vmscan_wait;
59828+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
59829+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
59830+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
59831+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
59832+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
59833
59834-extern atomic_t fscache_n_marks;
59835-extern atomic_t fscache_n_uncaches;
59836+extern atomic_unchecked_t fscache_n_marks;
59837+extern atomic_unchecked_t fscache_n_uncaches;
59838
59839-extern atomic_t fscache_n_acquires;
59840-extern atomic_t fscache_n_acquires_null;
59841-extern atomic_t fscache_n_acquires_no_cache;
59842-extern atomic_t fscache_n_acquires_ok;
59843-extern atomic_t fscache_n_acquires_nobufs;
59844-extern atomic_t fscache_n_acquires_oom;
59845+extern atomic_unchecked_t fscache_n_acquires;
59846+extern atomic_unchecked_t fscache_n_acquires_null;
59847+extern atomic_unchecked_t fscache_n_acquires_no_cache;
59848+extern atomic_unchecked_t fscache_n_acquires_ok;
59849+extern atomic_unchecked_t fscache_n_acquires_nobufs;
59850+extern atomic_unchecked_t fscache_n_acquires_oom;
59851
59852-extern atomic_t fscache_n_invalidates;
59853-extern atomic_t fscache_n_invalidates_run;
59854+extern atomic_unchecked_t fscache_n_invalidates;
59855+extern atomic_unchecked_t fscache_n_invalidates_run;
59856
59857-extern atomic_t fscache_n_updates;
59858-extern atomic_t fscache_n_updates_null;
59859-extern atomic_t fscache_n_updates_run;
59860+extern atomic_unchecked_t fscache_n_updates;
59861+extern atomic_unchecked_t fscache_n_updates_null;
59862+extern atomic_unchecked_t fscache_n_updates_run;
59863
59864-extern atomic_t fscache_n_relinquishes;
59865-extern atomic_t fscache_n_relinquishes_null;
59866-extern atomic_t fscache_n_relinquishes_waitcrt;
59867-extern atomic_t fscache_n_relinquishes_retire;
59868+extern atomic_unchecked_t fscache_n_relinquishes;
59869+extern atomic_unchecked_t fscache_n_relinquishes_null;
59870+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
59871+extern atomic_unchecked_t fscache_n_relinquishes_retire;
59872
59873-extern atomic_t fscache_n_cookie_index;
59874-extern atomic_t fscache_n_cookie_data;
59875-extern atomic_t fscache_n_cookie_special;
59876+extern atomic_unchecked_t fscache_n_cookie_index;
59877+extern atomic_unchecked_t fscache_n_cookie_data;
59878+extern atomic_unchecked_t fscache_n_cookie_special;
59879
59880-extern atomic_t fscache_n_object_alloc;
59881-extern atomic_t fscache_n_object_no_alloc;
59882-extern atomic_t fscache_n_object_lookups;
59883-extern atomic_t fscache_n_object_lookups_negative;
59884-extern atomic_t fscache_n_object_lookups_positive;
59885-extern atomic_t fscache_n_object_lookups_timed_out;
59886-extern atomic_t fscache_n_object_created;
59887-extern atomic_t fscache_n_object_avail;
59888-extern atomic_t fscache_n_object_dead;
59889+extern atomic_unchecked_t fscache_n_object_alloc;
59890+extern atomic_unchecked_t fscache_n_object_no_alloc;
59891+extern atomic_unchecked_t fscache_n_object_lookups;
59892+extern atomic_unchecked_t fscache_n_object_lookups_negative;
59893+extern atomic_unchecked_t fscache_n_object_lookups_positive;
59894+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
59895+extern atomic_unchecked_t fscache_n_object_created;
59896+extern atomic_unchecked_t fscache_n_object_avail;
59897+extern atomic_unchecked_t fscache_n_object_dead;
59898
59899-extern atomic_t fscache_n_checkaux_none;
59900-extern atomic_t fscache_n_checkaux_okay;
59901-extern atomic_t fscache_n_checkaux_update;
59902-extern atomic_t fscache_n_checkaux_obsolete;
59903+extern atomic_unchecked_t fscache_n_checkaux_none;
59904+extern atomic_unchecked_t fscache_n_checkaux_okay;
59905+extern atomic_unchecked_t fscache_n_checkaux_update;
59906+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
59907
59908 extern atomic_t fscache_n_cop_alloc_object;
59909 extern atomic_t fscache_n_cop_lookup_object;
59910@@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
59911 atomic_inc(stat);
59912 }
59913
59914+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
59915+{
59916+ atomic_inc_unchecked(stat);
59917+}
59918+
59919 static inline void fscache_stat_d(atomic_t *stat)
59920 {
59921 atomic_dec(stat);
59922@@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
59923
59924 #define __fscache_stat(stat) (NULL)
59925 #define fscache_stat(stat) do {} while (0)
59926+#define fscache_stat_unchecked(stat) do {} while (0)
59927 #define fscache_stat_d(stat) do {} while (0)
59928 #endif
59929
59930diff --git a/fs/fscache/object.c b/fs/fscache/object.c
59931index 53d35c5..5d68ed4 100644
59932--- a/fs/fscache/object.c
59933+++ b/fs/fscache/object.c
59934@@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
59935 _debug("LOOKUP \"%s\" in \"%s\"",
59936 cookie->def->name, object->cache->tag->name);
59937
59938- fscache_stat(&fscache_n_object_lookups);
59939+ fscache_stat_unchecked(&fscache_n_object_lookups);
59940 fscache_stat(&fscache_n_cop_lookup_object);
59941 ret = object->cache->ops->lookup_object(object);
59942 fscache_stat_d(&fscache_n_cop_lookup_object);
59943@@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
59944 if (ret == -ETIMEDOUT) {
59945 /* probably stuck behind another object, so move this one to
59946 * the back of the queue */
59947- fscache_stat(&fscache_n_object_lookups_timed_out);
59948+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
59949 _leave(" [timeout]");
59950 return NO_TRANSIT;
59951 }
59952@@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
59953 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
59954
59955 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
59956- fscache_stat(&fscache_n_object_lookups_negative);
59957+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
59958
59959 /* Allow write requests to begin stacking up and read requests to begin
59960 * returning ENODATA.
59961@@ -524,7 +524,7 @@ void fscache_obtained_object(struct fscache_object *object)
59962 /* if we were still looking up, then we must have a positive lookup
59963 * result, in which case there may be data available */
59964 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
59965- fscache_stat(&fscache_n_object_lookups_positive);
59966+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
59967
59968 /* We do (presumably) have data */
59969 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
59970@@ -536,7 +536,7 @@ void fscache_obtained_object(struct fscache_object *object)
59971 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
59972 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
59973 } else {
59974- fscache_stat(&fscache_n_object_created);
59975+ fscache_stat_unchecked(&fscache_n_object_created);
59976 }
59977
59978 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
59979@@ -572,7 +572,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
59980 fscache_stat_d(&fscache_n_cop_lookup_complete);
59981
59982 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
59983- fscache_stat(&fscache_n_object_avail);
59984+ fscache_stat_unchecked(&fscache_n_object_avail);
59985
59986 _leave("");
59987 return transit_to(JUMPSTART_DEPS);
59988@@ -719,7 +719,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
59989
59990 /* this just shifts the object release to the work processor */
59991 fscache_put_object(object);
59992- fscache_stat(&fscache_n_object_dead);
59993+ fscache_stat_unchecked(&fscache_n_object_dead);
59994
59995 _leave("");
59996 return transit_to(OBJECT_DEAD);
59997@@ -884,7 +884,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
59998 enum fscache_checkaux result;
59999
60000 if (!object->cookie->def->check_aux) {
60001- fscache_stat(&fscache_n_checkaux_none);
60002+ fscache_stat_unchecked(&fscache_n_checkaux_none);
60003 return FSCACHE_CHECKAUX_OKAY;
60004 }
60005
60006@@ -893,17 +893,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60007 switch (result) {
60008 /* entry okay as is */
60009 case FSCACHE_CHECKAUX_OKAY:
60010- fscache_stat(&fscache_n_checkaux_okay);
60011+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
60012 break;
60013
60014 /* entry requires update */
60015 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
60016- fscache_stat(&fscache_n_checkaux_update);
60017+ fscache_stat_unchecked(&fscache_n_checkaux_update);
60018 break;
60019
60020 /* entry requires deletion */
60021 case FSCACHE_CHECKAUX_OBSOLETE:
60022- fscache_stat(&fscache_n_checkaux_obsolete);
60023+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
60024 break;
60025
60026 default:
60027@@ -989,7 +989,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
60028 {
60029 const struct fscache_state *s;
60030
60031- fscache_stat(&fscache_n_invalidates_run);
60032+ fscache_stat_unchecked(&fscache_n_invalidates_run);
60033 fscache_stat(&fscache_n_cop_invalidate_object);
60034 s = _fscache_invalidate_object(object, event);
60035 fscache_stat_d(&fscache_n_cop_invalidate_object);
60036@@ -1004,7 +1004,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
60037 {
60038 _enter("{OBJ%x},%d", object->debug_id, event);
60039
60040- fscache_stat(&fscache_n_updates_run);
60041+ fscache_stat_unchecked(&fscache_n_updates_run);
60042 fscache_stat(&fscache_n_cop_update_object);
60043 object->cache->ops->update_object(object);
60044 fscache_stat_d(&fscache_n_cop_update_object);
60045diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
60046index 318071a..379938b 100644
60047--- a/fs/fscache/operation.c
60048+++ b/fs/fscache/operation.c
60049@@ -17,7 +17,7 @@
60050 #include <linux/slab.h>
60051 #include "internal.h"
60052
60053-atomic_t fscache_op_debug_id;
60054+atomic_unchecked_t fscache_op_debug_id;
60055 EXPORT_SYMBOL(fscache_op_debug_id);
60056
60057 /**
60058@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
60059 ASSERTCMP(atomic_read(&op->usage), >, 0);
60060 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
60061
60062- fscache_stat(&fscache_n_op_enqueue);
60063+ fscache_stat_unchecked(&fscache_n_op_enqueue);
60064 switch (op->flags & FSCACHE_OP_TYPE) {
60065 case FSCACHE_OP_ASYNC:
60066 _debug("queue async");
60067@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
60068 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
60069 if (op->processor)
60070 fscache_enqueue_operation(op);
60071- fscache_stat(&fscache_n_op_run);
60072+ fscache_stat_unchecked(&fscache_n_op_run);
60073 }
60074
60075 /*
60076@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60077 if (object->n_in_progress > 0) {
60078 atomic_inc(&op->usage);
60079 list_add_tail(&op->pend_link, &object->pending_ops);
60080- fscache_stat(&fscache_n_op_pend);
60081+ fscache_stat_unchecked(&fscache_n_op_pend);
60082 } else if (!list_empty(&object->pending_ops)) {
60083 atomic_inc(&op->usage);
60084 list_add_tail(&op->pend_link, &object->pending_ops);
60085- fscache_stat(&fscache_n_op_pend);
60086+ fscache_stat_unchecked(&fscache_n_op_pend);
60087 fscache_start_operations(object);
60088 } else {
60089 ASSERTCMP(object->n_in_progress, ==, 0);
60090@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60091 object->n_exclusive++; /* reads and writes must wait */
60092 atomic_inc(&op->usage);
60093 list_add_tail(&op->pend_link, &object->pending_ops);
60094- fscache_stat(&fscache_n_op_pend);
60095+ fscache_stat_unchecked(&fscache_n_op_pend);
60096 ret = 0;
60097 } else {
60098 /* If we're in any other state, there must have been an I/O
60099@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
60100 if (object->n_exclusive > 0) {
60101 atomic_inc(&op->usage);
60102 list_add_tail(&op->pend_link, &object->pending_ops);
60103- fscache_stat(&fscache_n_op_pend);
60104+ fscache_stat_unchecked(&fscache_n_op_pend);
60105 } else if (!list_empty(&object->pending_ops)) {
60106 atomic_inc(&op->usage);
60107 list_add_tail(&op->pend_link, &object->pending_ops);
60108- fscache_stat(&fscache_n_op_pend);
60109+ fscache_stat_unchecked(&fscache_n_op_pend);
60110 fscache_start_operations(object);
60111 } else {
60112 ASSERTCMP(object->n_exclusive, ==, 0);
60113@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
60114 object->n_ops++;
60115 atomic_inc(&op->usage);
60116 list_add_tail(&op->pend_link, &object->pending_ops);
60117- fscache_stat(&fscache_n_op_pend);
60118+ fscache_stat_unchecked(&fscache_n_op_pend);
60119 ret = 0;
60120 } else if (fscache_object_is_dying(object)) {
60121- fscache_stat(&fscache_n_op_rejected);
60122+ fscache_stat_unchecked(&fscache_n_op_rejected);
60123 op->state = FSCACHE_OP_ST_CANCELLED;
60124 ret = -ENOBUFS;
60125 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
60126@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
60127 ret = -EBUSY;
60128 if (op->state == FSCACHE_OP_ST_PENDING) {
60129 ASSERT(!list_empty(&op->pend_link));
60130- fscache_stat(&fscache_n_op_cancelled);
60131+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60132 list_del_init(&op->pend_link);
60133 if (do_cancel)
60134 do_cancel(op);
60135@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
60136 while (!list_empty(&object->pending_ops)) {
60137 op = list_entry(object->pending_ops.next,
60138 struct fscache_operation, pend_link);
60139- fscache_stat(&fscache_n_op_cancelled);
60140+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60141 list_del_init(&op->pend_link);
60142
60143 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
60144@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
60145 op->state, ==, FSCACHE_OP_ST_CANCELLED);
60146 op->state = FSCACHE_OP_ST_DEAD;
60147
60148- fscache_stat(&fscache_n_op_release);
60149+ fscache_stat_unchecked(&fscache_n_op_release);
60150
60151 if (op->release) {
60152 op->release(op);
60153@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
60154 * lock, and defer it otherwise */
60155 if (!spin_trylock(&object->lock)) {
60156 _debug("defer put");
60157- fscache_stat(&fscache_n_op_deferred_release);
60158+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
60159
60160 cache = object->cache;
60161 spin_lock(&cache->op_gc_list_lock);
60162@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
60163
60164 _debug("GC DEFERRED REL OBJ%x OP%x",
60165 object->debug_id, op->debug_id);
60166- fscache_stat(&fscache_n_op_gc);
60167+ fscache_stat_unchecked(&fscache_n_op_gc);
60168
60169 ASSERTCMP(atomic_read(&op->usage), ==, 0);
60170 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
60171diff --git a/fs/fscache/page.c b/fs/fscache/page.c
60172index 7f5c658..6c1e164 100644
60173--- a/fs/fscache/page.c
60174+++ b/fs/fscache/page.c
60175@@ -61,7 +61,7 @@ try_again:
60176 val = radix_tree_lookup(&cookie->stores, page->index);
60177 if (!val) {
60178 rcu_read_unlock();
60179- fscache_stat(&fscache_n_store_vmscan_not_storing);
60180+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
60181 __fscache_uncache_page(cookie, page);
60182 return true;
60183 }
60184@@ -91,11 +91,11 @@ try_again:
60185 spin_unlock(&cookie->stores_lock);
60186
60187 if (xpage) {
60188- fscache_stat(&fscache_n_store_vmscan_cancelled);
60189- fscache_stat(&fscache_n_store_radix_deletes);
60190+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
60191+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60192 ASSERTCMP(xpage, ==, page);
60193 } else {
60194- fscache_stat(&fscache_n_store_vmscan_gone);
60195+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
60196 }
60197
60198 wake_up_bit(&cookie->flags, 0);
60199@@ -110,11 +110,11 @@ page_busy:
60200 * sleeping on memory allocation, so we may need to impose a timeout
60201 * too. */
60202 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60203- fscache_stat(&fscache_n_store_vmscan_busy);
60204+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60205 return false;
60206 }
60207
60208- fscache_stat(&fscache_n_store_vmscan_wait);
60209+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60210 __fscache_wait_on_page_write(cookie, page);
60211 gfp &= ~__GFP_WAIT;
60212 goto try_again;
60213@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60214 FSCACHE_COOKIE_STORING_TAG);
60215 if (!radix_tree_tag_get(&cookie->stores, page->index,
60216 FSCACHE_COOKIE_PENDING_TAG)) {
60217- fscache_stat(&fscache_n_store_radix_deletes);
60218+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60219 xpage = radix_tree_delete(&cookie->stores, page->index);
60220 }
60221 spin_unlock(&cookie->stores_lock);
60222@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60223
60224 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60225
60226- fscache_stat(&fscache_n_attr_changed_calls);
60227+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60228
60229 if (fscache_object_is_active(object)) {
60230 fscache_stat(&fscache_n_cop_attr_changed);
60231@@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60232
60233 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60234
60235- fscache_stat(&fscache_n_attr_changed);
60236+ fscache_stat_unchecked(&fscache_n_attr_changed);
60237
60238 op = kzalloc(sizeof(*op), GFP_KERNEL);
60239 if (!op) {
60240- fscache_stat(&fscache_n_attr_changed_nomem);
60241+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60242 _leave(" = -ENOMEM");
60243 return -ENOMEM;
60244 }
60245@@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60246 if (fscache_submit_exclusive_op(object, op) < 0)
60247 goto nobufs;
60248 spin_unlock(&cookie->lock);
60249- fscache_stat(&fscache_n_attr_changed_ok);
60250+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60251 fscache_put_operation(op);
60252 _leave(" = 0");
60253 return 0;
60254@@ -225,7 +225,7 @@ nobufs:
60255 kfree(op);
60256 if (wake_cookie)
60257 __fscache_wake_unused_cookie(cookie);
60258- fscache_stat(&fscache_n_attr_changed_nobufs);
60259+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60260 _leave(" = %d", -ENOBUFS);
60261 return -ENOBUFS;
60262 }
60263@@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60264 /* allocate a retrieval operation and attempt to submit it */
60265 op = kzalloc(sizeof(*op), GFP_NOIO);
60266 if (!op) {
60267- fscache_stat(&fscache_n_retrievals_nomem);
60268+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60269 return NULL;
60270 }
60271
60272@@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60273 return 0;
60274 }
60275
60276- fscache_stat(&fscache_n_retrievals_wait);
60277+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
60278
60279 jif = jiffies;
60280 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60281 fscache_wait_bit_interruptible,
60282 TASK_INTERRUPTIBLE) != 0) {
60283- fscache_stat(&fscache_n_retrievals_intr);
60284+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60285 _leave(" = -ERESTARTSYS");
60286 return -ERESTARTSYS;
60287 }
60288@@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60289 */
60290 int fscache_wait_for_operation_activation(struct fscache_object *object,
60291 struct fscache_operation *op,
60292- atomic_t *stat_op_waits,
60293- atomic_t *stat_object_dead,
60294+ atomic_unchecked_t *stat_op_waits,
60295+ atomic_unchecked_t *stat_object_dead,
60296 void (*do_cancel)(struct fscache_operation *))
60297 {
60298 int ret;
60299@@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60300
60301 _debug(">>> WT");
60302 if (stat_op_waits)
60303- fscache_stat(stat_op_waits);
60304+ fscache_stat_unchecked(stat_op_waits);
60305 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60306 fscache_wait_bit_interruptible,
60307 TASK_INTERRUPTIBLE) != 0) {
60308@@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60309 check_if_dead:
60310 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60311 if (stat_object_dead)
60312- fscache_stat(stat_object_dead);
60313+ fscache_stat_unchecked(stat_object_dead);
60314 _leave(" = -ENOBUFS [cancelled]");
60315 return -ENOBUFS;
60316 }
60317@@ -366,7 +366,7 @@ check_if_dead:
60318 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60319 fscache_cancel_op(op, do_cancel);
60320 if (stat_object_dead)
60321- fscache_stat(stat_object_dead);
60322+ fscache_stat_unchecked(stat_object_dead);
60323 return -ENOBUFS;
60324 }
60325 return 0;
60326@@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60327
60328 _enter("%p,%p,,,", cookie, page);
60329
60330- fscache_stat(&fscache_n_retrievals);
60331+ fscache_stat_unchecked(&fscache_n_retrievals);
60332
60333 if (hlist_empty(&cookie->backing_objects))
60334 goto nobufs;
60335@@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60336 goto nobufs_unlock_dec;
60337 spin_unlock(&cookie->lock);
60338
60339- fscache_stat(&fscache_n_retrieval_ops);
60340+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60341
60342 /* pin the netfs read context in case we need to do the actual netfs
60343 * read because we've encountered a cache read failure */
60344@@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60345
60346 error:
60347 if (ret == -ENOMEM)
60348- fscache_stat(&fscache_n_retrievals_nomem);
60349+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60350 else if (ret == -ERESTARTSYS)
60351- fscache_stat(&fscache_n_retrievals_intr);
60352+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60353 else if (ret == -ENODATA)
60354- fscache_stat(&fscache_n_retrievals_nodata);
60355+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60356 else if (ret < 0)
60357- fscache_stat(&fscache_n_retrievals_nobufs);
60358+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60359 else
60360- fscache_stat(&fscache_n_retrievals_ok);
60361+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60362
60363 fscache_put_retrieval(op);
60364 _leave(" = %d", ret);
60365@@ -490,7 +490,7 @@ nobufs_unlock:
60366 __fscache_wake_unused_cookie(cookie);
60367 kfree(op);
60368 nobufs:
60369- fscache_stat(&fscache_n_retrievals_nobufs);
60370+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60371 _leave(" = -ENOBUFS");
60372 return -ENOBUFS;
60373 }
60374@@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60375
60376 _enter("%p,,%d,,,", cookie, *nr_pages);
60377
60378- fscache_stat(&fscache_n_retrievals);
60379+ fscache_stat_unchecked(&fscache_n_retrievals);
60380
60381 if (hlist_empty(&cookie->backing_objects))
60382 goto nobufs;
60383@@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60384 goto nobufs_unlock_dec;
60385 spin_unlock(&cookie->lock);
60386
60387- fscache_stat(&fscache_n_retrieval_ops);
60388+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60389
60390 /* pin the netfs read context in case we need to do the actual netfs
60391 * read because we've encountered a cache read failure */
60392@@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60393
60394 error:
60395 if (ret == -ENOMEM)
60396- fscache_stat(&fscache_n_retrievals_nomem);
60397+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60398 else if (ret == -ERESTARTSYS)
60399- fscache_stat(&fscache_n_retrievals_intr);
60400+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60401 else if (ret == -ENODATA)
60402- fscache_stat(&fscache_n_retrievals_nodata);
60403+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60404 else if (ret < 0)
60405- fscache_stat(&fscache_n_retrievals_nobufs);
60406+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60407 else
60408- fscache_stat(&fscache_n_retrievals_ok);
60409+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60410
60411 fscache_put_retrieval(op);
60412 _leave(" = %d", ret);
60413@@ -621,7 +621,7 @@ nobufs_unlock:
60414 if (wake_cookie)
60415 __fscache_wake_unused_cookie(cookie);
60416 nobufs:
60417- fscache_stat(&fscache_n_retrievals_nobufs);
60418+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60419 _leave(" = -ENOBUFS");
60420 return -ENOBUFS;
60421 }
60422@@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60423
60424 _enter("%p,%p,,,", cookie, page);
60425
60426- fscache_stat(&fscache_n_allocs);
60427+ fscache_stat_unchecked(&fscache_n_allocs);
60428
60429 if (hlist_empty(&cookie->backing_objects))
60430 goto nobufs;
60431@@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60432 goto nobufs_unlock_dec;
60433 spin_unlock(&cookie->lock);
60434
60435- fscache_stat(&fscache_n_alloc_ops);
60436+ fscache_stat_unchecked(&fscache_n_alloc_ops);
60437
60438 ret = fscache_wait_for_operation_activation(
60439 object, &op->op,
60440@@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60441
60442 error:
60443 if (ret == -ERESTARTSYS)
60444- fscache_stat(&fscache_n_allocs_intr);
60445+ fscache_stat_unchecked(&fscache_n_allocs_intr);
60446 else if (ret < 0)
60447- fscache_stat(&fscache_n_allocs_nobufs);
60448+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60449 else
60450- fscache_stat(&fscache_n_allocs_ok);
60451+ fscache_stat_unchecked(&fscache_n_allocs_ok);
60452
60453 fscache_put_retrieval(op);
60454 _leave(" = %d", ret);
60455@@ -715,7 +715,7 @@ nobufs_unlock:
60456 if (wake_cookie)
60457 __fscache_wake_unused_cookie(cookie);
60458 nobufs:
60459- fscache_stat(&fscache_n_allocs_nobufs);
60460+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60461 _leave(" = -ENOBUFS");
60462 return -ENOBUFS;
60463 }
60464@@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60465
60466 spin_lock(&cookie->stores_lock);
60467
60468- fscache_stat(&fscache_n_store_calls);
60469+ fscache_stat_unchecked(&fscache_n_store_calls);
60470
60471 /* find a page to store */
60472 page = NULL;
60473@@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60474 page = results[0];
60475 _debug("gang %d [%lx]", n, page->index);
60476 if (page->index > op->store_limit) {
60477- fscache_stat(&fscache_n_store_pages_over_limit);
60478+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
60479 goto superseded;
60480 }
60481
60482@@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60483 spin_unlock(&cookie->stores_lock);
60484 spin_unlock(&object->lock);
60485
60486- fscache_stat(&fscache_n_store_pages);
60487+ fscache_stat_unchecked(&fscache_n_store_pages);
60488 fscache_stat(&fscache_n_cop_write_page);
60489 ret = object->cache->ops->write_page(op, page);
60490 fscache_stat_d(&fscache_n_cop_write_page);
60491@@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60492 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60493 ASSERT(PageFsCache(page));
60494
60495- fscache_stat(&fscache_n_stores);
60496+ fscache_stat_unchecked(&fscache_n_stores);
60497
60498 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
60499 _leave(" = -ENOBUFS [invalidating]");
60500@@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60501 spin_unlock(&cookie->stores_lock);
60502 spin_unlock(&object->lock);
60503
60504- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
60505+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60506 op->store_limit = object->store_limit;
60507
60508 __fscache_use_cookie(cookie);
60509@@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60510
60511 spin_unlock(&cookie->lock);
60512 radix_tree_preload_end();
60513- fscache_stat(&fscache_n_store_ops);
60514- fscache_stat(&fscache_n_stores_ok);
60515+ fscache_stat_unchecked(&fscache_n_store_ops);
60516+ fscache_stat_unchecked(&fscache_n_stores_ok);
60517
60518 /* the work queue now carries its own ref on the object */
60519 fscache_put_operation(&op->op);
60520@@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60521 return 0;
60522
60523 already_queued:
60524- fscache_stat(&fscache_n_stores_again);
60525+ fscache_stat_unchecked(&fscache_n_stores_again);
60526 already_pending:
60527 spin_unlock(&cookie->stores_lock);
60528 spin_unlock(&object->lock);
60529 spin_unlock(&cookie->lock);
60530 radix_tree_preload_end();
60531 kfree(op);
60532- fscache_stat(&fscache_n_stores_ok);
60533+ fscache_stat_unchecked(&fscache_n_stores_ok);
60534 _leave(" = 0");
60535 return 0;
60536
60537@@ -1024,14 +1024,14 @@ nobufs:
60538 kfree(op);
60539 if (wake_cookie)
60540 __fscache_wake_unused_cookie(cookie);
60541- fscache_stat(&fscache_n_stores_nobufs);
60542+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
60543 _leave(" = -ENOBUFS");
60544 return -ENOBUFS;
60545
60546 nomem_free:
60547 kfree(op);
60548 nomem:
60549- fscache_stat(&fscache_n_stores_oom);
60550+ fscache_stat_unchecked(&fscache_n_stores_oom);
60551 _leave(" = -ENOMEM");
60552 return -ENOMEM;
60553 }
60554@@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
60555 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60556 ASSERTCMP(page, !=, NULL);
60557
60558- fscache_stat(&fscache_n_uncaches);
60559+ fscache_stat_unchecked(&fscache_n_uncaches);
60560
60561 /* cache withdrawal may beat us to it */
60562 if (!PageFsCache(page))
60563@@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
60564 struct fscache_cookie *cookie = op->op.object->cookie;
60565
60566 #ifdef CONFIG_FSCACHE_STATS
60567- atomic_inc(&fscache_n_marks);
60568+ atomic_inc_unchecked(&fscache_n_marks);
60569 #endif
60570
60571 _debug("- mark %p{%lx}", page, page->index);
60572diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
60573index 40d13c7..ddf52b9 100644
60574--- a/fs/fscache/stats.c
60575+++ b/fs/fscache/stats.c
60576@@ -18,99 +18,99 @@
60577 /*
60578 * operation counters
60579 */
60580-atomic_t fscache_n_op_pend;
60581-atomic_t fscache_n_op_run;
60582-atomic_t fscache_n_op_enqueue;
60583-atomic_t fscache_n_op_requeue;
60584-atomic_t fscache_n_op_deferred_release;
60585-atomic_t fscache_n_op_release;
60586-atomic_t fscache_n_op_gc;
60587-atomic_t fscache_n_op_cancelled;
60588-atomic_t fscache_n_op_rejected;
60589+atomic_unchecked_t fscache_n_op_pend;
60590+atomic_unchecked_t fscache_n_op_run;
60591+atomic_unchecked_t fscache_n_op_enqueue;
60592+atomic_unchecked_t fscache_n_op_requeue;
60593+atomic_unchecked_t fscache_n_op_deferred_release;
60594+atomic_unchecked_t fscache_n_op_release;
60595+atomic_unchecked_t fscache_n_op_gc;
60596+atomic_unchecked_t fscache_n_op_cancelled;
60597+atomic_unchecked_t fscache_n_op_rejected;
60598
60599-atomic_t fscache_n_attr_changed;
60600-atomic_t fscache_n_attr_changed_ok;
60601-atomic_t fscache_n_attr_changed_nobufs;
60602-atomic_t fscache_n_attr_changed_nomem;
60603-atomic_t fscache_n_attr_changed_calls;
60604+atomic_unchecked_t fscache_n_attr_changed;
60605+atomic_unchecked_t fscache_n_attr_changed_ok;
60606+atomic_unchecked_t fscache_n_attr_changed_nobufs;
60607+atomic_unchecked_t fscache_n_attr_changed_nomem;
60608+atomic_unchecked_t fscache_n_attr_changed_calls;
60609
60610-atomic_t fscache_n_allocs;
60611-atomic_t fscache_n_allocs_ok;
60612-atomic_t fscache_n_allocs_wait;
60613-atomic_t fscache_n_allocs_nobufs;
60614-atomic_t fscache_n_allocs_intr;
60615-atomic_t fscache_n_allocs_object_dead;
60616-atomic_t fscache_n_alloc_ops;
60617-atomic_t fscache_n_alloc_op_waits;
60618+atomic_unchecked_t fscache_n_allocs;
60619+atomic_unchecked_t fscache_n_allocs_ok;
60620+atomic_unchecked_t fscache_n_allocs_wait;
60621+atomic_unchecked_t fscache_n_allocs_nobufs;
60622+atomic_unchecked_t fscache_n_allocs_intr;
60623+atomic_unchecked_t fscache_n_allocs_object_dead;
60624+atomic_unchecked_t fscache_n_alloc_ops;
60625+atomic_unchecked_t fscache_n_alloc_op_waits;
60626
60627-atomic_t fscache_n_retrievals;
60628-atomic_t fscache_n_retrievals_ok;
60629-atomic_t fscache_n_retrievals_wait;
60630-atomic_t fscache_n_retrievals_nodata;
60631-atomic_t fscache_n_retrievals_nobufs;
60632-atomic_t fscache_n_retrievals_intr;
60633-atomic_t fscache_n_retrievals_nomem;
60634-atomic_t fscache_n_retrievals_object_dead;
60635-atomic_t fscache_n_retrieval_ops;
60636-atomic_t fscache_n_retrieval_op_waits;
60637+atomic_unchecked_t fscache_n_retrievals;
60638+atomic_unchecked_t fscache_n_retrievals_ok;
60639+atomic_unchecked_t fscache_n_retrievals_wait;
60640+atomic_unchecked_t fscache_n_retrievals_nodata;
60641+atomic_unchecked_t fscache_n_retrievals_nobufs;
60642+atomic_unchecked_t fscache_n_retrievals_intr;
60643+atomic_unchecked_t fscache_n_retrievals_nomem;
60644+atomic_unchecked_t fscache_n_retrievals_object_dead;
60645+atomic_unchecked_t fscache_n_retrieval_ops;
60646+atomic_unchecked_t fscache_n_retrieval_op_waits;
60647
60648-atomic_t fscache_n_stores;
60649-atomic_t fscache_n_stores_ok;
60650-atomic_t fscache_n_stores_again;
60651-atomic_t fscache_n_stores_nobufs;
60652-atomic_t fscache_n_stores_oom;
60653-atomic_t fscache_n_store_ops;
60654-atomic_t fscache_n_store_calls;
60655-atomic_t fscache_n_store_pages;
60656-atomic_t fscache_n_store_radix_deletes;
60657-atomic_t fscache_n_store_pages_over_limit;
60658+atomic_unchecked_t fscache_n_stores;
60659+atomic_unchecked_t fscache_n_stores_ok;
60660+atomic_unchecked_t fscache_n_stores_again;
60661+atomic_unchecked_t fscache_n_stores_nobufs;
60662+atomic_unchecked_t fscache_n_stores_oom;
60663+atomic_unchecked_t fscache_n_store_ops;
60664+atomic_unchecked_t fscache_n_store_calls;
60665+atomic_unchecked_t fscache_n_store_pages;
60666+atomic_unchecked_t fscache_n_store_radix_deletes;
60667+atomic_unchecked_t fscache_n_store_pages_over_limit;
60668
60669-atomic_t fscache_n_store_vmscan_not_storing;
60670-atomic_t fscache_n_store_vmscan_gone;
60671-atomic_t fscache_n_store_vmscan_busy;
60672-atomic_t fscache_n_store_vmscan_cancelled;
60673-atomic_t fscache_n_store_vmscan_wait;
60674+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60675+atomic_unchecked_t fscache_n_store_vmscan_gone;
60676+atomic_unchecked_t fscache_n_store_vmscan_busy;
60677+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60678+atomic_unchecked_t fscache_n_store_vmscan_wait;
60679
60680-atomic_t fscache_n_marks;
60681-atomic_t fscache_n_uncaches;
60682+atomic_unchecked_t fscache_n_marks;
60683+atomic_unchecked_t fscache_n_uncaches;
60684
60685-atomic_t fscache_n_acquires;
60686-atomic_t fscache_n_acquires_null;
60687-atomic_t fscache_n_acquires_no_cache;
60688-atomic_t fscache_n_acquires_ok;
60689-atomic_t fscache_n_acquires_nobufs;
60690-atomic_t fscache_n_acquires_oom;
60691+atomic_unchecked_t fscache_n_acquires;
60692+atomic_unchecked_t fscache_n_acquires_null;
60693+atomic_unchecked_t fscache_n_acquires_no_cache;
60694+atomic_unchecked_t fscache_n_acquires_ok;
60695+atomic_unchecked_t fscache_n_acquires_nobufs;
60696+atomic_unchecked_t fscache_n_acquires_oom;
60697
60698-atomic_t fscache_n_invalidates;
60699-atomic_t fscache_n_invalidates_run;
60700+atomic_unchecked_t fscache_n_invalidates;
60701+atomic_unchecked_t fscache_n_invalidates_run;
60702
60703-atomic_t fscache_n_updates;
60704-atomic_t fscache_n_updates_null;
60705-atomic_t fscache_n_updates_run;
60706+atomic_unchecked_t fscache_n_updates;
60707+atomic_unchecked_t fscache_n_updates_null;
60708+atomic_unchecked_t fscache_n_updates_run;
60709
60710-atomic_t fscache_n_relinquishes;
60711-atomic_t fscache_n_relinquishes_null;
60712-atomic_t fscache_n_relinquishes_waitcrt;
60713-atomic_t fscache_n_relinquishes_retire;
60714+atomic_unchecked_t fscache_n_relinquishes;
60715+atomic_unchecked_t fscache_n_relinquishes_null;
60716+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60717+atomic_unchecked_t fscache_n_relinquishes_retire;
60718
60719-atomic_t fscache_n_cookie_index;
60720-atomic_t fscache_n_cookie_data;
60721-atomic_t fscache_n_cookie_special;
60722+atomic_unchecked_t fscache_n_cookie_index;
60723+atomic_unchecked_t fscache_n_cookie_data;
60724+atomic_unchecked_t fscache_n_cookie_special;
60725
60726-atomic_t fscache_n_object_alloc;
60727-atomic_t fscache_n_object_no_alloc;
60728-atomic_t fscache_n_object_lookups;
60729-atomic_t fscache_n_object_lookups_negative;
60730-atomic_t fscache_n_object_lookups_positive;
60731-atomic_t fscache_n_object_lookups_timed_out;
60732-atomic_t fscache_n_object_created;
60733-atomic_t fscache_n_object_avail;
60734-atomic_t fscache_n_object_dead;
60735+atomic_unchecked_t fscache_n_object_alloc;
60736+atomic_unchecked_t fscache_n_object_no_alloc;
60737+atomic_unchecked_t fscache_n_object_lookups;
60738+atomic_unchecked_t fscache_n_object_lookups_negative;
60739+atomic_unchecked_t fscache_n_object_lookups_positive;
60740+atomic_unchecked_t fscache_n_object_lookups_timed_out;
60741+atomic_unchecked_t fscache_n_object_created;
60742+atomic_unchecked_t fscache_n_object_avail;
60743+atomic_unchecked_t fscache_n_object_dead;
60744
60745-atomic_t fscache_n_checkaux_none;
60746-atomic_t fscache_n_checkaux_okay;
60747-atomic_t fscache_n_checkaux_update;
60748-atomic_t fscache_n_checkaux_obsolete;
60749+atomic_unchecked_t fscache_n_checkaux_none;
60750+atomic_unchecked_t fscache_n_checkaux_okay;
60751+atomic_unchecked_t fscache_n_checkaux_update;
60752+atomic_unchecked_t fscache_n_checkaux_obsolete;
60753
60754 atomic_t fscache_n_cop_alloc_object;
60755 atomic_t fscache_n_cop_lookup_object;
60756@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
60757 seq_puts(m, "FS-Cache statistics\n");
60758
60759 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
60760- atomic_read(&fscache_n_cookie_index),
60761- atomic_read(&fscache_n_cookie_data),
60762- atomic_read(&fscache_n_cookie_special));
60763+ atomic_read_unchecked(&fscache_n_cookie_index),
60764+ atomic_read_unchecked(&fscache_n_cookie_data),
60765+ atomic_read_unchecked(&fscache_n_cookie_special));
60766
60767 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
60768- atomic_read(&fscache_n_object_alloc),
60769- atomic_read(&fscache_n_object_no_alloc),
60770- atomic_read(&fscache_n_object_avail),
60771- atomic_read(&fscache_n_object_dead));
60772+ atomic_read_unchecked(&fscache_n_object_alloc),
60773+ atomic_read_unchecked(&fscache_n_object_no_alloc),
60774+ atomic_read_unchecked(&fscache_n_object_avail),
60775+ atomic_read_unchecked(&fscache_n_object_dead));
60776 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
60777- atomic_read(&fscache_n_checkaux_none),
60778- atomic_read(&fscache_n_checkaux_okay),
60779- atomic_read(&fscache_n_checkaux_update),
60780- atomic_read(&fscache_n_checkaux_obsolete));
60781+ atomic_read_unchecked(&fscache_n_checkaux_none),
60782+ atomic_read_unchecked(&fscache_n_checkaux_okay),
60783+ atomic_read_unchecked(&fscache_n_checkaux_update),
60784+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
60785
60786 seq_printf(m, "Pages : mrk=%u unc=%u\n",
60787- atomic_read(&fscache_n_marks),
60788- atomic_read(&fscache_n_uncaches));
60789+ atomic_read_unchecked(&fscache_n_marks),
60790+ atomic_read_unchecked(&fscache_n_uncaches));
60791
60792 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
60793 " oom=%u\n",
60794- atomic_read(&fscache_n_acquires),
60795- atomic_read(&fscache_n_acquires_null),
60796- atomic_read(&fscache_n_acquires_no_cache),
60797- atomic_read(&fscache_n_acquires_ok),
60798- atomic_read(&fscache_n_acquires_nobufs),
60799- atomic_read(&fscache_n_acquires_oom));
60800+ atomic_read_unchecked(&fscache_n_acquires),
60801+ atomic_read_unchecked(&fscache_n_acquires_null),
60802+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
60803+ atomic_read_unchecked(&fscache_n_acquires_ok),
60804+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
60805+ atomic_read_unchecked(&fscache_n_acquires_oom));
60806
60807 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
60808- atomic_read(&fscache_n_object_lookups),
60809- atomic_read(&fscache_n_object_lookups_negative),
60810- atomic_read(&fscache_n_object_lookups_positive),
60811- atomic_read(&fscache_n_object_created),
60812- atomic_read(&fscache_n_object_lookups_timed_out));
60813+ atomic_read_unchecked(&fscache_n_object_lookups),
60814+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
60815+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
60816+ atomic_read_unchecked(&fscache_n_object_created),
60817+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
60818
60819 seq_printf(m, "Invals : n=%u run=%u\n",
60820- atomic_read(&fscache_n_invalidates),
60821- atomic_read(&fscache_n_invalidates_run));
60822+ atomic_read_unchecked(&fscache_n_invalidates),
60823+ atomic_read_unchecked(&fscache_n_invalidates_run));
60824
60825 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
60826- atomic_read(&fscache_n_updates),
60827- atomic_read(&fscache_n_updates_null),
60828- atomic_read(&fscache_n_updates_run));
60829+ atomic_read_unchecked(&fscache_n_updates),
60830+ atomic_read_unchecked(&fscache_n_updates_null),
60831+ atomic_read_unchecked(&fscache_n_updates_run));
60832
60833 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
60834- atomic_read(&fscache_n_relinquishes),
60835- atomic_read(&fscache_n_relinquishes_null),
60836- atomic_read(&fscache_n_relinquishes_waitcrt),
60837- atomic_read(&fscache_n_relinquishes_retire));
60838+ atomic_read_unchecked(&fscache_n_relinquishes),
60839+ atomic_read_unchecked(&fscache_n_relinquishes_null),
60840+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
60841+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
60842
60843 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
60844- atomic_read(&fscache_n_attr_changed),
60845- atomic_read(&fscache_n_attr_changed_ok),
60846- atomic_read(&fscache_n_attr_changed_nobufs),
60847- atomic_read(&fscache_n_attr_changed_nomem),
60848- atomic_read(&fscache_n_attr_changed_calls));
60849+ atomic_read_unchecked(&fscache_n_attr_changed),
60850+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
60851+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
60852+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
60853+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
60854
60855 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
60856- atomic_read(&fscache_n_allocs),
60857- atomic_read(&fscache_n_allocs_ok),
60858- atomic_read(&fscache_n_allocs_wait),
60859- atomic_read(&fscache_n_allocs_nobufs),
60860- atomic_read(&fscache_n_allocs_intr));
60861+ atomic_read_unchecked(&fscache_n_allocs),
60862+ atomic_read_unchecked(&fscache_n_allocs_ok),
60863+ atomic_read_unchecked(&fscache_n_allocs_wait),
60864+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
60865+ atomic_read_unchecked(&fscache_n_allocs_intr));
60866 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
60867- atomic_read(&fscache_n_alloc_ops),
60868- atomic_read(&fscache_n_alloc_op_waits),
60869- atomic_read(&fscache_n_allocs_object_dead));
60870+ atomic_read_unchecked(&fscache_n_alloc_ops),
60871+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
60872+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
60873
60874 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
60875 " int=%u oom=%u\n",
60876- atomic_read(&fscache_n_retrievals),
60877- atomic_read(&fscache_n_retrievals_ok),
60878- atomic_read(&fscache_n_retrievals_wait),
60879- atomic_read(&fscache_n_retrievals_nodata),
60880- atomic_read(&fscache_n_retrievals_nobufs),
60881- atomic_read(&fscache_n_retrievals_intr),
60882- atomic_read(&fscache_n_retrievals_nomem));
60883+ atomic_read_unchecked(&fscache_n_retrievals),
60884+ atomic_read_unchecked(&fscache_n_retrievals_ok),
60885+ atomic_read_unchecked(&fscache_n_retrievals_wait),
60886+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
60887+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
60888+ atomic_read_unchecked(&fscache_n_retrievals_intr),
60889+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
60890 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
60891- atomic_read(&fscache_n_retrieval_ops),
60892- atomic_read(&fscache_n_retrieval_op_waits),
60893- atomic_read(&fscache_n_retrievals_object_dead));
60894+ atomic_read_unchecked(&fscache_n_retrieval_ops),
60895+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
60896+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
60897
60898 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
60899- atomic_read(&fscache_n_stores),
60900- atomic_read(&fscache_n_stores_ok),
60901- atomic_read(&fscache_n_stores_again),
60902- atomic_read(&fscache_n_stores_nobufs),
60903- atomic_read(&fscache_n_stores_oom));
60904+ atomic_read_unchecked(&fscache_n_stores),
60905+ atomic_read_unchecked(&fscache_n_stores_ok),
60906+ atomic_read_unchecked(&fscache_n_stores_again),
60907+ atomic_read_unchecked(&fscache_n_stores_nobufs),
60908+ atomic_read_unchecked(&fscache_n_stores_oom));
60909 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
60910- atomic_read(&fscache_n_store_ops),
60911- atomic_read(&fscache_n_store_calls),
60912- atomic_read(&fscache_n_store_pages),
60913- atomic_read(&fscache_n_store_radix_deletes),
60914- atomic_read(&fscache_n_store_pages_over_limit));
60915+ atomic_read_unchecked(&fscache_n_store_ops),
60916+ atomic_read_unchecked(&fscache_n_store_calls),
60917+ atomic_read_unchecked(&fscache_n_store_pages),
60918+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
60919+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
60920
60921 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
60922- atomic_read(&fscache_n_store_vmscan_not_storing),
60923- atomic_read(&fscache_n_store_vmscan_gone),
60924- atomic_read(&fscache_n_store_vmscan_busy),
60925- atomic_read(&fscache_n_store_vmscan_cancelled),
60926- atomic_read(&fscache_n_store_vmscan_wait));
60927+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
60928+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
60929+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
60930+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
60931+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
60932
60933 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
60934- atomic_read(&fscache_n_op_pend),
60935- atomic_read(&fscache_n_op_run),
60936- atomic_read(&fscache_n_op_enqueue),
60937- atomic_read(&fscache_n_op_cancelled),
60938- atomic_read(&fscache_n_op_rejected));
60939+ atomic_read_unchecked(&fscache_n_op_pend),
60940+ atomic_read_unchecked(&fscache_n_op_run),
60941+ atomic_read_unchecked(&fscache_n_op_enqueue),
60942+ atomic_read_unchecked(&fscache_n_op_cancelled),
60943+ atomic_read_unchecked(&fscache_n_op_rejected));
60944 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
60945- atomic_read(&fscache_n_op_deferred_release),
60946- atomic_read(&fscache_n_op_release),
60947- atomic_read(&fscache_n_op_gc));
60948+ atomic_read_unchecked(&fscache_n_op_deferred_release),
60949+ atomic_read_unchecked(&fscache_n_op_release),
60950+ atomic_read_unchecked(&fscache_n_op_gc));
60951
60952 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
60953 atomic_read(&fscache_n_cop_alloc_object),
60954diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
60955index b96a49b..9bfdc47 100644
60956--- a/fs/fuse/cuse.c
60957+++ b/fs/fuse/cuse.c
60958@@ -606,10 +606,12 @@ static int __init cuse_init(void)
60959 INIT_LIST_HEAD(&cuse_conntbl[i]);
60960
60961 /* inherit and extend fuse_dev_operations */
60962- cuse_channel_fops = fuse_dev_operations;
60963- cuse_channel_fops.owner = THIS_MODULE;
60964- cuse_channel_fops.open = cuse_channel_open;
60965- cuse_channel_fops.release = cuse_channel_release;
60966+ pax_open_kernel();
60967+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
60968+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
60969+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
60970+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
60971+ pax_close_kernel();
60972
60973 cuse_class = class_create(THIS_MODULE, "cuse");
60974 if (IS_ERR(cuse_class))
60975diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
60976index fa8cb4b..4acb935 100644
60977--- a/fs/fuse/dev.c
60978+++ b/fs/fuse/dev.c
60979@@ -1323,7 +1323,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
60980 ret = 0;
60981 pipe_lock(pipe);
60982
60983- if (!pipe->readers) {
60984+ if (!atomic_read(&pipe->readers)) {
60985 send_sig(SIGPIPE, current, 0);
60986 if (!ret)
60987 ret = -EPIPE;
60988@@ -1352,7 +1352,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
60989 page_nr++;
60990 ret += buf->len;
60991
60992- if (pipe->files)
60993+ if (atomic_read(&pipe->files))
60994 do_wakeup = 1;
60995 }
60996
60997diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
60998index c3eb2c4..98007d4 100644
60999--- a/fs/fuse/dir.c
61000+++ b/fs/fuse/dir.c
61001@@ -1408,7 +1408,7 @@ static char *read_link(struct dentry *dentry)
61002 return link;
61003 }
61004
61005-static void free_link(char *link)
61006+static void free_link(const char *link)
61007 {
61008 if (!IS_ERR(link))
61009 free_page((unsigned long) link);
61010diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
61011index db23ce1..9e6cd9d 100644
61012--- a/fs/hostfs/hostfs_kern.c
61013+++ b/fs/hostfs/hostfs_kern.c
61014@@ -895,7 +895,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
61015
61016 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
61017 {
61018- char *s = nd_get_link(nd);
61019+ const char *s = nd_get_link(nd);
61020 if (!IS_ERR(s))
61021 __putname(s);
61022 }
61023diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
61024index d19b30a..ef89c36 100644
61025--- a/fs/hugetlbfs/inode.c
61026+++ b/fs/hugetlbfs/inode.c
61027@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61028 struct mm_struct *mm = current->mm;
61029 struct vm_area_struct *vma;
61030 struct hstate *h = hstate_file(file);
61031+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
61032 struct vm_unmapped_area_info info;
61033
61034 if (len & ~huge_page_mask(h))
61035@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61036 return addr;
61037 }
61038
61039+#ifdef CONFIG_PAX_RANDMMAP
61040+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
61041+#endif
61042+
61043 if (addr) {
61044 addr = ALIGN(addr, huge_page_size(h));
61045 vma = find_vma(mm, addr);
61046- if (TASK_SIZE - len >= addr &&
61047- (!vma || addr + len <= vma->vm_start))
61048+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
61049 return addr;
61050 }
61051
61052 info.flags = 0;
61053 info.length = len;
61054 info.low_limit = TASK_UNMAPPED_BASE;
61055+
61056+#ifdef CONFIG_PAX_RANDMMAP
61057+ if (mm->pax_flags & MF_PAX_RANDMMAP)
61058+ info.low_limit += mm->delta_mmap;
61059+#endif
61060+
61061 info.high_limit = TASK_SIZE;
61062 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
61063 info.align_offset = 0;
61064@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
61065 };
61066 MODULE_ALIAS_FS("hugetlbfs");
61067
61068-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61069+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61070
61071 static int can_do_hugetlb_shm(void)
61072 {
61073diff --git a/fs/inode.c b/fs/inode.c
61074index 4bcdad3..1883822 100644
61075--- a/fs/inode.c
61076+++ b/fs/inode.c
61077@@ -841,8 +841,8 @@ unsigned int get_next_ino(void)
61078
61079 #ifdef CONFIG_SMP
61080 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
61081- static atomic_t shared_last_ino;
61082- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
61083+ static atomic_unchecked_t shared_last_ino;
61084+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
61085
61086 res = next - LAST_INO_BATCH;
61087 }
61088diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
61089index 4a6cf28..d3a29d3 100644
61090--- a/fs/jffs2/erase.c
61091+++ b/fs/jffs2/erase.c
61092@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
61093 struct jffs2_unknown_node marker = {
61094 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
61095 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61096- .totlen = cpu_to_je32(c->cleanmarker_size)
61097+ .totlen = cpu_to_je32(c->cleanmarker_size),
61098+ .hdr_crc = cpu_to_je32(0)
61099 };
61100
61101 jffs2_prealloc_raw_node_refs(c, jeb, 1);
61102diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
61103index a6597d6..41b30ec 100644
61104--- a/fs/jffs2/wbuf.c
61105+++ b/fs/jffs2/wbuf.c
61106@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
61107 {
61108 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
61109 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61110- .totlen = constant_cpu_to_je32(8)
61111+ .totlen = constant_cpu_to_je32(8),
61112+ .hdr_crc = constant_cpu_to_je32(0)
61113 };
61114
61115 /*
61116diff --git a/fs/jfs/super.c b/fs/jfs/super.c
61117index 6669aa2..36b033d 100644
61118--- a/fs/jfs/super.c
61119+++ b/fs/jfs/super.c
61120@@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
61121
61122 jfs_inode_cachep =
61123 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
61124- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
61125+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
61126 init_once);
61127 if (jfs_inode_cachep == NULL)
61128 return -ENOMEM;
61129diff --git a/fs/libfs.c b/fs/libfs.c
61130index a184424..944ddce 100644
61131--- a/fs/libfs.c
61132+++ b/fs/libfs.c
61133@@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61134
61135 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
61136 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
61137+ char d_name[sizeof(next->d_iname)];
61138+ const unsigned char *name;
61139+
61140 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
61141 if (!simple_positive(next)) {
61142 spin_unlock(&next->d_lock);
61143@@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61144
61145 spin_unlock(&next->d_lock);
61146 spin_unlock(&dentry->d_lock);
61147- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
61148+ name = next->d_name.name;
61149+ if (name == next->d_iname) {
61150+ memcpy(d_name, name, next->d_name.len);
61151+ name = d_name;
61152+ }
61153+ if (!dir_emit(ctx, name, next->d_name.len,
61154 next->d_inode->i_ino, dt_type(next->d_inode)))
61155 return 0;
61156 spin_lock(&dentry->d_lock);
61157@@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
61158 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
61159 void *cookie)
61160 {
61161- char *s = nd_get_link(nd);
61162+ const char *s = nd_get_link(nd);
61163 if (!IS_ERR(s))
61164 kfree(s);
61165 }
61166diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
61167index acd3947..1f896e2 100644
61168--- a/fs/lockd/clntproc.c
61169+++ b/fs/lockd/clntproc.c
61170@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
61171 /*
61172 * Cookie counter for NLM requests
61173 */
61174-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
61175+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
61176
61177 void nlmclnt_next_cookie(struct nlm_cookie *c)
61178 {
61179- u32 cookie = atomic_inc_return(&nlm_cookie);
61180+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
61181
61182 memcpy(c->data, &cookie, 4);
61183 c->len=4;
61184diff --git a/fs/locks.c b/fs/locks.c
61185index 92a0f0a..45a48f0 100644
61186--- a/fs/locks.c
61187+++ b/fs/locks.c
61188@@ -2219,16 +2219,16 @@ void locks_remove_flock(struct file *filp)
61189 return;
61190
61191 if (filp->f_op->flock) {
61192- struct file_lock fl = {
61193+ struct file_lock flock = {
61194 .fl_pid = current->tgid,
61195 .fl_file = filp,
61196 .fl_flags = FL_FLOCK,
61197 .fl_type = F_UNLCK,
61198 .fl_end = OFFSET_MAX,
61199 };
61200- filp->f_op->flock(filp, F_SETLKW, &fl);
61201- if (fl.fl_ops && fl.fl_ops->fl_release_private)
61202- fl.fl_ops->fl_release_private(&fl);
61203+ filp->f_op->flock(filp, F_SETLKW, &flock);
61204+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
61205+ flock.fl_ops->fl_release_private(&flock);
61206 }
61207
61208 spin_lock(&inode->i_lock);
61209diff --git a/fs/mount.h b/fs/mount.h
61210index b29e42f..5ea7fdf 100644
61211--- a/fs/mount.h
61212+++ b/fs/mount.h
61213@@ -11,7 +11,7 @@ struct mnt_namespace {
61214 u64 seq; /* Sequence number to prevent loops */
61215 wait_queue_head_t poll;
61216 int event;
61217-};
61218+} __randomize_layout;
61219
61220 struct mnt_pcp {
61221 int mnt_count;
61222@@ -57,7 +57,7 @@ struct mount {
61223 int mnt_expiry_mark; /* true if marked for expiry */
61224 int mnt_pinned;
61225 struct path mnt_ex_mountpoint;
61226-};
61227+} __randomize_layout;
61228
61229 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
61230
61231diff --git a/fs/namei.c b/fs/namei.c
61232index 399f637..a24748c 100644
61233--- a/fs/namei.c
61234+++ b/fs/namei.c
61235@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
61236 if (ret != -EACCES)
61237 return ret;
61238
61239+#ifdef CONFIG_GRKERNSEC
61240+ /* we'll block if we have to log due to a denied capability use */
61241+ if (mask & MAY_NOT_BLOCK)
61242+ return -ECHILD;
61243+#endif
61244+
61245 if (S_ISDIR(inode->i_mode)) {
61246 /* DACs are overridable for directories */
61247- if (inode_capable(inode, CAP_DAC_OVERRIDE))
61248- return 0;
61249 if (!(mask & MAY_WRITE))
61250- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61251+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61252+ inode_capable(inode, CAP_DAC_READ_SEARCH))
61253 return 0;
61254+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
61255+ return 0;
61256 return -EACCES;
61257 }
61258 /*
61259+ * Searching includes executable on directories, else just read.
61260+ */
61261+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61262+ if (mask == MAY_READ)
61263+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61264+ inode_capable(inode, CAP_DAC_READ_SEARCH))
61265+ return 0;
61266+
61267+ /*
61268 * Read/write DACs are always overridable.
61269 * Executable DACs are overridable when there is
61270 * at least one exec bit set.
61271@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
61272 if (inode_capable(inode, CAP_DAC_OVERRIDE))
61273 return 0;
61274
61275- /*
61276- * Searching includes executable on directories, else just read.
61277- */
61278- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61279- if (mask == MAY_READ)
61280- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61281- return 0;
61282-
61283 return -EACCES;
61284 }
61285
61286@@ -810,7 +818,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61287 {
61288 struct dentry *dentry = link->dentry;
61289 int error;
61290- char *s;
61291+ const char *s;
61292
61293 BUG_ON(nd->flags & LOOKUP_RCU);
61294
61295@@ -831,6 +839,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61296 if (error)
61297 goto out_put_nd_path;
61298
61299+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
61300+ dentry->d_inode, dentry, nd->path.mnt)) {
61301+ error = -EACCES;
61302+ goto out_put_nd_path;
61303+ }
61304+
61305 nd->last_type = LAST_BIND;
61306 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
61307 error = PTR_ERR(*p);
61308@@ -1579,6 +1593,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
61309 if (res)
61310 break;
61311 res = walk_component(nd, path, LOOKUP_FOLLOW);
61312+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
61313+ res = -EACCES;
61314 put_link(nd, &link, cookie);
61315 } while (res > 0);
61316
61317@@ -1652,7 +1668,7 @@ EXPORT_SYMBOL(full_name_hash);
61318 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
61319 {
61320 unsigned long a, b, adata, bdata, mask, hash, len;
61321- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61322+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61323
61324 hash = a = 0;
61325 len = -sizeof(unsigned long);
61326@@ -1936,6 +1952,8 @@ static int path_lookupat(int dfd, const char *name,
61327 if (err)
61328 break;
61329 err = lookup_last(nd, &path);
61330+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
61331+ err = -EACCES;
61332 put_link(nd, &link, cookie);
61333 }
61334 }
61335@@ -1943,6 +1961,13 @@ static int path_lookupat(int dfd, const char *name,
61336 if (!err)
61337 err = complete_walk(nd);
61338
61339+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
61340+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61341+ path_put(&nd->path);
61342+ err = -ENOENT;
61343+ }
61344+ }
61345+
61346 if (!err && nd->flags & LOOKUP_DIRECTORY) {
61347 if (!d_is_directory(nd->path.dentry)) {
61348 path_put(&nd->path);
61349@@ -1970,8 +1995,15 @@ static int filename_lookup(int dfd, struct filename *name,
61350 retval = path_lookupat(dfd, name->name,
61351 flags | LOOKUP_REVAL, nd);
61352
61353- if (likely(!retval))
61354+ if (likely(!retval)) {
61355 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
61356+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
61357+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
61358+ path_put(&nd->path);
61359+ return -ENOENT;
61360+ }
61361+ }
61362+ }
61363 return retval;
61364 }
61365
61366@@ -2545,6 +2577,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
61367 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
61368 return -EPERM;
61369
61370+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
61371+ return -EPERM;
61372+ if (gr_handle_rawio(inode))
61373+ return -EPERM;
61374+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
61375+ return -EACCES;
61376+
61377 return 0;
61378 }
61379
61380@@ -2776,7 +2815,7 @@ looked_up:
61381 * cleared otherwise prior to returning.
61382 */
61383 static int lookup_open(struct nameidata *nd, struct path *path,
61384- struct file *file,
61385+ struct path *link, struct file *file,
61386 const struct open_flags *op,
61387 bool got_write, int *opened)
61388 {
61389@@ -2811,6 +2850,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61390 /* Negative dentry, just create the file */
61391 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
61392 umode_t mode = op->mode;
61393+
61394+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
61395+ error = -EACCES;
61396+ goto out_dput;
61397+ }
61398+
61399+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
61400+ error = -EACCES;
61401+ goto out_dput;
61402+ }
61403+
61404 if (!IS_POSIXACL(dir->d_inode))
61405 mode &= ~current_umask();
61406 /*
61407@@ -2832,6 +2882,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61408 nd->flags & LOOKUP_EXCL);
61409 if (error)
61410 goto out_dput;
61411+ else
61412+ gr_handle_create(dentry, nd->path.mnt);
61413 }
61414 out_no_open:
61415 path->dentry = dentry;
61416@@ -2846,7 +2898,7 @@ out_dput:
61417 /*
61418 * Handle the last step of open()
61419 */
61420-static int do_last(struct nameidata *nd, struct path *path,
61421+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
61422 struct file *file, const struct open_flags *op,
61423 int *opened, struct filename *name)
61424 {
61425@@ -2896,6 +2948,15 @@ static int do_last(struct nameidata *nd, struct path *path,
61426 if (error)
61427 return error;
61428
61429+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
61430+ error = -ENOENT;
61431+ goto out;
61432+ }
61433+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
61434+ error = -EACCES;
61435+ goto out;
61436+ }
61437+
61438 audit_inode(name, dir, LOOKUP_PARENT);
61439 error = -EISDIR;
61440 /* trailing slashes? */
61441@@ -2915,7 +2976,7 @@ retry_lookup:
61442 */
61443 }
61444 mutex_lock(&dir->d_inode->i_mutex);
61445- error = lookup_open(nd, path, file, op, got_write, opened);
61446+ error = lookup_open(nd, path, link, file, op, got_write, opened);
61447 mutex_unlock(&dir->d_inode->i_mutex);
61448
61449 if (error <= 0) {
61450@@ -2939,11 +3000,28 @@ retry_lookup:
61451 goto finish_open_created;
61452 }
61453
61454+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
61455+ error = -ENOENT;
61456+ goto exit_dput;
61457+ }
61458+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
61459+ error = -EACCES;
61460+ goto exit_dput;
61461+ }
61462+
61463 /*
61464 * create/update audit record if it already exists.
61465 */
61466- if (d_is_positive(path->dentry))
61467+ if (d_is_positive(path->dentry)) {
61468+ /* only check if O_CREAT is specified, all other checks need to go
61469+ into may_open */
61470+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
61471+ error = -EACCES;
61472+ goto exit_dput;
61473+ }
61474+
61475 audit_inode(name, path->dentry, 0);
61476+ }
61477
61478 /*
61479 * If atomic_open() acquired write access it is dropped now due to
61480@@ -2984,6 +3062,11 @@ finish_lookup:
61481 }
61482 }
61483 BUG_ON(inode != path->dentry->d_inode);
61484+ /* if we're resolving a symlink to another symlink */
61485+ if (link && gr_handle_symlink_owner(link, inode)) {
61486+ error = -EACCES;
61487+ goto out;
61488+ }
61489 return 1;
61490 }
61491
61492@@ -2993,7 +3076,6 @@ finish_lookup:
61493 save_parent.dentry = nd->path.dentry;
61494 save_parent.mnt = mntget(path->mnt);
61495 nd->path.dentry = path->dentry;
61496-
61497 }
61498 nd->inode = inode;
61499 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
61500@@ -3003,7 +3085,18 @@ finish_open:
61501 path_put(&save_parent);
61502 return error;
61503 }
61504+
61505+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61506+ error = -ENOENT;
61507+ goto out;
61508+ }
61509+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
61510+ error = -EACCES;
61511+ goto out;
61512+ }
61513+
61514 audit_inode(name, nd->path.dentry, 0);
61515+
61516 error = -EISDIR;
61517 if ((open_flag & O_CREAT) &&
61518 (d_is_directory(nd->path.dentry) || d_is_autodir(nd->path.dentry)))
61519@@ -3167,7 +3260,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61520 if (unlikely(error))
61521 goto out;
61522
61523- error = do_last(nd, &path, file, op, &opened, pathname);
61524+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
61525 while (unlikely(error > 0)) { /* trailing symlink */
61526 struct path link = path;
61527 void *cookie;
61528@@ -3185,7 +3278,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61529 error = follow_link(&link, nd, &cookie);
61530 if (unlikely(error))
61531 break;
61532- error = do_last(nd, &path, file, op, &opened, pathname);
61533+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
61534 put_link(nd, &link, cookie);
61535 }
61536 out:
61537@@ -3285,9 +3378,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
61538 goto unlock;
61539
61540 error = -EEXIST;
61541- if (d_is_positive(dentry))
61542+ if (d_is_positive(dentry)) {
61543+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
61544+ error = -ENOENT;
61545 goto fail;
61546-
61547+ }
61548 /*
61549 * Special case - lookup gave negative, but... we had foo/bar/
61550 * From the vfs_mknod() POV we just have a negative dentry -
61551@@ -3339,6 +3434,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
61552 }
61553 EXPORT_SYMBOL(user_path_create);
61554
61555+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
61556+{
61557+ struct filename *tmp = getname(pathname);
61558+ struct dentry *res;
61559+ if (IS_ERR(tmp))
61560+ return ERR_CAST(tmp);
61561+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
61562+ if (IS_ERR(res))
61563+ putname(tmp);
61564+ else
61565+ *to = tmp;
61566+ return res;
61567+}
61568+
61569 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
61570 {
61571 int error = may_create(dir, dentry);
61572@@ -3401,6 +3510,17 @@ retry:
61573
61574 if (!IS_POSIXACL(path.dentry->d_inode))
61575 mode &= ~current_umask();
61576+
61577+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
61578+ error = -EPERM;
61579+ goto out;
61580+ }
61581+
61582+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
61583+ error = -EACCES;
61584+ goto out;
61585+ }
61586+
61587 error = security_path_mknod(&path, dentry, mode, dev);
61588 if (error)
61589 goto out;
61590@@ -3417,6 +3537,8 @@ retry:
61591 break;
61592 }
61593 out:
61594+ if (!error)
61595+ gr_handle_create(dentry, path.mnt);
61596 done_path_create(&path, dentry);
61597 if (retry_estale(error, lookup_flags)) {
61598 lookup_flags |= LOOKUP_REVAL;
61599@@ -3469,9 +3591,16 @@ retry:
61600
61601 if (!IS_POSIXACL(path.dentry->d_inode))
61602 mode &= ~current_umask();
61603+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
61604+ error = -EACCES;
61605+ goto out;
61606+ }
61607 error = security_path_mkdir(&path, dentry, mode);
61608 if (!error)
61609 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
61610+ if (!error)
61611+ gr_handle_create(dentry, path.mnt);
61612+out:
61613 done_path_create(&path, dentry);
61614 if (retry_estale(error, lookup_flags)) {
61615 lookup_flags |= LOOKUP_REVAL;
61616@@ -3552,6 +3681,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
61617 struct filename *name;
61618 struct dentry *dentry;
61619 struct nameidata nd;
61620+ ino_t saved_ino = 0;
61621+ dev_t saved_dev = 0;
61622 unsigned int lookup_flags = 0;
61623 retry:
61624 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61625@@ -3584,10 +3715,21 @@ retry:
61626 error = -ENOENT;
61627 goto exit3;
61628 }
61629+
61630+ saved_ino = dentry->d_inode->i_ino;
61631+ saved_dev = gr_get_dev_from_dentry(dentry);
61632+
61633+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
61634+ error = -EACCES;
61635+ goto exit3;
61636+ }
61637+
61638 error = security_path_rmdir(&nd.path, dentry);
61639 if (error)
61640 goto exit3;
61641 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
61642+ if (!error && (saved_dev || saved_ino))
61643+ gr_handle_delete(saved_ino, saved_dev);
61644 exit3:
61645 dput(dentry);
61646 exit2:
61647@@ -3677,6 +3819,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
61648 struct nameidata nd;
61649 struct inode *inode = NULL;
61650 struct inode *delegated_inode = NULL;
61651+ ino_t saved_ino = 0;
61652+ dev_t saved_dev = 0;
61653 unsigned int lookup_flags = 0;
61654 retry:
61655 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61656@@ -3703,10 +3847,22 @@ retry_deleg:
61657 if (d_is_negative(dentry))
61658 goto slashes;
61659 ihold(inode);
61660+
61661+ if (inode->i_nlink <= 1) {
61662+ saved_ino = inode->i_ino;
61663+ saved_dev = gr_get_dev_from_dentry(dentry);
61664+ }
61665+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
61666+ error = -EACCES;
61667+ goto exit2;
61668+ }
61669+
61670 error = security_path_unlink(&nd.path, dentry);
61671 if (error)
61672 goto exit2;
61673 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
61674+ if (!error && (saved_ino || saved_dev))
61675+ gr_handle_delete(saved_ino, saved_dev);
61676 exit2:
61677 dput(dentry);
61678 }
61679@@ -3794,9 +3950,17 @@ retry:
61680 if (IS_ERR(dentry))
61681 goto out_putname;
61682
61683+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
61684+ error = -EACCES;
61685+ goto out;
61686+ }
61687+
61688 error = security_path_symlink(&path, dentry, from->name);
61689 if (!error)
61690 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
61691+ if (!error)
61692+ gr_handle_create(dentry, path.mnt);
61693+out:
61694 done_path_create(&path, dentry);
61695 if (retry_estale(error, lookup_flags)) {
61696 lookup_flags |= LOOKUP_REVAL;
61697@@ -3899,6 +4063,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
61698 struct dentry *new_dentry;
61699 struct path old_path, new_path;
61700 struct inode *delegated_inode = NULL;
61701+ struct filename *to = NULL;
61702 int how = 0;
61703 int error;
61704
61705@@ -3922,7 +4087,7 @@ retry:
61706 if (error)
61707 return error;
61708
61709- new_dentry = user_path_create(newdfd, newname, &new_path,
61710+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
61711 (how & LOOKUP_REVAL));
61712 error = PTR_ERR(new_dentry);
61713 if (IS_ERR(new_dentry))
61714@@ -3934,11 +4099,28 @@ retry:
61715 error = may_linkat(&old_path);
61716 if (unlikely(error))
61717 goto out_dput;
61718+
61719+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
61720+ old_path.dentry->d_inode,
61721+ old_path.dentry->d_inode->i_mode, to)) {
61722+ error = -EACCES;
61723+ goto out_dput;
61724+ }
61725+
61726+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
61727+ old_path.dentry, old_path.mnt, to)) {
61728+ error = -EACCES;
61729+ goto out_dput;
61730+ }
61731+
61732 error = security_path_link(old_path.dentry, &new_path, new_dentry);
61733 if (error)
61734 goto out_dput;
61735 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
61736+ if (!error)
61737+ gr_handle_create(new_dentry, new_path.mnt);
61738 out_dput:
61739+ putname(to);
61740 done_path_create(&new_path, new_dentry);
61741 if (delegated_inode) {
61742 error = break_deleg_wait(&delegated_inode);
61743@@ -4225,6 +4407,12 @@ retry_deleg:
61744 if (new_dentry == trap)
61745 goto exit5;
61746
61747+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
61748+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
61749+ to);
61750+ if (error)
61751+ goto exit5;
61752+
61753 error = security_path_rename(&oldnd.path, old_dentry,
61754 &newnd.path, new_dentry);
61755 if (error)
61756@@ -4232,6 +4420,9 @@ retry_deleg:
61757 error = vfs_rename(old_dir->d_inode, old_dentry,
61758 new_dir->d_inode, new_dentry,
61759 &delegated_inode);
61760+ if (!error)
61761+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
61762+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
61763 exit5:
61764 dput(new_dentry);
61765 exit4:
61766@@ -4268,6 +4459,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
61767
61768 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
61769 {
61770+ char tmpbuf[64];
61771+ const char *newlink;
61772 int len;
61773
61774 len = PTR_ERR(link);
61775@@ -4277,7 +4470,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
61776 len = strlen(link);
61777 if (len > (unsigned) buflen)
61778 len = buflen;
61779- if (copy_to_user(buffer, link, len))
61780+
61781+ if (len < sizeof(tmpbuf)) {
61782+ memcpy(tmpbuf, link, len);
61783+ newlink = tmpbuf;
61784+ } else
61785+ newlink = link;
61786+
61787+ if (copy_to_user(buffer, newlink, len))
61788 len = -EFAULT;
61789 out:
61790 return len;
61791diff --git a/fs/namespace.c b/fs/namespace.c
61792index 6d0e54e..4c1f85e 100644
61793--- a/fs/namespace.c
61794+++ b/fs/namespace.c
61795@@ -1339,6 +1339,9 @@ static int do_umount(struct mount *mnt, int flags)
61796 if (!(sb->s_flags & MS_RDONLY))
61797 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
61798 up_write(&sb->s_umount);
61799+
61800+ gr_log_remount(mnt->mnt_devname, retval);
61801+
61802 return retval;
61803 }
61804
61805@@ -1361,6 +1364,9 @@ static int do_umount(struct mount *mnt, int flags)
61806 }
61807 unlock_mount_hash();
61808 namespace_unlock();
61809+
61810+ gr_log_unmount(mnt->mnt_devname, retval);
61811+
61812 return retval;
61813 }
61814
61815@@ -1380,7 +1386,7 @@ static inline bool may_mount(void)
61816 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
61817 */
61818
61819-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
61820+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
61821 {
61822 struct path path;
61823 struct mount *mnt;
61824@@ -1422,7 +1428,7 @@ out:
61825 /*
61826 * The 2.0 compatible umount. No flags.
61827 */
61828-SYSCALL_DEFINE1(oldumount, char __user *, name)
61829+SYSCALL_DEFINE1(oldumount, const char __user *, name)
61830 {
61831 return sys_umount(name, 0);
61832 }
61833@@ -2426,6 +2432,16 @@ long do_mount(const char *dev_name, const char *dir_name,
61834 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
61835 MS_STRICTATIME);
61836
61837+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
61838+ retval = -EPERM;
61839+ goto dput_out;
61840+ }
61841+
61842+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
61843+ retval = -EPERM;
61844+ goto dput_out;
61845+ }
61846+
61847 if (flags & MS_REMOUNT)
61848 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
61849 data_page);
61850@@ -2440,6 +2456,9 @@ long do_mount(const char *dev_name, const char *dir_name,
61851 dev_name, data_page);
61852 dput_out:
61853 path_put(&path);
61854+
61855+ gr_log_mount(dev_name, dir_name, retval);
61856+
61857 return retval;
61858 }
61859
61860@@ -2457,7 +2476,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
61861 * number incrementing at 10Ghz will take 12,427 years to wrap which
61862 * is effectively never, so we can ignore the possibility.
61863 */
61864-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
61865+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
61866
61867 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61868 {
61869@@ -2472,7 +2491,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61870 kfree(new_ns);
61871 return ERR_PTR(ret);
61872 }
61873- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
61874+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
61875 atomic_set(&new_ns->count, 1);
61876 new_ns->root = NULL;
61877 INIT_LIST_HEAD(&new_ns->list);
61878@@ -2482,7 +2501,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61879 return new_ns;
61880 }
61881
61882-struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
61883+__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
61884 struct user_namespace *user_ns, struct fs_struct *new_fs)
61885 {
61886 struct mnt_namespace *new_ns;
61887@@ -2603,8 +2622,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
61888 }
61889 EXPORT_SYMBOL(mount_subtree);
61890
61891-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
61892- char __user *, type, unsigned long, flags, void __user *, data)
61893+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
61894+ const char __user *, type, unsigned long, flags, void __user *, data)
61895 {
61896 int ret;
61897 char *kernel_type;
61898@@ -2717,6 +2736,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
61899 if (error)
61900 goto out2;
61901
61902+ if (gr_handle_chroot_pivot()) {
61903+ error = -EPERM;
61904+ goto out2;
61905+ }
61906+
61907 get_fs_root(current->fs, &root);
61908 old_mp = lock_mount(&old);
61909 error = PTR_ERR(old_mp);
61910@@ -2983,7 +3007,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
61911 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
61912 return -EPERM;
61913
61914- if (fs->users != 1)
61915+ if (atomic_read(&fs->users) != 1)
61916 return -EINVAL;
61917
61918 get_mnt_ns(mnt_ns);
61919diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
61920index f4ccfe6..a5cf064 100644
61921--- a/fs/nfs/callback_xdr.c
61922+++ b/fs/nfs/callback_xdr.c
61923@@ -51,7 +51,7 @@ struct callback_op {
61924 callback_decode_arg_t decode_args;
61925 callback_encode_res_t encode_res;
61926 long res_maxsize;
61927-};
61928+} __do_const;
61929
61930 static struct callback_op callback_ops[];
61931
61932diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
61933index 5d94c02..630214f 100644
61934--- a/fs/nfs/inode.c
61935+++ b/fs/nfs/inode.c
61936@@ -1153,16 +1153,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
61937 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
61938 }
61939
61940-static atomic_long_t nfs_attr_generation_counter;
61941+static atomic_long_unchecked_t nfs_attr_generation_counter;
61942
61943 static unsigned long nfs_read_attr_generation_counter(void)
61944 {
61945- return atomic_long_read(&nfs_attr_generation_counter);
61946+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
61947 }
61948
61949 unsigned long nfs_inc_attr_generation_counter(void)
61950 {
61951- return atomic_long_inc_return(&nfs_attr_generation_counter);
61952+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
61953 }
61954
61955 void nfs_fattr_init(struct nfs_fattr *fattr)
61956diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
61957index 419572f..5414a23 100644
61958--- a/fs/nfsd/nfs4proc.c
61959+++ b/fs/nfsd/nfs4proc.c
61960@@ -1168,7 +1168,7 @@ struct nfsd4_operation {
61961 nfsd4op_rsize op_rsize_bop;
61962 stateid_getter op_get_currentstateid;
61963 stateid_setter op_set_currentstateid;
61964-};
61965+} __do_const;
61966
61967 static struct nfsd4_operation nfsd4_ops[];
61968
61969diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
61970index ee7237f..e3ae60a 100644
61971--- a/fs/nfsd/nfs4xdr.c
61972+++ b/fs/nfsd/nfs4xdr.c
61973@@ -1523,7 +1523,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
61974
61975 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
61976
61977-static nfsd4_dec nfsd4_dec_ops[] = {
61978+static const nfsd4_dec nfsd4_dec_ops[] = {
61979 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
61980 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
61981 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
61982diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
61983index b6af150..f6ec5e3 100644
61984--- a/fs/nfsd/nfscache.c
61985+++ b/fs/nfsd/nfscache.c
61986@@ -547,14 +547,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
61987 {
61988 struct svc_cacherep *rp = rqstp->rq_cacherep;
61989 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
61990- int len;
61991+ long len;
61992 size_t bufsize = 0;
61993
61994 if (!rp)
61995 return;
61996
61997- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
61998- len >>= 2;
61999+ if (statp) {
62000+ len = (char*)statp - (char*)resv->iov_base;
62001+ len = resv->iov_len - len;
62002+ len >>= 2;
62003+ }
62004
62005 /* Don't cache excessive amounts of data and XDR failures */
62006 if (!statp || len > (256 >> 2)) {
62007diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
62008index 7eea63c..a35f4fb 100644
62009--- a/fs/nfsd/vfs.c
62010+++ b/fs/nfsd/vfs.c
62011@@ -993,7 +993,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62012 } else {
62013 oldfs = get_fs();
62014 set_fs(KERNEL_DS);
62015- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
62016+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
62017 set_fs(oldfs);
62018 }
62019
62020@@ -1084,7 +1084,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62021
62022 /* Write the data. */
62023 oldfs = get_fs(); set_fs(KERNEL_DS);
62024- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
62025+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
62026 set_fs(oldfs);
62027 if (host_err < 0)
62028 goto out_nfserr;
62029@@ -1629,7 +1629,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
62030 */
62031
62032 oldfs = get_fs(); set_fs(KERNEL_DS);
62033- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
62034+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
62035 set_fs(oldfs);
62036
62037 if (host_err < 0)
62038diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
62039index fea6bd5..8ee9d81 100644
62040--- a/fs/nls/nls_base.c
62041+++ b/fs/nls/nls_base.c
62042@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
62043
62044 int register_nls(struct nls_table * nls)
62045 {
62046- struct nls_table ** tmp = &tables;
62047+ struct nls_table *tmp = tables;
62048
62049 if (nls->next)
62050 return -EBUSY;
62051
62052 spin_lock(&nls_lock);
62053- while (*tmp) {
62054- if (nls == *tmp) {
62055+ while (tmp) {
62056+ if (nls == tmp) {
62057 spin_unlock(&nls_lock);
62058 return -EBUSY;
62059 }
62060- tmp = &(*tmp)->next;
62061+ tmp = tmp->next;
62062 }
62063- nls->next = tables;
62064+ pax_open_kernel();
62065+ *(struct nls_table **)&nls->next = tables;
62066+ pax_close_kernel();
62067 tables = nls;
62068 spin_unlock(&nls_lock);
62069 return 0;
62070@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
62071
62072 int unregister_nls(struct nls_table * nls)
62073 {
62074- struct nls_table ** tmp = &tables;
62075+ struct nls_table * const * tmp = &tables;
62076
62077 spin_lock(&nls_lock);
62078 while (*tmp) {
62079 if (nls == *tmp) {
62080- *tmp = nls->next;
62081+ pax_open_kernel();
62082+ *(struct nls_table **)tmp = nls->next;
62083+ pax_close_kernel();
62084 spin_unlock(&nls_lock);
62085 return 0;
62086 }
62087diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
62088index 7424929..35f6be5 100644
62089--- a/fs/nls/nls_euc-jp.c
62090+++ b/fs/nls/nls_euc-jp.c
62091@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
62092 p_nls = load_nls("cp932");
62093
62094 if (p_nls) {
62095- table.charset2upper = p_nls->charset2upper;
62096- table.charset2lower = p_nls->charset2lower;
62097+ pax_open_kernel();
62098+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62099+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62100+ pax_close_kernel();
62101 return register_nls(&table);
62102 }
62103
62104diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
62105index e7bc1d7..06bd4bb 100644
62106--- a/fs/nls/nls_koi8-ru.c
62107+++ b/fs/nls/nls_koi8-ru.c
62108@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
62109 p_nls = load_nls("koi8-u");
62110
62111 if (p_nls) {
62112- table.charset2upper = p_nls->charset2upper;
62113- table.charset2lower = p_nls->charset2lower;
62114+ pax_open_kernel();
62115+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62116+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62117+ pax_close_kernel();
62118 return register_nls(&table);
62119 }
62120
62121diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
62122index 6663511..7668ca4 100644
62123--- a/fs/notify/fanotify/fanotify_user.c
62124+++ b/fs/notify/fanotify/fanotify_user.c
62125@@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
62126
62127 fd = fanotify_event_metadata.fd;
62128 ret = -EFAULT;
62129- if (copy_to_user(buf, &fanotify_event_metadata,
62130- fanotify_event_metadata.event_len))
62131+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
62132+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
62133 goto out_close_fd;
62134
62135 ret = prepare_for_access_response(group, event, fd);
62136diff --git a/fs/notify/notification.c b/fs/notify/notification.c
62137index 7b51b05..5ea5ef6 100644
62138--- a/fs/notify/notification.c
62139+++ b/fs/notify/notification.c
62140@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
62141 * get set to 0 so it will never get 'freed'
62142 */
62143 static struct fsnotify_event *q_overflow_event;
62144-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62145+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62146
62147 /**
62148 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
62149@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62150 */
62151 u32 fsnotify_get_cookie(void)
62152 {
62153- return atomic_inc_return(&fsnotify_sync_cookie);
62154+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
62155 }
62156 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
62157
62158diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
62159index 9e38daf..5727cae 100644
62160--- a/fs/ntfs/dir.c
62161+++ b/fs/ntfs/dir.c
62162@@ -1310,7 +1310,7 @@ find_next_index_buffer:
62163 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
62164 ~(s64)(ndir->itype.index.block_size - 1)));
62165 /* Bounds checks. */
62166- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62167+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62168 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
62169 "inode 0x%lx or driver bug.", vdir->i_ino);
62170 goto err_out;
62171diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
62172index ea4ba9d..1e13d34 100644
62173--- a/fs/ntfs/file.c
62174+++ b/fs/ntfs/file.c
62175@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
62176 char *addr;
62177 size_t total = 0;
62178 unsigned len;
62179- int left;
62180+ unsigned left;
62181
62182 do {
62183 len = PAGE_CACHE_SIZE - ofs;
62184diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
62185index 82650d5..db37dcf 100644
62186--- a/fs/ntfs/super.c
62187+++ b/fs/ntfs/super.c
62188@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62189 if (!silent)
62190 ntfs_error(sb, "Primary boot sector is invalid.");
62191 } else if (!silent)
62192- ntfs_error(sb, read_err_str, "primary");
62193+ ntfs_error(sb, read_err_str, "%s", "primary");
62194 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
62195 if (bh_primary)
62196 brelse(bh_primary);
62197@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62198 goto hotfix_primary_boot_sector;
62199 brelse(bh_backup);
62200 } else if (!silent)
62201- ntfs_error(sb, read_err_str, "backup");
62202+ ntfs_error(sb, read_err_str, "%s", "backup");
62203 /* Try to read NT3.51- backup boot sector. */
62204 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
62205 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
62206@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62207 "sector.");
62208 brelse(bh_backup);
62209 } else if (!silent)
62210- ntfs_error(sb, read_err_str, "backup");
62211+ ntfs_error(sb, read_err_str, "%s", "backup");
62212 /* We failed. Cleanup and return. */
62213 if (bh_primary)
62214 brelse(bh_primary);
62215diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
62216index cd5496b..26a1055 100644
62217--- a/fs/ocfs2/localalloc.c
62218+++ b/fs/ocfs2/localalloc.c
62219@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
62220 goto bail;
62221 }
62222
62223- atomic_inc(&osb->alloc_stats.moves);
62224+ atomic_inc_unchecked(&osb->alloc_stats.moves);
62225
62226 bail:
62227 if (handle)
62228diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
62229index 3a90347..c40bef8 100644
62230--- a/fs/ocfs2/ocfs2.h
62231+++ b/fs/ocfs2/ocfs2.h
62232@@ -235,11 +235,11 @@ enum ocfs2_vol_state
62233
62234 struct ocfs2_alloc_stats
62235 {
62236- atomic_t moves;
62237- atomic_t local_data;
62238- atomic_t bitmap_data;
62239- atomic_t bg_allocs;
62240- atomic_t bg_extends;
62241+ atomic_unchecked_t moves;
62242+ atomic_unchecked_t local_data;
62243+ atomic_unchecked_t bitmap_data;
62244+ atomic_unchecked_t bg_allocs;
62245+ atomic_unchecked_t bg_extends;
62246 };
62247
62248 enum ocfs2_local_alloc_state
62249diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
62250index 2c91452..77a3cd2 100644
62251--- a/fs/ocfs2/suballoc.c
62252+++ b/fs/ocfs2/suballoc.c
62253@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
62254 mlog_errno(status);
62255 goto bail;
62256 }
62257- atomic_inc(&osb->alloc_stats.bg_extends);
62258+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
62259
62260 /* You should never ask for this much metadata */
62261 BUG_ON(bits_wanted >
62262@@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
62263 mlog_errno(status);
62264 goto bail;
62265 }
62266- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62267+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62268
62269 *suballoc_loc = res.sr_bg_blkno;
62270 *suballoc_bit_start = res.sr_bit_offset;
62271@@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
62272 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
62273 res->sr_bits);
62274
62275- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62276+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62277
62278 BUG_ON(res->sr_bits != 1);
62279
62280@@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
62281 mlog_errno(status);
62282 goto bail;
62283 }
62284- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62285+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62286
62287 BUG_ON(res.sr_bits != 1);
62288
62289@@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62290 cluster_start,
62291 num_clusters);
62292 if (!status)
62293- atomic_inc(&osb->alloc_stats.local_data);
62294+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
62295 } else {
62296 if (min_clusters > (osb->bitmap_cpg - 1)) {
62297 /* The only paths asking for contiguousness
62298@@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62299 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
62300 res.sr_bg_blkno,
62301 res.sr_bit_offset);
62302- atomic_inc(&osb->alloc_stats.bitmap_data);
62303+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
62304 *num_clusters = res.sr_bits;
62305 }
62306 }
62307diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
62308index c414929..5c9ee542 100644
62309--- a/fs/ocfs2/super.c
62310+++ b/fs/ocfs2/super.c
62311@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
62312 "%10s => GlobalAllocs: %d LocalAllocs: %d "
62313 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
62314 "Stats",
62315- atomic_read(&osb->alloc_stats.bitmap_data),
62316- atomic_read(&osb->alloc_stats.local_data),
62317- atomic_read(&osb->alloc_stats.bg_allocs),
62318- atomic_read(&osb->alloc_stats.moves),
62319- atomic_read(&osb->alloc_stats.bg_extends));
62320+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
62321+ atomic_read_unchecked(&osb->alloc_stats.local_data),
62322+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
62323+ atomic_read_unchecked(&osb->alloc_stats.moves),
62324+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
62325
62326 out += snprintf(buf + out, len - out,
62327 "%10s => State: %u Descriptor: %llu Size: %u bits "
62328@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
62329 spin_lock_init(&osb->osb_xattr_lock);
62330 ocfs2_init_steal_slots(osb);
62331
62332- atomic_set(&osb->alloc_stats.moves, 0);
62333- atomic_set(&osb->alloc_stats.local_data, 0);
62334- atomic_set(&osb->alloc_stats.bitmap_data, 0);
62335- atomic_set(&osb->alloc_stats.bg_allocs, 0);
62336- atomic_set(&osb->alloc_stats.bg_extends, 0);
62337+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
62338+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
62339+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
62340+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
62341+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
62342
62343 /* Copy the blockcheck stats from the superblock probe */
62344 osb->osb_ecc_stats = *stats;
62345diff --git a/fs/open.c b/fs/open.c
62346index 4b3e1ed..1c84599 100644
62347--- a/fs/open.c
62348+++ b/fs/open.c
62349@@ -32,6 +32,8 @@
62350 #include <linux/dnotify.h>
62351 #include <linux/compat.h>
62352
62353+#define CREATE_TRACE_POINTS
62354+#include <trace/events/fs.h>
62355 #include "internal.h"
62356
62357 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
62358@@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
62359 error = locks_verify_truncate(inode, NULL, length);
62360 if (!error)
62361 error = security_path_truncate(path);
62362+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
62363+ error = -EACCES;
62364 if (!error)
62365 error = do_truncate(path->dentry, length, 0, NULL);
62366
62367@@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
62368 error = locks_verify_truncate(inode, f.file, length);
62369 if (!error)
62370 error = security_path_truncate(&f.file->f_path);
62371+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
62372+ error = -EACCES;
62373 if (!error)
62374 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
62375 sb_end_write(inode->i_sb);
62376@@ -361,6 +367,9 @@ retry:
62377 if (__mnt_is_readonly(path.mnt))
62378 res = -EROFS;
62379
62380+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
62381+ res = -EACCES;
62382+
62383 out_path_release:
62384 path_put(&path);
62385 if (retry_estale(res, lookup_flags)) {
62386@@ -392,6 +401,8 @@ retry:
62387 if (error)
62388 goto dput_and_out;
62389
62390+ gr_log_chdir(path.dentry, path.mnt);
62391+
62392 set_fs_pwd(current->fs, &path);
62393
62394 dput_and_out:
62395@@ -421,6 +432,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
62396 goto out_putf;
62397
62398 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
62399+
62400+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
62401+ error = -EPERM;
62402+
62403+ if (!error)
62404+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
62405+
62406 if (!error)
62407 set_fs_pwd(current->fs, &f.file->f_path);
62408 out_putf:
62409@@ -450,7 +468,13 @@ retry:
62410 if (error)
62411 goto dput_and_out;
62412
62413+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
62414+ goto dput_and_out;
62415+
62416 set_fs_root(current->fs, &path);
62417+
62418+ gr_handle_chroot_chdir(&path);
62419+
62420 error = 0;
62421 dput_and_out:
62422 path_put(&path);
62423@@ -474,6 +498,16 @@ static int chmod_common(struct path *path, umode_t mode)
62424 return error;
62425 retry_deleg:
62426 mutex_lock(&inode->i_mutex);
62427+
62428+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
62429+ error = -EACCES;
62430+ goto out_unlock;
62431+ }
62432+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
62433+ error = -EACCES;
62434+ goto out_unlock;
62435+ }
62436+
62437 error = security_path_chmod(path, mode);
62438 if (error)
62439 goto out_unlock;
62440@@ -539,6 +573,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
62441 uid = make_kuid(current_user_ns(), user);
62442 gid = make_kgid(current_user_ns(), group);
62443
62444+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
62445+ return -EACCES;
62446+
62447 newattrs.ia_valid = ATTR_CTIME;
62448 if (user != (uid_t) -1) {
62449 if (!uid_valid(uid))
62450@@ -990,6 +1027,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
62451 } else {
62452 fsnotify_open(f);
62453 fd_install(fd, f);
62454+ trace_do_sys_open(tmp->name, flags, mode);
62455 }
62456 }
62457 putname(tmp);
62458diff --git a/fs/pipe.c b/fs/pipe.c
62459index 0e0752e..7cfdd50 100644
62460--- a/fs/pipe.c
62461+++ b/fs/pipe.c
62462@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
62463
62464 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
62465 {
62466- if (pipe->files)
62467+ if (atomic_read(&pipe->files))
62468 mutex_lock_nested(&pipe->mutex, subclass);
62469 }
62470
62471@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
62472
62473 void pipe_unlock(struct pipe_inode_info *pipe)
62474 {
62475- if (pipe->files)
62476+ if (atomic_read(&pipe->files))
62477 mutex_unlock(&pipe->mutex);
62478 }
62479 EXPORT_SYMBOL(pipe_unlock);
62480@@ -449,9 +449,9 @@ redo:
62481 }
62482 if (bufs) /* More to do? */
62483 continue;
62484- if (!pipe->writers)
62485+ if (!atomic_read(&pipe->writers))
62486 break;
62487- if (!pipe->waiting_writers) {
62488+ if (!atomic_read(&pipe->waiting_writers)) {
62489 /* syscall merging: Usually we must not sleep
62490 * if O_NONBLOCK is set, or if we got some data.
62491 * But if a writer sleeps in kernel space, then
62492@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
62493 ret = 0;
62494 __pipe_lock(pipe);
62495
62496- if (!pipe->readers) {
62497+ if (!atomic_read(&pipe->readers)) {
62498 send_sig(SIGPIPE, current, 0);
62499 ret = -EPIPE;
62500 goto out;
62501@@ -562,7 +562,7 @@ redo1:
62502 for (;;) {
62503 int bufs;
62504
62505- if (!pipe->readers) {
62506+ if (!atomic_read(&pipe->readers)) {
62507 send_sig(SIGPIPE, current, 0);
62508 if (!ret)
62509 ret = -EPIPE;
62510@@ -653,9 +653,9 @@ redo2:
62511 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62512 do_wakeup = 0;
62513 }
62514- pipe->waiting_writers++;
62515+ atomic_inc(&pipe->waiting_writers);
62516 pipe_wait(pipe);
62517- pipe->waiting_writers--;
62518+ atomic_dec(&pipe->waiting_writers);
62519 }
62520 out:
62521 __pipe_unlock(pipe);
62522@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62523 mask = 0;
62524 if (filp->f_mode & FMODE_READ) {
62525 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
62526- if (!pipe->writers && filp->f_version != pipe->w_counter)
62527+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
62528 mask |= POLLHUP;
62529 }
62530
62531@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62532 * Most Unices do not set POLLERR for FIFOs but on Linux they
62533 * behave exactly like pipes for poll().
62534 */
62535- if (!pipe->readers)
62536+ if (!atomic_read(&pipe->readers))
62537 mask |= POLLERR;
62538 }
62539
62540@@ -731,7 +731,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
62541 int kill = 0;
62542
62543 spin_lock(&inode->i_lock);
62544- if (!--pipe->files) {
62545+ if (atomic_dec_and_test(&pipe->files)) {
62546 inode->i_pipe = NULL;
62547 kill = 1;
62548 }
62549@@ -748,11 +748,11 @@ pipe_release(struct inode *inode, struct file *file)
62550
62551 __pipe_lock(pipe);
62552 if (file->f_mode & FMODE_READ)
62553- pipe->readers--;
62554+ atomic_dec(&pipe->readers);
62555 if (file->f_mode & FMODE_WRITE)
62556- pipe->writers--;
62557+ atomic_dec(&pipe->writers);
62558
62559- if (pipe->readers || pipe->writers) {
62560+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
62561 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
62562 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62563 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
62564@@ -817,7 +817,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
62565 kfree(pipe);
62566 }
62567
62568-static struct vfsmount *pipe_mnt __read_mostly;
62569+struct vfsmount *pipe_mnt __read_mostly;
62570
62571 /*
62572 * pipefs_dname() is called from d_path().
62573@@ -847,8 +847,9 @@ static struct inode * get_pipe_inode(void)
62574 goto fail_iput;
62575
62576 inode->i_pipe = pipe;
62577- pipe->files = 2;
62578- pipe->readers = pipe->writers = 1;
62579+ atomic_set(&pipe->files, 2);
62580+ atomic_set(&pipe->readers, 1);
62581+ atomic_set(&pipe->writers, 1);
62582 inode->i_fop = &pipefifo_fops;
62583
62584 /*
62585@@ -1027,17 +1028,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
62586 spin_lock(&inode->i_lock);
62587 if (inode->i_pipe) {
62588 pipe = inode->i_pipe;
62589- pipe->files++;
62590+ atomic_inc(&pipe->files);
62591 spin_unlock(&inode->i_lock);
62592 } else {
62593 spin_unlock(&inode->i_lock);
62594 pipe = alloc_pipe_info();
62595 if (!pipe)
62596 return -ENOMEM;
62597- pipe->files = 1;
62598+ atomic_set(&pipe->files, 1);
62599 spin_lock(&inode->i_lock);
62600 if (unlikely(inode->i_pipe)) {
62601- inode->i_pipe->files++;
62602+ atomic_inc(&inode->i_pipe->files);
62603 spin_unlock(&inode->i_lock);
62604 free_pipe_info(pipe);
62605 pipe = inode->i_pipe;
62606@@ -1062,10 +1063,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
62607 * opened, even when there is no process writing the FIFO.
62608 */
62609 pipe->r_counter++;
62610- if (pipe->readers++ == 0)
62611+ if (atomic_inc_return(&pipe->readers) == 1)
62612 wake_up_partner(pipe);
62613
62614- if (!is_pipe && !pipe->writers) {
62615+ if (!is_pipe && !atomic_read(&pipe->writers)) {
62616 if ((filp->f_flags & O_NONBLOCK)) {
62617 /* suppress POLLHUP until we have
62618 * seen a writer */
62619@@ -1084,14 +1085,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
62620 * errno=ENXIO when there is no process reading the FIFO.
62621 */
62622 ret = -ENXIO;
62623- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
62624+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
62625 goto err;
62626
62627 pipe->w_counter++;
62628- if (!pipe->writers++)
62629+ if (atomic_inc_return(&pipe->writers) == 1)
62630 wake_up_partner(pipe);
62631
62632- if (!is_pipe && !pipe->readers) {
62633+ if (!is_pipe && !atomic_read(&pipe->readers)) {
62634 if (wait_for_partner(pipe, &pipe->r_counter))
62635 goto err_wr;
62636 }
62637@@ -1105,11 +1106,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
62638 * the process can at least talk to itself.
62639 */
62640
62641- pipe->readers++;
62642- pipe->writers++;
62643+ atomic_inc(&pipe->readers);
62644+ atomic_inc(&pipe->writers);
62645 pipe->r_counter++;
62646 pipe->w_counter++;
62647- if (pipe->readers == 1 || pipe->writers == 1)
62648+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
62649 wake_up_partner(pipe);
62650 break;
62651
62652@@ -1123,13 +1124,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
62653 return 0;
62654
62655 err_rd:
62656- if (!--pipe->readers)
62657+ if (atomic_dec_and_test(&pipe->readers))
62658 wake_up_interruptible(&pipe->wait);
62659 ret = -ERESTARTSYS;
62660 goto err;
62661
62662 err_wr:
62663- if (!--pipe->writers)
62664+ if (atomic_dec_and_test(&pipe->writers))
62665 wake_up_interruptible(&pipe->wait);
62666 ret = -ERESTARTSYS;
62667 goto err;
62668diff --git a/fs/posix_acl.c b/fs/posix_acl.c
62669index 8bd2135..eab9adb 100644
62670--- a/fs/posix_acl.c
62671+++ b/fs/posix_acl.c
62672@@ -19,6 +19,7 @@
62673 #include <linux/sched.h>
62674 #include <linux/posix_acl.h>
62675 #include <linux/export.h>
62676+#include <linux/grsecurity.h>
62677
62678 #include <linux/errno.h>
62679
62680@@ -183,7 +184,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
62681 }
62682 }
62683 if (mode_p)
62684- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62685+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62686 return not_equiv;
62687 }
62688
62689@@ -331,7 +332,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
62690 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
62691 }
62692
62693- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62694+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62695 return not_equiv;
62696 }
62697
62698@@ -389,6 +390,8 @@ posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
62699 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
62700 int err = -ENOMEM;
62701 if (clone) {
62702+ *mode_p &= ~gr_acl_umask();
62703+
62704 err = posix_acl_create_masq(clone, mode_p);
62705 if (err < 0) {
62706 posix_acl_release(clone);
62707diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
62708index 2183fcf..3c32a98 100644
62709--- a/fs/proc/Kconfig
62710+++ b/fs/proc/Kconfig
62711@@ -30,7 +30,7 @@ config PROC_FS
62712
62713 config PROC_KCORE
62714 bool "/proc/kcore support" if !ARM
62715- depends on PROC_FS && MMU
62716+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
62717 help
62718 Provides a virtual ELF core file of the live kernel. This can
62719 be read with gdb and other ELF tools. No modifications can be
62720@@ -38,8 +38,8 @@ config PROC_KCORE
62721
62722 config PROC_VMCORE
62723 bool "/proc/vmcore support"
62724- depends on PROC_FS && CRASH_DUMP
62725- default y
62726+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
62727+ default n
62728 help
62729 Exports the dump image of crashed kernel in ELF format.
62730
62731@@ -63,8 +63,8 @@ config PROC_SYSCTL
62732 limited in memory.
62733
62734 config PROC_PAGE_MONITOR
62735- default y
62736- depends on PROC_FS && MMU
62737+ default n
62738+ depends on PROC_FS && MMU && !GRKERNSEC
62739 bool "Enable /proc page monitoring" if EXPERT
62740 help
62741 Various /proc files exist to monitor process memory utilization:
62742diff --git a/fs/proc/array.c b/fs/proc/array.c
62743index 1bd2077..2f7cfd5 100644
62744--- a/fs/proc/array.c
62745+++ b/fs/proc/array.c
62746@@ -60,6 +60,7 @@
62747 #include <linux/tty.h>
62748 #include <linux/string.h>
62749 #include <linux/mman.h>
62750+#include <linux/grsecurity.h>
62751 #include <linux/proc_fs.h>
62752 #include <linux/ioport.h>
62753 #include <linux/uaccess.h>
62754@@ -365,6 +366,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
62755 seq_putc(m, '\n');
62756 }
62757
62758+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62759+static inline void task_pax(struct seq_file *m, struct task_struct *p)
62760+{
62761+ if (p->mm)
62762+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
62763+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
62764+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
62765+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
62766+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
62767+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
62768+ else
62769+ seq_printf(m, "PaX:\t-----\n");
62770+}
62771+#endif
62772+
62773 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
62774 struct pid *pid, struct task_struct *task)
62775 {
62776@@ -383,9 +399,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
62777 task_cpus_allowed(m, task);
62778 cpuset_task_status_allowed(m, task);
62779 task_context_switch_counts(m, task);
62780+
62781+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62782+ task_pax(m, task);
62783+#endif
62784+
62785+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
62786+ task_grsec_rbac(m, task);
62787+#endif
62788+
62789 return 0;
62790 }
62791
62792+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62793+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
62794+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
62795+ _mm->pax_flags & MF_PAX_SEGMEXEC))
62796+#endif
62797+
62798 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62799 struct pid *pid, struct task_struct *task, int whole)
62800 {
62801@@ -407,6 +438,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62802 char tcomm[sizeof(task->comm)];
62803 unsigned long flags;
62804
62805+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62806+ if (current->exec_id != m->exec_id) {
62807+ gr_log_badprocpid("stat");
62808+ return 0;
62809+ }
62810+#endif
62811+
62812 state = *get_task_state(task);
62813 vsize = eip = esp = 0;
62814 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
62815@@ -478,6 +516,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62816 gtime = task_gtime(task);
62817 }
62818
62819+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62820+ if (PAX_RAND_FLAGS(mm)) {
62821+ eip = 0;
62822+ esp = 0;
62823+ wchan = 0;
62824+ }
62825+#endif
62826+#ifdef CONFIG_GRKERNSEC_HIDESYM
62827+ wchan = 0;
62828+ eip =0;
62829+ esp =0;
62830+#endif
62831+
62832 /* scale priority and nice values from timeslices to -20..20 */
62833 /* to make it look like a "normal" Unix priority/nice value */
62834 priority = task_prio(task);
62835@@ -514,9 +565,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62836 seq_put_decimal_ull(m, ' ', vsize);
62837 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
62838 seq_put_decimal_ull(m, ' ', rsslim);
62839+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62840+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
62841+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
62842+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
62843+#else
62844 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
62845 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
62846 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
62847+#endif
62848 seq_put_decimal_ull(m, ' ', esp);
62849 seq_put_decimal_ull(m, ' ', eip);
62850 /* The signal information here is obsolete.
62851@@ -538,7 +595,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62852 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
62853 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
62854
62855- if (mm && permitted) {
62856+ if (mm && permitted
62857+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62858+ && !PAX_RAND_FLAGS(mm)
62859+#endif
62860+ ) {
62861 seq_put_decimal_ull(m, ' ', mm->start_data);
62862 seq_put_decimal_ull(m, ' ', mm->end_data);
62863 seq_put_decimal_ull(m, ' ', mm->start_brk);
62864@@ -576,8 +637,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
62865 struct pid *pid, struct task_struct *task)
62866 {
62867 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
62868- struct mm_struct *mm = get_task_mm(task);
62869+ struct mm_struct *mm;
62870
62871+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62872+ if (current->exec_id != m->exec_id) {
62873+ gr_log_badprocpid("statm");
62874+ return 0;
62875+ }
62876+#endif
62877+ mm = get_task_mm(task);
62878 if (mm) {
62879 size = task_statm(mm, &shared, &text, &data, &resident);
62880 mmput(mm);
62881@@ -600,6 +668,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
62882 return 0;
62883 }
62884
62885+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
62886+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
62887+{
62888+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
62889+}
62890+#endif
62891+
62892 #ifdef CONFIG_CHECKPOINT_RESTORE
62893 static struct pid *
62894 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
62895diff --git a/fs/proc/base.c b/fs/proc/base.c
62896index b59a34b..68a79e8 100644
62897--- a/fs/proc/base.c
62898+++ b/fs/proc/base.c
62899@@ -113,6 +113,14 @@ struct pid_entry {
62900 union proc_op op;
62901 };
62902
62903+struct getdents_callback {
62904+ struct linux_dirent __user * current_dir;
62905+ struct linux_dirent __user * previous;
62906+ struct file * file;
62907+ int count;
62908+ int error;
62909+};
62910+
62911 #define NOD(NAME, MODE, IOP, FOP, OP) { \
62912 .name = (NAME), \
62913 .len = sizeof(NAME) - 1, \
62914@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
62915 if (!mm->arg_end)
62916 goto out_mm; /* Shh! No looking before we're done */
62917
62918+ if (gr_acl_handle_procpidmem(task))
62919+ goto out_mm;
62920+
62921 len = mm->arg_end - mm->arg_start;
62922
62923 if (len > PAGE_SIZE)
62924@@ -237,12 +248,28 @@ out:
62925 return res;
62926 }
62927
62928+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62929+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
62930+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
62931+ _mm->pax_flags & MF_PAX_SEGMEXEC))
62932+#endif
62933+
62934 static int proc_pid_auxv(struct task_struct *task, char *buffer)
62935 {
62936 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
62937 int res = PTR_ERR(mm);
62938 if (mm && !IS_ERR(mm)) {
62939 unsigned int nwords = 0;
62940+
62941+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62942+ /* allow if we're currently ptracing this task */
62943+ if (PAX_RAND_FLAGS(mm) &&
62944+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
62945+ mmput(mm);
62946+ return 0;
62947+ }
62948+#endif
62949+
62950 do {
62951 nwords += 2;
62952 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
62953@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
62954 }
62955
62956
62957-#ifdef CONFIG_KALLSYMS
62958+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62959 /*
62960 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
62961 * Returns the resolved symbol. If that fails, simply return the address.
62962@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
62963 mutex_unlock(&task->signal->cred_guard_mutex);
62964 }
62965
62966-#ifdef CONFIG_STACKTRACE
62967+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62968
62969 #define MAX_STACK_TRACE_DEPTH 64
62970
62971@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
62972 return count;
62973 }
62974
62975-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
62976+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
62977 static int proc_pid_syscall(struct task_struct *task, char *buffer)
62978 {
62979 long nr;
62980@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
62981 /************************************************************************/
62982
62983 /* permission checks */
62984-static int proc_fd_access_allowed(struct inode *inode)
62985+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
62986 {
62987 struct task_struct *task;
62988 int allowed = 0;
62989@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
62990 */
62991 task = get_proc_task(inode);
62992 if (task) {
62993- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
62994+ if (log)
62995+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
62996+ else
62997+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
62998 put_task_struct(task);
62999 }
63000 return allowed;
63001@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
63002 struct task_struct *task,
63003 int hide_pid_min)
63004 {
63005+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63006+ return false;
63007+
63008+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63009+ rcu_read_lock();
63010+ {
63011+ const struct cred *tmpcred = current_cred();
63012+ const struct cred *cred = __task_cred(task);
63013+
63014+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
63015+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63016+ || in_group_p(grsec_proc_gid)
63017+#endif
63018+ ) {
63019+ rcu_read_unlock();
63020+ return true;
63021+ }
63022+ }
63023+ rcu_read_unlock();
63024+
63025+ if (!pid->hide_pid)
63026+ return false;
63027+#endif
63028+
63029 if (pid->hide_pid < hide_pid_min)
63030 return true;
63031 if (in_group_p(pid->pid_gid))
63032 return true;
63033+
63034 return ptrace_may_access(task, PTRACE_MODE_READ);
63035 }
63036
63037@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
63038 put_task_struct(task);
63039
63040 if (!has_perms) {
63041+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63042+ {
63043+#else
63044 if (pid->hide_pid == 2) {
63045+#endif
63046 /*
63047 * Let's make getdents(), stat(), and open()
63048 * consistent with each other. If a process
63049@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63050 if (!task)
63051 return -ESRCH;
63052
63053+ if (gr_acl_handle_procpidmem(task)) {
63054+ put_task_struct(task);
63055+ return -EPERM;
63056+ }
63057+
63058 mm = mm_access(task, mode);
63059 put_task_struct(task);
63060
63061@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63062
63063 file->private_data = mm;
63064
63065+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63066+ file->f_version = current->exec_id;
63067+#endif
63068+
63069 return 0;
63070 }
63071
63072@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63073 ssize_t copied;
63074 char *page;
63075
63076+#ifdef CONFIG_GRKERNSEC
63077+ if (write)
63078+ return -EPERM;
63079+#endif
63080+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63081+ if (file->f_version != current->exec_id) {
63082+ gr_log_badprocpid("mem");
63083+ return 0;
63084+ }
63085+#endif
63086+
63087 if (!mm)
63088 return 0;
63089
63090@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63091 goto free;
63092
63093 while (count > 0) {
63094- int this_len = min_t(int, count, PAGE_SIZE);
63095+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
63096
63097 if (write && copy_from_user(page, buf, this_len)) {
63098 copied = -EFAULT;
63099@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63100 if (!mm)
63101 return 0;
63102
63103+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63104+ if (file->f_version != current->exec_id) {
63105+ gr_log_badprocpid("environ");
63106+ return 0;
63107+ }
63108+#endif
63109+
63110 page = (char *)__get_free_page(GFP_TEMPORARY);
63111 if (!page)
63112 return -ENOMEM;
63113@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63114 goto free;
63115 while (count > 0) {
63116 size_t this_len, max_len;
63117- int retval;
63118+ ssize_t retval;
63119
63120 if (src >= (mm->env_end - mm->env_start))
63121 break;
63122@@ -1467,7 +1553,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
63123 int error = -EACCES;
63124
63125 /* Are we allowed to snoop on the tasks file descriptors? */
63126- if (!proc_fd_access_allowed(inode))
63127+ if (!proc_fd_access_allowed(inode, 0))
63128 goto out;
63129
63130 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63131@@ -1511,8 +1597,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
63132 struct path path;
63133
63134 /* Are we allowed to snoop on the tasks file descriptors? */
63135- if (!proc_fd_access_allowed(inode))
63136- goto out;
63137+ /* logging this is needed for learning on chromium to work properly,
63138+ but we don't want to flood the logs from 'ps' which does a readlink
63139+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
63140+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
63141+ */
63142+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
63143+ if (!proc_fd_access_allowed(inode,0))
63144+ goto out;
63145+ } else {
63146+ if (!proc_fd_access_allowed(inode,1))
63147+ goto out;
63148+ }
63149
63150 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63151 if (error)
63152@@ -1562,7 +1658,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
63153 rcu_read_lock();
63154 cred = __task_cred(task);
63155 inode->i_uid = cred->euid;
63156+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63157+ inode->i_gid = grsec_proc_gid;
63158+#else
63159 inode->i_gid = cred->egid;
63160+#endif
63161 rcu_read_unlock();
63162 }
63163 security_task_to_inode(task, inode);
63164@@ -1598,10 +1698,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
63165 return -ENOENT;
63166 }
63167 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63168+#ifdef CONFIG_GRKERNSEC_PROC_USER
63169+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63170+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63171+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63172+#endif
63173 task_dumpable(task)) {
63174 cred = __task_cred(task);
63175 stat->uid = cred->euid;
63176+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63177+ stat->gid = grsec_proc_gid;
63178+#else
63179 stat->gid = cred->egid;
63180+#endif
63181 }
63182 }
63183 rcu_read_unlock();
63184@@ -1639,11 +1748,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
63185
63186 if (task) {
63187 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63188+#ifdef CONFIG_GRKERNSEC_PROC_USER
63189+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63190+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63191+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63192+#endif
63193 task_dumpable(task)) {
63194 rcu_read_lock();
63195 cred = __task_cred(task);
63196 inode->i_uid = cred->euid;
63197+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63198+ inode->i_gid = grsec_proc_gid;
63199+#else
63200 inode->i_gid = cred->egid;
63201+#endif
63202 rcu_read_unlock();
63203 } else {
63204 inode->i_uid = GLOBAL_ROOT_UID;
63205@@ -2173,6 +2291,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
63206 if (!task)
63207 goto out_no_task;
63208
63209+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63210+ goto out;
63211+
63212 /*
63213 * Yes, it does not scale. And it should not. Don't add
63214 * new entries into /proc/<tgid>/ without very good reasons.
63215@@ -2203,6 +2324,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
63216 if (!task)
63217 return -ENOENT;
63218
63219+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63220+ goto out;
63221+
63222 if (!dir_emit_dots(file, ctx))
63223 goto out;
63224
63225@@ -2592,7 +2716,7 @@ static const struct pid_entry tgid_base_stuff[] = {
63226 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
63227 #endif
63228 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63229-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63230+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63231 INF("syscall", S_IRUGO, proc_pid_syscall),
63232 #endif
63233 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63234@@ -2617,10 +2741,10 @@ static const struct pid_entry tgid_base_stuff[] = {
63235 #ifdef CONFIG_SECURITY
63236 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63237 #endif
63238-#ifdef CONFIG_KALLSYMS
63239+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63240 INF("wchan", S_IRUGO, proc_pid_wchan),
63241 #endif
63242-#ifdef CONFIG_STACKTRACE
63243+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63244 ONE("stack", S_IRUGO, proc_pid_stack),
63245 #endif
63246 #ifdef CONFIG_SCHEDSTATS
63247@@ -2654,6 +2778,9 @@ static const struct pid_entry tgid_base_stuff[] = {
63248 #ifdef CONFIG_HARDWALL
63249 INF("hardwall", S_IRUGO, proc_pid_hardwall),
63250 #endif
63251+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63252+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
63253+#endif
63254 #ifdef CONFIG_USER_NS
63255 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
63256 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
63257@@ -2784,7 +2911,14 @@ static int proc_pid_instantiate(struct inode *dir,
63258 if (!inode)
63259 goto out;
63260
63261+#ifdef CONFIG_GRKERNSEC_PROC_USER
63262+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
63263+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63264+ inode->i_gid = grsec_proc_gid;
63265+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
63266+#else
63267 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
63268+#endif
63269 inode->i_op = &proc_tgid_base_inode_operations;
63270 inode->i_fop = &proc_tgid_base_operations;
63271 inode->i_flags|=S_IMMUTABLE;
63272@@ -2822,7 +2956,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
63273 if (!task)
63274 goto out;
63275
63276+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63277+ goto out_put_task;
63278+
63279 result = proc_pid_instantiate(dir, dentry, task, NULL);
63280+out_put_task:
63281 put_task_struct(task);
63282 out:
63283 return ERR_PTR(result);
63284@@ -2928,7 +3066,7 @@ static const struct pid_entry tid_base_stuff[] = {
63285 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
63286 #endif
63287 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63288-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63289+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63290 INF("syscall", S_IRUGO, proc_pid_syscall),
63291 #endif
63292 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63293@@ -2955,10 +3093,10 @@ static const struct pid_entry tid_base_stuff[] = {
63294 #ifdef CONFIG_SECURITY
63295 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63296 #endif
63297-#ifdef CONFIG_KALLSYMS
63298+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63299 INF("wchan", S_IRUGO, proc_pid_wchan),
63300 #endif
63301-#ifdef CONFIG_STACKTRACE
63302+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63303 ONE("stack", S_IRUGO, proc_pid_stack),
63304 #endif
63305 #ifdef CONFIG_SCHEDSTATS
63306diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
63307index 82676e3..5f8518a 100644
63308--- a/fs/proc/cmdline.c
63309+++ b/fs/proc/cmdline.c
63310@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
63311
63312 static int __init proc_cmdline_init(void)
63313 {
63314+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63315+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
63316+#else
63317 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
63318+#endif
63319 return 0;
63320 }
63321 module_init(proc_cmdline_init);
63322diff --git a/fs/proc/devices.c b/fs/proc/devices.c
63323index b143471..bb105e5 100644
63324--- a/fs/proc/devices.c
63325+++ b/fs/proc/devices.c
63326@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
63327
63328 static int __init proc_devices_init(void)
63329 {
63330+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63331+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
63332+#else
63333 proc_create("devices", 0, NULL, &proc_devinfo_operations);
63334+#endif
63335 return 0;
63336 }
63337 module_init(proc_devices_init);
63338diff --git a/fs/proc/fd.c b/fs/proc/fd.c
63339index 985ea88..d118a0a 100644
63340--- a/fs/proc/fd.c
63341+++ b/fs/proc/fd.c
63342@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
63343 if (!task)
63344 return -ENOENT;
63345
63346- files = get_files_struct(task);
63347+ if (!gr_acl_handle_procpidmem(task))
63348+ files = get_files_struct(task);
63349 put_task_struct(task);
63350
63351 if (files) {
63352@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
63353 */
63354 int proc_fd_permission(struct inode *inode, int mask)
63355 {
63356+ struct task_struct *task;
63357 int rv = generic_permission(inode, mask);
63358- if (rv == 0)
63359- return 0;
63360+
63361 if (task_tgid(current) == proc_pid(inode))
63362 rv = 0;
63363+
63364+ task = get_proc_task(inode);
63365+ if (task == NULL)
63366+ return rv;
63367+
63368+ if (gr_acl_handle_procpidmem(task))
63369+ rv = -EACCES;
63370+
63371+ put_task_struct(task);
63372+
63373 return rv;
63374 }
63375
63376diff --git a/fs/proc/inode.c b/fs/proc/inode.c
63377index 124fc43..8afbb02 100644
63378--- a/fs/proc/inode.c
63379+++ b/fs/proc/inode.c
63380@@ -23,11 +23,17 @@
63381 #include <linux/slab.h>
63382 #include <linux/mount.h>
63383 #include <linux/magic.h>
63384+#include <linux/grsecurity.h>
63385
63386 #include <asm/uaccess.h>
63387
63388 #include "internal.h"
63389
63390+#ifdef CONFIG_PROC_SYSCTL
63391+extern const struct inode_operations proc_sys_inode_operations;
63392+extern const struct inode_operations proc_sys_dir_operations;
63393+#endif
63394+
63395 static void proc_evict_inode(struct inode *inode)
63396 {
63397 struct proc_dir_entry *de;
63398@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
63399 ns = PROC_I(inode)->ns.ns;
63400 if (ns_ops && ns)
63401 ns_ops->put(ns);
63402+
63403+#ifdef CONFIG_PROC_SYSCTL
63404+ if (inode->i_op == &proc_sys_inode_operations ||
63405+ inode->i_op == &proc_sys_dir_operations)
63406+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
63407+#endif
63408+
63409 }
63410
63411 static struct kmem_cache * proc_inode_cachep;
63412@@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
63413 if (de->mode) {
63414 inode->i_mode = de->mode;
63415 inode->i_uid = de->uid;
63416+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63417+ inode->i_gid = grsec_proc_gid;
63418+#else
63419 inode->i_gid = de->gid;
63420+#endif
63421 }
63422 if (de->size)
63423 inode->i_size = de->size;
63424diff --git a/fs/proc/internal.h b/fs/proc/internal.h
63425index 651d09a..3d7f0bf 100644
63426--- a/fs/proc/internal.h
63427+++ b/fs/proc/internal.h
63428@@ -48,7 +48,7 @@ struct proc_dir_entry {
63429 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
63430 u8 namelen;
63431 char name[];
63432-};
63433+} __randomize_layout;
63434
63435 union proc_op {
63436 int (*proc_get_link)(struct dentry *, struct path *);
63437@@ -67,7 +67,7 @@ struct proc_inode {
63438 struct ctl_table *sysctl_entry;
63439 struct proc_ns ns;
63440 struct inode vfs_inode;
63441-};
63442+} __randomize_layout;
63443
63444 /*
63445 * General functions
63446@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
63447 struct pid *, struct task_struct *);
63448 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
63449 struct pid *, struct task_struct *);
63450+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63451+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
63452+#endif
63453
63454 /*
63455 * base.c
63456diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
63457index 05029c0..7ea1987 100644
63458--- a/fs/proc/interrupts.c
63459+++ b/fs/proc/interrupts.c
63460@@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
63461
63462 static int __init proc_interrupts_init(void)
63463 {
63464+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63465+ proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
63466+#else
63467 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
63468+#endif
63469 return 0;
63470 }
63471 module_init(proc_interrupts_init);
63472diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
63473index 5ed0e52..a1c1f2e 100644
63474--- a/fs/proc/kcore.c
63475+++ b/fs/proc/kcore.c
63476@@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63477 * the addresses in the elf_phdr on our list.
63478 */
63479 start = kc_offset_to_vaddr(*fpos - elf_buflen);
63480- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
63481+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
63482+ if (tsz > buflen)
63483 tsz = buflen;
63484-
63485+
63486 while (buflen) {
63487 struct kcore_list *m;
63488
63489@@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63490 kfree(elf_buf);
63491 } else {
63492 if (kern_addr_valid(start)) {
63493- unsigned long n;
63494+ char *elf_buf;
63495+ mm_segment_t oldfs;
63496
63497- n = copy_to_user(buffer, (char *)start, tsz);
63498- /*
63499- * We cannot distinguish between fault on source
63500- * and fault on destination. When this happens
63501- * we clear too and hope it will trigger the
63502- * EFAULT again.
63503- */
63504- if (n) {
63505- if (clear_user(buffer + tsz - n,
63506- n))
63507+ elf_buf = kmalloc(tsz, GFP_KERNEL);
63508+ if (!elf_buf)
63509+ return -ENOMEM;
63510+ oldfs = get_fs();
63511+ set_fs(KERNEL_DS);
63512+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
63513+ set_fs(oldfs);
63514+ if (copy_to_user(buffer, elf_buf, tsz)) {
63515+ kfree(elf_buf);
63516 return -EFAULT;
63517+ }
63518 }
63519+ set_fs(oldfs);
63520+ kfree(elf_buf);
63521 } else {
63522 if (clear_user(buffer, tsz))
63523 return -EFAULT;
63524@@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63525
63526 static int open_kcore(struct inode *inode, struct file *filp)
63527 {
63528+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
63529+ return -EPERM;
63530+#endif
63531 if (!capable(CAP_SYS_RAWIO))
63532 return -EPERM;
63533 if (kcore_need_update)
63534diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
63535index a77d2b2..a9153f0 100644
63536--- a/fs/proc/meminfo.c
63537+++ b/fs/proc/meminfo.c
63538@@ -150,7 +150,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
63539 vmi.used >> 10,
63540 vmi.largest_chunk >> 10
63541 #ifdef CONFIG_MEMORY_FAILURE
63542- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63543+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63544 #endif
63545 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
63546 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
63547diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
63548index 5f9bc8a..5c35f08 100644
63549--- a/fs/proc/nommu.c
63550+++ b/fs/proc/nommu.c
63551@@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
63552
63553 if (file) {
63554 seq_pad(m, ' ');
63555- seq_path(m, &file->f_path, "");
63556+ seq_path(m, &file->f_path, "\n\\");
63557 }
63558
63559 seq_putc(m, '\n');
63560diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
63561index 4677bb7..408e936 100644
63562--- a/fs/proc/proc_net.c
63563+++ b/fs/proc/proc_net.c
63564@@ -23,6 +23,7 @@
63565 #include <linux/nsproxy.h>
63566 #include <net/net_namespace.h>
63567 #include <linux/seq_file.h>
63568+#include <linux/grsecurity.h>
63569
63570 #include "internal.h"
63571
63572@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
63573 struct task_struct *task;
63574 struct nsproxy *ns;
63575 struct net *net = NULL;
63576+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63577+ const struct cred *cred = current_cred();
63578+#endif
63579+
63580+#ifdef CONFIG_GRKERNSEC_PROC_USER
63581+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
63582+ return net;
63583+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63584+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
63585+ return net;
63586+#endif
63587
63588 rcu_read_lock();
63589 task = pid_task(proc_pid(dir), PIDTYPE_PID);
63590diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
63591index 7129046..6914844 100644
63592--- a/fs/proc/proc_sysctl.c
63593+++ b/fs/proc/proc_sysctl.c
63594@@ -11,13 +11,21 @@
63595 #include <linux/namei.h>
63596 #include <linux/mm.h>
63597 #include <linux/module.h>
63598+#include <linux/nsproxy.h>
63599+#ifdef CONFIG_GRKERNSEC
63600+#include <net/net_namespace.h>
63601+#endif
63602 #include "internal.h"
63603
63604+extern int gr_handle_chroot_sysctl(const int op);
63605+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
63606+ const int op);
63607+
63608 static const struct dentry_operations proc_sys_dentry_operations;
63609 static const struct file_operations proc_sys_file_operations;
63610-static const struct inode_operations proc_sys_inode_operations;
63611+const struct inode_operations proc_sys_inode_operations;
63612 static const struct file_operations proc_sys_dir_file_operations;
63613-static const struct inode_operations proc_sys_dir_operations;
63614+const struct inode_operations proc_sys_dir_operations;
63615
63616 void proc_sys_poll_notify(struct ctl_table_poll *poll)
63617 {
63618@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
63619
63620 err = NULL;
63621 d_set_d_op(dentry, &proc_sys_dentry_operations);
63622+
63623+ gr_handle_proc_create(dentry, inode);
63624+
63625 d_add(dentry, inode);
63626
63627 out:
63628@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63629 struct inode *inode = file_inode(filp);
63630 struct ctl_table_header *head = grab_header(inode);
63631 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
63632+ int op = write ? MAY_WRITE : MAY_READ;
63633 ssize_t error;
63634 size_t res;
63635
63636@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63637 * and won't be until we finish.
63638 */
63639 error = -EPERM;
63640- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
63641+ if (sysctl_perm(head, table, op))
63642 goto out;
63643
63644 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
63645@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63646 if (!table->proc_handler)
63647 goto out;
63648
63649+#ifdef CONFIG_GRKERNSEC
63650+ error = -EPERM;
63651+ if (gr_handle_chroot_sysctl(op))
63652+ goto out;
63653+ dget(filp->f_path.dentry);
63654+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
63655+ dput(filp->f_path.dentry);
63656+ goto out;
63657+ }
63658+ dput(filp->f_path.dentry);
63659+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
63660+ goto out;
63661+ if (write) {
63662+ if (current->nsproxy->net_ns != table->extra2) {
63663+ if (!capable(CAP_SYS_ADMIN))
63664+ goto out;
63665+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
63666+ goto out;
63667+ }
63668+#endif
63669+
63670 /* careful: calling conventions are nasty here */
63671 res = count;
63672 error = table->proc_handler(table, write, buf, &res, ppos);
63673@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
63674 return false;
63675 } else {
63676 d_set_d_op(child, &proc_sys_dentry_operations);
63677+
63678+ gr_handle_proc_create(child, inode);
63679+
63680 d_add(child, inode);
63681 }
63682 } else {
63683@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
63684 if ((*pos)++ < ctx->pos)
63685 return true;
63686
63687+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
63688+ return 0;
63689+
63690 if (unlikely(S_ISLNK(table->mode)))
63691 res = proc_sys_link_fill_cache(file, ctx, head, table);
63692 else
63693@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
63694 if (IS_ERR(head))
63695 return PTR_ERR(head);
63696
63697+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
63698+ return -ENOENT;
63699+
63700 generic_fillattr(inode, stat);
63701 if (table)
63702 stat->mode = (stat->mode & S_IFMT) | table->mode;
63703@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
63704 .llseek = generic_file_llseek,
63705 };
63706
63707-static const struct inode_operations proc_sys_inode_operations = {
63708+const struct inode_operations proc_sys_inode_operations = {
63709 .permission = proc_sys_permission,
63710 .setattr = proc_sys_setattr,
63711 .getattr = proc_sys_getattr,
63712 };
63713
63714-static const struct inode_operations proc_sys_dir_operations = {
63715+const struct inode_operations proc_sys_dir_operations = {
63716 .lookup = proc_sys_lookup,
63717 .permission = proc_sys_permission,
63718 .setattr = proc_sys_setattr,
63719@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
63720 static struct ctl_dir *new_dir(struct ctl_table_set *set,
63721 const char *name, int namelen)
63722 {
63723- struct ctl_table *table;
63724+ ctl_table_no_const *table;
63725 struct ctl_dir *new;
63726 struct ctl_node *node;
63727 char *new_name;
63728@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
63729 return NULL;
63730
63731 node = (struct ctl_node *)(new + 1);
63732- table = (struct ctl_table *)(node + 1);
63733+ table = (ctl_table_no_const *)(node + 1);
63734 new_name = (char *)(table + 2);
63735 memcpy(new_name, name, namelen);
63736 new_name[namelen] = '\0';
63737@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
63738 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
63739 struct ctl_table_root *link_root)
63740 {
63741- struct ctl_table *link_table, *entry, *link;
63742+ ctl_table_no_const *link_table, *link;
63743+ struct ctl_table *entry;
63744 struct ctl_table_header *links;
63745 struct ctl_node *node;
63746 char *link_name;
63747@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
63748 return NULL;
63749
63750 node = (struct ctl_node *)(links + 1);
63751- link_table = (struct ctl_table *)(node + nr_entries);
63752+ link_table = (ctl_table_no_const *)(node + nr_entries);
63753 link_name = (char *)&link_table[nr_entries + 1];
63754
63755 for (link = link_table, entry = table; entry->procname; link++, entry++) {
63756@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63757 struct ctl_table_header ***subheader, struct ctl_table_set *set,
63758 struct ctl_table *table)
63759 {
63760- struct ctl_table *ctl_table_arg = NULL;
63761- struct ctl_table *entry, *files;
63762+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
63763+ struct ctl_table *entry;
63764 int nr_files = 0;
63765 int nr_dirs = 0;
63766 int err = -ENOMEM;
63767@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63768 nr_files++;
63769 }
63770
63771- files = table;
63772 /* If there are mixed files and directories we need a new table */
63773 if (nr_dirs && nr_files) {
63774- struct ctl_table *new;
63775+ ctl_table_no_const *new;
63776 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
63777 GFP_KERNEL);
63778 if (!files)
63779@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63780 /* Register everything except a directory full of subdirectories */
63781 if (nr_files || !nr_dirs) {
63782 struct ctl_table_header *header;
63783- header = __register_sysctl_table(set, path, files);
63784+ header = __register_sysctl_table(set, path, files ? files : table);
63785 if (!header) {
63786 kfree(ctl_table_arg);
63787 goto out;
63788diff --git a/fs/proc/root.c b/fs/proc/root.c
63789index 87dbcbe..55e1b4d 100644
63790--- a/fs/proc/root.c
63791+++ b/fs/proc/root.c
63792@@ -186,7 +186,15 @@ void __init proc_root_init(void)
63793 #ifdef CONFIG_PROC_DEVICETREE
63794 proc_device_tree_init();
63795 #endif
63796+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63797+#ifdef CONFIG_GRKERNSEC_PROC_USER
63798+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
63799+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63800+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
63801+#endif
63802+#else
63803 proc_mkdir("bus", NULL);
63804+#endif
63805 proc_sys_init();
63806 }
63807
63808diff --git a/fs/proc/stat.c b/fs/proc/stat.c
63809index 1cf86c0..0ee1ca5 100644
63810--- a/fs/proc/stat.c
63811+++ b/fs/proc/stat.c
63812@@ -11,6 +11,7 @@
63813 #include <linux/irqnr.h>
63814 #include <asm/cputime.h>
63815 #include <linux/tick.h>
63816+#include <linux/grsecurity.h>
63817
63818 #ifndef arch_irq_stat_cpu
63819 #define arch_irq_stat_cpu(cpu) 0
63820@@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
63821 u64 sum_softirq = 0;
63822 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
63823 struct timespec boottime;
63824+ int unrestricted = 1;
63825+
63826+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63827+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63828+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
63829+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63830+ && !in_group_p(grsec_proc_gid)
63831+#endif
63832+ )
63833+ unrestricted = 0;
63834+#endif
63835+#endif
63836
63837 user = nice = system = idle = iowait =
63838 irq = softirq = steal = 0;
63839@@ -94,6 +107,7 @@ static int show_stat(struct seq_file *p, void *v)
63840 getboottime(&boottime);
63841 jif = boottime.tv_sec;
63842
63843+ if (unrestricted) {
63844 for_each_possible_cpu(i) {
63845 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
63846 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
63847@@ -116,6 +130,7 @@ static int show_stat(struct seq_file *p, void *v)
63848 }
63849 }
63850 sum += arch_irq_stat();
63851+ }
63852
63853 seq_puts(p, "cpu ");
63854 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
63855@@ -131,6 +146,7 @@ static int show_stat(struct seq_file *p, void *v)
63856 seq_putc(p, '\n');
63857
63858 for_each_online_cpu(i) {
63859+ if (unrestricted) {
63860 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
63861 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
63862 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
63863@@ -142,6 +158,7 @@ static int show_stat(struct seq_file *p, void *v)
63864 steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
63865 guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
63866 guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
63867+ }
63868 seq_printf(p, "cpu%d", i);
63869 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
63870 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
63871@@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
63872
63873 /* sum again ? it could be updated? */
63874 for_each_irq_nr(j)
63875- seq_put_decimal_ull(p, ' ', kstat_irqs(j));
63876+ seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
63877
63878 seq_printf(p,
63879 "\nctxt %llu\n"
63880@@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
63881 "processes %lu\n"
63882 "procs_running %lu\n"
63883 "procs_blocked %lu\n",
63884- nr_context_switches(),
63885+ unrestricted ? nr_context_switches() : 0ULL,
63886 (unsigned long)jif,
63887- total_forks,
63888- nr_running(),
63889- nr_iowait());
63890+ unrestricted ? total_forks : 0UL,
63891+ unrestricted ? nr_running() : 0UL,
63892+ unrestricted ? nr_iowait() : 0UL);
63893
63894 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
63895
63896diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
63897index fb52b54..5fc7c14 100644
63898--- a/fs/proc/task_mmu.c
63899+++ b/fs/proc/task_mmu.c
63900@@ -12,12 +12,19 @@
63901 #include <linux/swap.h>
63902 #include <linux/swapops.h>
63903 #include <linux/mmu_notifier.h>
63904+#include <linux/grsecurity.h>
63905
63906 #include <asm/elf.h>
63907 #include <asm/uaccess.h>
63908 #include <asm/tlbflush.h>
63909 #include "internal.h"
63910
63911+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63912+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63913+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63914+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63915+#endif
63916+
63917 void task_mem(struct seq_file *m, struct mm_struct *mm)
63918 {
63919 unsigned long data, text, lib, swap;
63920@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
63921 "VmExe:\t%8lu kB\n"
63922 "VmLib:\t%8lu kB\n"
63923 "VmPTE:\t%8lu kB\n"
63924- "VmSwap:\t%8lu kB\n",
63925- hiwater_vm << (PAGE_SHIFT-10),
63926+ "VmSwap:\t%8lu kB\n"
63927+
63928+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63929+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
63930+#endif
63931+
63932+ ,hiwater_vm << (PAGE_SHIFT-10),
63933 total_vm << (PAGE_SHIFT-10),
63934 mm->locked_vm << (PAGE_SHIFT-10),
63935 mm->pinned_vm << (PAGE_SHIFT-10),
63936@@ -64,7 +76,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
63937 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
63938 (PTRS_PER_PTE * sizeof(pte_t) *
63939 atomic_long_read(&mm->nr_ptes)) >> 10,
63940- swap << (PAGE_SHIFT-10));
63941+ swap << (PAGE_SHIFT-10)
63942+
63943+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63944+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63945+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
63946+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
63947+#else
63948+ , mm->context.user_cs_base
63949+ , mm->context.user_cs_limit
63950+#endif
63951+#endif
63952+
63953+ );
63954 }
63955
63956 unsigned long task_vsize(struct mm_struct *mm)
63957@@ -270,13 +294,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63958 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
63959 }
63960
63961- /* We don't show the stack guard page in /proc/maps */
63962+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63963+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
63964+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
63965+#else
63966 start = vma->vm_start;
63967- if (stack_guard_page_start(vma, start))
63968- start += PAGE_SIZE;
63969 end = vma->vm_end;
63970- if (stack_guard_page_end(vma, end))
63971- end -= PAGE_SIZE;
63972+#endif
63973
63974 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
63975 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
63976@@ -286,7 +310,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63977 flags & VM_WRITE ? 'w' : '-',
63978 flags & VM_EXEC ? 'x' : '-',
63979 flags & VM_MAYSHARE ? 's' : 'p',
63980+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63981+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
63982+#else
63983 pgoff,
63984+#endif
63985 MAJOR(dev), MINOR(dev), ino);
63986
63987 /*
63988@@ -295,7 +323,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63989 */
63990 if (file) {
63991 seq_pad(m, ' ');
63992- seq_path(m, &file->f_path, "\n");
63993+ seq_path(m, &file->f_path, "\n\\");
63994 goto done;
63995 }
63996
63997@@ -321,8 +349,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63998 * Thread stack in /proc/PID/task/TID/maps or
63999 * the main process stack.
64000 */
64001- if (!is_pid || (vma->vm_start <= mm->start_stack &&
64002- vma->vm_end >= mm->start_stack)) {
64003+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
64004+ (vma->vm_start <= mm->start_stack &&
64005+ vma->vm_end >= mm->start_stack)) {
64006 name = "[stack]";
64007 } else {
64008 /* Thread stack in /proc/PID/maps */
64009@@ -346,6 +375,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
64010 struct proc_maps_private *priv = m->private;
64011 struct task_struct *task = priv->task;
64012
64013+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64014+ if (current->exec_id != m->exec_id) {
64015+ gr_log_badprocpid("maps");
64016+ return 0;
64017+ }
64018+#endif
64019+
64020 show_map_vma(m, vma, is_pid);
64021
64022 if (m->count < m->size) /* vma is copied successfully */
64023@@ -586,12 +622,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64024 .private = &mss,
64025 };
64026
64027+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64028+ if (current->exec_id != m->exec_id) {
64029+ gr_log_badprocpid("smaps");
64030+ return 0;
64031+ }
64032+#endif
64033 memset(&mss, 0, sizeof mss);
64034- mss.vma = vma;
64035- /* mmap_sem is held in m_start */
64036- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64037- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64038-
64039+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64040+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
64041+#endif
64042+ mss.vma = vma;
64043+ /* mmap_sem is held in m_start */
64044+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64045+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64046+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64047+ }
64048+#endif
64049 show_map_vma(m, vma, is_pid);
64050
64051 seq_printf(m,
64052@@ -609,7 +656,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64053 "KernelPageSize: %8lu kB\n"
64054 "MMUPageSize: %8lu kB\n"
64055 "Locked: %8lu kB\n",
64056+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64057+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
64058+#else
64059 (vma->vm_end - vma->vm_start) >> 10,
64060+#endif
64061 mss.resident >> 10,
64062 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
64063 mss.shared_clean >> 10,
64064@@ -1387,6 +1438,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64065 char buffer[64];
64066 int nid;
64067
64068+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64069+ if (current->exec_id != m->exec_id) {
64070+ gr_log_badprocpid("numa_maps");
64071+ return 0;
64072+ }
64073+#endif
64074+
64075 if (!mm)
64076 return 0;
64077
64078@@ -1404,11 +1462,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64079 mpol_to_str(buffer, sizeof(buffer), pol);
64080 mpol_cond_put(pol);
64081
64082+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64083+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
64084+#else
64085 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
64086+#endif
64087
64088 if (file) {
64089 seq_printf(m, " file=");
64090- seq_path(m, &file->f_path, "\n\t= ");
64091+ seq_path(m, &file->f_path, "\n\t\\= ");
64092 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
64093 seq_printf(m, " heap");
64094 } else {
64095diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
64096index 678455d..ebd3245 100644
64097--- a/fs/proc/task_nommu.c
64098+++ b/fs/proc/task_nommu.c
64099@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64100 else
64101 bytes += kobjsize(mm);
64102
64103- if (current->fs && current->fs->users > 1)
64104+ if (current->fs && atomic_read(&current->fs->users) > 1)
64105 sbytes += kobjsize(current->fs);
64106 else
64107 bytes += kobjsize(current->fs);
64108@@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
64109
64110 if (file) {
64111 seq_pad(m, ' ');
64112- seq_path(m, &file->f_path, "");
64113+ seq_path(m, &file->f_path, "\n\\");
64114 } else if (mm) {
64115 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
64116
64117diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
64118index 9100d69..51cd925 100644
64119--- a/fs/proc/vmcore.c
64120+++ b/fs/proc/vmcore.c
64121@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
64122 nr_bytes = count;
64123
64124 /* If pfn is not ram, return zeros for sparse dump files */
64125- if (pfn_is_ram(pfn) == 0)
64126- memset(buf, 0, nr_bytes);
64127- else {
64128+ if (pfn_is_ram(pfn) == 0) {
64129+ if (userbuf) {
64130+ if (clear_user((char __force_user *)buf, nr_bytes))
64131+ return -EFAULT;
64132+ } else
64133+ memset(buf, 0, nr_bytes);
64134+ } else {
64135 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
64136 offset, userbuf);
64137 if (tmp < 0)
64138@@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
64139 static int copy_to(void *target, void *src, size_t size, int userbuf)
64140 {
64141 if (userbuf) {
64142- if (copy_to_user((char __user *) target, src, size))
64143+ if (copy_to_user((char __force_user *) target, src, size))
64144 return -EFAULT;
64145 } else {
64146 memcpy(target, src, size);
64147@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64148 if (*fpos < m->offset + m->size) {
64149 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
64150 start = m->paddr + *fpos - m->offset;
64151- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
64152+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
64153 if (tmp < 0)
64154 return tmp;
64155 buflen -= tsz;
64156@@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64157 static ssize_t read_vmcore(struct file *file, char __user *buffer,
64158 size_t buflen, loff_t *fpos)
64159 {
64160- return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
64161+ return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
64162 }
64163
64164 /*
64165diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
64166index b00fcc9..e0c6381 100644
64167--- a/fs/qnx6/qnx6.h
64168+++ b/fs/qnx6/qnx6.h
64169@@ -74,7 +74,7 @@ enum {
64170 BYTESEX_BE,
64171 };
64172
64173-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64174+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64175 {
64176 if (sbi->s_bytesex == BYTESEX_LE)
64177 return le64_to_cpu((__force __le64)n);
64178@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
64179 return (__force __fs64)cpu_to_be64(n);
64180 }
64181
64182-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64183+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64184 {
64185 if (sbi->s_bytesex == BYTESEX_LE)
64186 return le32_to_cpu((__force __le32)n);
64187diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
64188index 72d2917..c917c12 100644
64189--- a/fs/quota/netlink.c
64190+++ b/fs/quota/netlink.c
64191@@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
64192 void quota_send_warning(struct kqid qid, dev_t dev,
64193 const char warntype)
64194 {
64195- static atomic_t seq;
64196+ static atomic_unchecked_t seq;
64197 struct sk_buff *skb;
64198 void *msg_head;
64199 int ret;
64200@@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
64201 "VFS: Not enough memory to send quota warning.\n");
64202 return;
64203 }
64204- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
64205+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
64206 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
64207 if (!msg_head) {
64208 printk(KERN_ERR
64209diff --git a/fs/read_write.c b/fs/read_write.c
64210index cfa18df..c110979 100644
64211--- a/fs/read_write.c
64212+++ b/fs/read_write.c
64213@@ -438,7 +438,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
64214
64215 old_fs = get_fs();
64216 set_fs(get_ds());
64217- p = (__force const char __user *)buf;
64218+ p = (const char __force_user *)buf;
64219 if (count > MAX_RW_COUNT)
64220 count = MAX_RW_COUNT;
64221 if (file->f_op->write)
64222diff --git a/fs/readdir.c b/fs/readdir.c
64223index 5b53d99..a6c3049 100644
64224--- a/fs/readdir.c
64225+++ b/fs/readdir.c
64226@@ -17,6 +17,7 @@
64227 #include <linux/security.h>
64228 #include <linux/syscalls.h>
64229 #include <linux/unistd.h>
64230+#include <linux/namei.h>
64231
64232 #include <asm/uaccess.h>
64233
64234@@ -69,6 +70,7 @@ struct old_linux_dirent {
64235 struct readdir_callback {
64236 struct dir_context ctx;
64237 struct old_linux_dirent __user * dirent;
64238+ struct file * file;
64239 int result;
64240 };
64241
64242@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
64243 buf->result = -EOVERFLOW;
64244 return -EOVERFLOW;
64245 }
64246+
64247+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64248+ return 0;
64249+
64250 buf->result++;
64251 dirent = buf->dirent;
64252 if (!access_ok(VERIFY_WRITE, dirent,
64253@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
64254 if (!f.file)
64255 return -EBADF;
64256
64257+ buf.file = f.file;
64258 error = iterate_dir(f.file, &buf.ctx);
64259 if (buf.result)
64260 error = buf.result;
64261@@ -142,6 +149,7 @@ struct getdents_callback {
64262 struct dir_context ctx;
64263 struct linux_dirent __user * current_dir;
64264 struct linux_dirent __user * previous;
64265+ struct file * file;
64266 int count;
64267 int error;
64268 };
64269@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
64270 buf->error = -EOVERFLOW;
64271 return -EOVERFLOW;
64272 }
64273+
64274+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64275+ return 0;
64276+
64277 dirent = buf->previous;
64278 if (dirent) {
64279 if (__put_user(offset, &dirent->d_off))
64280@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
64281 if (!f.file)
64282 return -EBADF;
64283
64284+ buf.file = f.file;
64285 error = iterate_dir(f.file, &buf.ctx);
64286 if (error >= 0)
64287 error = buf.error;
64288@@ -226,6 +239,7 @@ struct getdents_callback64 {
64289 struct dir_context ctx;
64290 struct linux_dirent64 __user * current_dir;
64291 struct linux_dirent64 __user * previous;
64292+ struct file *file;
64293 int count;
64294 int error;
64295 };
64296@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
64297 buf->error = -EINVAL; /* only used if we fail.. */
64298 if (reclen > buf->count)
64299 return -EINVAL;
64300+
64301+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64302+ return 0;
64303+
64304 dirent = buf->previous;
64305 if (dirent) {
64306 if (__put_user(offset, &dirent->d_off))
64307@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
64308 if (!f.file)
64309 return -EBADF;
64310
64311+ buf.file = f.file;
64312 error = iterate_dir(f.file, &buf.ctx);
64313 if (error >= 0)
64314 error = buf.error;
64315diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
64316index 2b7882b..1c5ef48 100644
64317--- a/fs/reiserfs/do_balan.c
64318+++ b/fs/reiserfs/do_balan.c
64319@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
64320 return;
64321 }
64322
64323- atomic_inc(&(fs_generation(tb->tb_sb)));
64324+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
64325 do_balance_starts(tb);
64326
64327 /* balance leaf returns 0 except if combining L R and S into
64328diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
64329index ee382ef..f4eb6eb5 100644
64330--- a/fs/reiserfs/item_ops.c
64331+++ b/fs/reiserfs/item_ops.c
64332@@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
64333 }
64334
64335 static struct item_operations errcatch_ops = {
64336- errcatch_bytes_number,
64337- errcatch_decrement_key,
64338- errcatch_is_left_mergeable,
64339- errcatch_print_item,
64340- errcatch_check_item,
64341+ .bytes_number = errcatch_bytes_number,
64342+ .decrement_key = errcatch_decrement_key,
64343+ .is_left_mergeable = errcatch_is_left_mergeable,
64344+ .print_item = errcatch_print_item,
64345+ .check_item = errcatch_check_item,
64346
64347- errcatch_create_vi,
64348- errcatch_check_left,
64349- errcatch_check_right,
64350- errcatch_part_size,
64351- errcatch_unit_num,
64352- errcatch_print_vi
64353+ .create_vi = errcatch_create_vi,
64354+ .check_left = errcatch_check_left,
64355+ .check_right = errcatch_check_right,
64356+ .part_size = errcatch_part_size,
64357+ .unit_num = errcatch_unit_num,
64358+ .print_vi = errcatch_print_vi
64359 };
64360
64361 //////////////////////////////////////////////////////////////////////////////
64362diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
64363index a958444..42b2323 100644
64364--- a/fs/reiserfs/procfs.c
64365+++ b/fs/reiserfs/procfs.c
64366@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
64367 "SMALL_TAILS " : "NO_TAILS ",
64368 replay_only(sb) ? "REPLAY_ONLY " : "",
64369 convert_reiserfs(sb) ? "CONV " : "",
64370- atomic_read(&r->s_generation_counter),
64371+ atomic_read_unchecked(&r->s_generation_counter),
64372 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
64373 SF(s_do_balance), SF(s_unneeded_left_neighbor),
64374 SF(s_good_search_by_key_reada), SF(s_bmaps),
64375diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
64376index f8adaee..0eeeeca 100644
64377--- a/fs/reiserfs/reiserfs.h
64378+++ b/fs/reiserfs/reiserfs.h
64379@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
64380 /* Comment? -Hans */
64381 wait_queue_head_t s_wait;
64382 /* To be obsoleted soon by per buffer seals.. -Hans */
64383- atomic_t s_generation_counter; // increased by one every time the
64384+ atomic_unchecked_t s_generation_counter; // increased by one every time the
64385 // tree gets re-balanced
64386 unsigned long s_properties; /* File system properties. Currently holds
64387 on-disk FS format */
64388@@ -1982,7 +1982,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
64389 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
64390
64391 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
64392-#define get_generation(s) atomic_read (&fs_generation(s))
64393+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
64394 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
64395 #define __fs_changed(gen,s) (gen != get_generation (s))
64396 #define fs_changed(gen,s) \
64397diff --git a/fs/select.c b/fs/select.c
64398index 467bb1c..cf9d65a 100644
64399--- a/fs/select.c
64400+++ b/fs/select.c
64401@@ -20,6 +20,7 @@
64402 #include <linux/export.h>
64403 #include <linux/slab.h>
64404 #include <linux/poll.h>
64405+#include <linux/security.h>
64406 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
64407 #include <linux/file.h>
64408 #include <linux/fdtable.h>
64409@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
64410 struct poll_list *walk = head;
64411 unsigned long todo = nfds;
64412
64413+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
64414 if (nfds > rlimit(RLIMIT_NOFILE))
64415 return -EINVAL;
64416
64417diff --git a/fs/seq_file.c b/fs/seq_file.c
64418index 1d641bb..e600623 100644
64419--- a/fs/seq_file.c
64420+++ b/fs/seq_file.c
64421@@ -10,6 +10,7 @@
64422 #include <linux/seq_file.h>
64423 #include <linux/slab.h>
64424 #include <linux/cred.h>
64425+#include <linux/sched.h>
64426
64427 #include <asm/uaccess.h>
64428 #include <asm/page.h>
64429@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
64430 #ifdef CONFIG_USER_NS
64431 p->user_ns = file->f_cred->user_ns;
64432 #endif
64433+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64434+ p->exec_id = current->exec_id;
64435+#endif
64436
64437 /*
64438 * Wrappers around seq_open(e.g. swaps_open) need to be
64439@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
64440 return 0;
64441 }
64442 if (!m->buf) {
64443- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64444+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64445 if (!m->buf)
64446 return -ENOMEM;
64447 }
64448@@ -137,7 +141,7 @@ Eoverflow:
64449 m->op->stop(m, p);
64450 kfree(m->buf);
64451 m->count = 0;
64452- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64453+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64454 return !m->buf ? -ENOMEM : -EAGAIN;
64455 }
64456
64457@@ -153,7 +157,7 @@ Eoverflow:
64458 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64459 {
64460 struct seq_file *m = file->private_data;
64461- size_t copied = 0;
64462+ ssize_t copied = 0;
64463 loff_t pos;
64464 size_t n;
64465 void *p;
64466@@ -192,7 +196,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64467
64468 /* grab buffer if we didn't have one */
64469 if (!m->buf) {
64470- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64471+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64472 if (!m->buf)
64473 goto Enomem;
64474 }
64475@@ -234,7 +238,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64476 m->op->stop(m, p);
64477 kfree(m->buf);
64478 m->count = 0;
64479- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64480+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64481 if (!m->buf)
64482 goto Enomem;
64483 m->version = 0;
64484@@ -584,7 +588,7 @@ static void single_stop(struct seq_file *p, void *v)
64485 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
64486 void *data)
64487 {
64488- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
64489+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
64490 int res = -ENOMEM;
64491
64492 if (op) {
64493diff --git a/fs/splice.c b/fs/splice.c
64494index 12028fa..a6f2619 100644
64495--- a/fs/splice.c
64496+++ b/fs/splice.c
64497@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64498 pipe_lock(pipe);
64499
64500 for (;;) {
64501- if (!pipe->readers) {
64502+ if (!atomic_read(&pipe->readers)) {
64503 send_sig(SIGPIPE, current, 0);
64504 if (!ret)
64505 ret = -EPIPE;
64506@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64507 page_nr++;
64508 ret += buf->len;
64509
64510- if (pipe->files)
64511+ if (atomic_read(&pipe->files))
64512 do_wakeup = 1;
64513
64514 if (!--spd->nr_pages)
64515@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64516 do_wakeup = 0;
64517 }
64518
64519- pipe->waiting_writers++;
64520+ atomic_inc(&pipe->waiting_writers);
64521 pipe_wait(pipe);
64522- pipe->waiting_writers--;
64523+ atomic_dec(&pipe->waiting_writers);
64524 }
64525
64526 pipe_unlock(pipe);
64527@@ -583,7 +583,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
64528 old_fs = get_fs();
64529 set_fs(get_ds());
64530 /* The cast to a user pointer is valid due to the set_fs() */
64531- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
64532+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
64533 set_fs(old_fs);
64534
64535 return res;
64536@@ -598,7 +598,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
64537 old_fs = get_fs();
64538 set_fs(get_ds());
64539 /* The cast to a user pointer is valid due to the set_fs() */
64540- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
64541+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
64542 set_fs(old_fs);
64543
64544 return res;
64545@@ -651,7 +651,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
64546 goto err;
64547
64548 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
64549- vec[i].iov_base = (void __user *) page_address(page);
64550+ vec[i].iov_base = (void __force_user *) page_address(page);
64551 vec[i].iov_len = this_len;
64552 spd.pages[i] = page;
64553 spd.nr_pages++;
64554@@ -847,7 +847,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
64555 ops->release(pipe, buf);
64556 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
64557 pipe->nrbufs--;
64558- if (pipe->files)
64559+ if (atomic_read(&pipe->files))
64560 sd->need_wakeup = true;
64561 }
64562
64563@@ -872,10 +872,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
64564 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
64565 {
64566 while (!pipe->nrbufs) {
64567- if (!pipe->writers)
64568+ if (!atomic_read(&pipe->writers))
64569 return 0;
64570
64571- if (!pipe->waiting_writers && sd->num_spliced)
64572+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
64573 return 0;
64574
64575 if (sd->flags & SPLICE_F_NONBLOCK)
64576@@ -1197,7 +1197,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
64577 * out of the pipe right after the splice_to_pipe(). So set
64578 * PIPE_READERS appropriately.
64579 */
64580- pipe->readers = 1;
64581+ atomic_set(&pipe->readers, 1);
64582
64583 current->splice_pipe = pipe;
64584 }
64585@@ -1493,6 +1493,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
64586
64587 partial[buffers].offset = off;
64588 partial[buffers].len = plen;
64589+ partial[buffers].private = 0;
64590
64591 off = 0;
64592 len -= plen;
64593@@ -1795,9 +1796,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64594 ret = -ERESTARTSYS;
64595 break;
64596 }
64597- if (!pipe->writers)
64598+ if (!atomic_read(&pipe->writers))
64599 break;
64600- if (!pipe->waiting_writers) {
64601+ if (!atomic_read(&pipe->waiting_writers)) {
64602 if (flags & SPLICE_F_NONBLOCK) {
64603 ret = -EAGAIN;
64604 break;
64605@@ -1829,7 +1830,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64606 pipe_lock(pipe);
64607
64608 while (pipe->nrbufs >= pipe->buffers) {
64609- if (!pipe->readers) {
64610+ if (!atomic_read(&pipe->readers)) {
64611 send_sig(SIGPIPE, current, 0);
64612 ret = -EPIPE;
64613 break;
64614@@ -1842,9 +1843,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64615 ret = -ERESTARTSYS;
64616 break;
64617 }
64618- pipe->waiting_writers++;
64619+ atomic_inc(&pipe->waiting_writers);
64620 pipe_wait(pipe);
64621- pipe->waiting_writers--;
64622+ atomic_dec(&pipe->waiting_writers);
64623 }
64624
64625 pipe_unlock(pipe);
64626@@ -1880,14 +1881,14 @@ retry:
64627 pipe_double_lock(ipipe, opipe);
64628
64629 do {
64630- if (!opipe->readers) {
64631+ if (!atomic_read(&opipe->readers)) {
64632 send_sig(SIGPIPE, current, 0);
64633 if (!ret)
64634 ret = -EPIPE;
64635 break;
64636 }
64637
64638- if (!ipipe->nrbufs && !ipipe->writers)
64639+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
64640 break;
64641
64642 /*
64643@@ -1984,7 +1985,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
64644 pipe_double_lock(ipipe, opipe);
64645
64646 do {
64647- if (!opipe->readers) {
64648+ if (!atomic_read(&opipe->readers)) {
64649 send_sig(SIGPIPE, current, 0);
64650 if (!ret)
64651 ret = -EPIPE;
64652@@ -2029,7 +2030,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
64653 * return EAGAIN if we have the potential of some data in the
64654 * future, otherwise just return 0
64655 */
64656- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
64657+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
64658 ret = -EAGAIN;
64659
64660 pipe_unlock(ipipe);
64661diff --git a/fs/stat.c b/fs/stat.c
64662index ae0c3ce..9ee641c 100644
64663--- a/fs/stat.c
64664+++ b/fs/stat.c
64665@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
64666 stat->gid = inode->i_gid;
64667 stat->rdev = inode->i_rdev;
64668 stat->size = i_size_read(inode);
64669- stat->atime = inode->i_atime;
64670- stat->mtime = inode->i_mtime;
64671+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
64672+ stat->atime = inode->i_ctime;
64673+ stat->mtime = inode->i_ctime;
64674+ } else {
64675+ stat->atime = inode->i_atime;
64676+ stat->mtime = inode->i_mtime;
64677+ }
64678 stat->ctime = inode->i_ctime;
64679 stat->blksize = (1 << inode->i_blkbits);
64680 stat->blocks = inode->i_blocks;
64681@@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
64682 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
64683 {
64684 struct inode *inode = path->dentry->d_inode;
64685+ int retval;
64686
64687- if (inode->i_op->getattr)
64688- return inode->i_op->getattr(path->mnt, path->dentry, stat);
64689+ if (inode->i_op->getattr) {
64690+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
64691+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
64692+ stat->atime = stat->ctime;
64693+ stat->mtime = stat->ctime;
64694+ }
64695+ return retval;
64696+ }
64697
64698 generic_fillattr(inode, stat);
64699 return 0;
64700diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
64701index 5e73d66..4f165fd 100644
64702--- a/fs/sysfs/dir.c
64703+++ b/fs/sysfs/dir.c
64704@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
64705 *
64706 * Returns 31 bit hash of ns + name (so it fits in an off_t )
64707 */
64708-static unsigned int sysfs_name_hash(const char *name, const void *ns)
64709+static unsigned int sysfs_name_hash(const unsigned char *name, const void *ns)
64710 {
64711 unsigned long hash = init_name_hash();
64712 unsigned int len = strlen(name);
64713@@ -676,6 +676,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
64714 struct sysfs_dirent *sd;
64715 int rc;
64716
64717+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
64718+ const char *parent_name = parent_sd->s_name;
64719+
64720+ mode = S_IFDIR | S_IRWXU;
64721+
64722+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
64723+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
64724+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
64725+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
64726+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
64727+#endif
64728+
64729 /* allocate */
64730 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
64731 if (!sd)
64732diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
64733index 35e7d08..4d6e676 100644
64734--- a/fs/sysfs/file.c
64735+++ b/fs/sysfs/file.c
64736@@ -42,7 +42,7 @@ static DEFINE_MUTEX(sysfs_open_file_mutex);
64737
64738 struct sysfs_open_dirent {
64739 atomic_t refcnt;
64740- atomic_t event;
64741+ atomic_unchecked_t event;
64742 wait_queue_head_t poll;
64743 struct list_head files; /* goes through sysfs_open_file.list */
64744 };
64745@@ -112,7 +112,7 @@ static int sysfs_seq_show(struct seq_file *sf, void *v)
64746 return -ENODEV;
64747 }
64748
64749- of->event = atomic_read(&of->sd->s_attr.open->event);
64750+ of->event = atomic_read_unchecked(&of->sd->s_attr.open->event);
64751
64752 /*
64753 * Lookup @ops and invoke show(). Control may reach here via seq
64754@@ -365,12 +365,12 @@ static int sysfs_bin_page_mkwrite(struct vm_area_struct *vma,
64755 return ret;
64756 }
64757
64758-static int sysfs_bin_access(struct vm_area_struct *vma, unsigned long addr,
64759- void *buf, int len, int write)
64760+static ssize_t sysfs_bin_access(struct vm_area_struct *vma, unsigned long addr,
64761+ void *buf, size_t len, int write)
64762 {
64763 struct file *file = vma->vm_file;
64764 struct sysfs_open_file *of = sysfs_of(file);
64765- int ret;
64766+ ssize_t ret;
64767
64768 if (!of->vm_ops)
64769 return -EINVAL;
64770@@ -564,7 +564,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
64771 return -ENOMEM;
64772
64773 atomic_set(&new_od->refcnt, 0);
64774- atomic_set(&new_od->event, 1);
64775+ atomic_set_unchecked(&new_od->event, 1);
64776 init_waitqueue_head(&new_od->poll);
64777 INIT_LIST_HEAD(&new_od->files);
64778 goto retry;
64779@@ -768,7 +768,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
64780
64781 sysfs_put_active(attr_sd);
64782
64783- if (of->event != atomic_read(&od->event))
64784+ if (of->event != atomic_read_unchecked(&od->event))
64785 goto trigger;
64786
64787 return DEFAULT_POLLMASK;
64788@@ -787,7 +787,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
64789 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
64790 od = sd->s_attr.open;
64791 if (od) {
64792- atomic_inc(&od->event);
64793+ atomic_inc_unchecked(&od->event);
64794 wake_up_interruptible(&od->poll);
64795 }
64796 }
64797diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
64798index 3ae3f1b..081a26c 100644
64799--- a/fs/sysfs/symlink.c
64800+++ b/fs/sysfs/symlink.c
64801@@ -314,7 +314,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
64802 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd,
64803 void *cookie)
64804 {
64805- char *page = nd_get_link(nd);
64806+ const char *page = nd_get_link(nd);
64807 if (!IS_ERR(page))
64808 free_page((unsigned long)page);
64809 }
64810diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
64811index 69d4889..a810bd4 100644
64812--- a/fs/sysv/sysv.h
64813+++ b/fs/sysv/sysv.h
64814@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
64815 #endif
64816 }
64817
64818-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
64819+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
64820 {
64821 if (sbi->s_bytesex == BYTESEX_PDP)
64822 return PDP_swab((__force __u32)n);
64823diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
64824index e18b988..f1d4ad0f 100644
64825--- a/fs/ubifs/io.c
64826+++ b/fs/ubifs/io.c
64827@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
64828 return err;
64829 }
64830
64831-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
64832+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
64833 {
64834 int err;
64835
64836diff --git a/fs/udf/misc.c b/fs/udf/misc.c
64837index c175b4d..8f36a16 100644
64838--- a/fs/udf/misc.c
64839+++ b/fs/udf/misc.c
64840@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
64841
64842 u8 udf_tag_checksum(const struct tag *t)
64843 {
64844- u8 *data = (u8 *)t;
64845+ const u8 *data = (const u8 *)t;
64846 u8 checksum = 0;
64847 int i;
64848 for (i = 0; i < sizeof(struct tag); ++i)
64849diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
64850index 8d974c4..b82f6ec 100644
64851--- a/fs/ufs/swab.h
64852+++ b/fs/ufs/swab.h
64853@@ -22,7 +22,7 @@ enum {
64854 BYTESEX_BE
64855 };
64856
64857-static inline u64
64858+static inline u64 __intentional_overflow(-1)
64859 fs64_to_cpu(struct super_block *sbp, __fs64 n)
64860 {
64861 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
64862@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
64863 return (__force __fs64)cpu_to_be64(n);
64864 }
64865
64866-static inline u32
64867+static inline u32 __intentional_overflow(-1)
64868 fs32_to_cpu(struct super_block *sbp, __fs32 n)
64869 {
64870 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
64871diff --git a/fs/utimes.c b/fs/utimes.c
64872index aa138d6..5f3a811 100644
64873--- a/fs/utimes.c
64874+++ b/fs/utimes.c
64875@@ -1,6 +1,7 @@
64876 #include <linux/compiler.h>
64877 #include <linux/file.h>
64878 #include <linux/fs.h>
64879+#include <linux/security.h>
64880 #include <linux/linkage.h>
64881 #include <linux/mount.h>
64882 #include <linux/namei.h>
64883@@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
64884 }
64885 }
64886 retry_deleg:
64887+
64888+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
64889+ error = -EACCES;
64890+ goto mnt_drop_write_and_out;
64891+ }
64892+
64893 mutex_lock(&inode->i_mutex);
64894 error = notify_change(path->dentry, &newattrs, &delegated_inode);
64895 mutex_unlock(&inode->i_mutex);
64896diff --git a/fs/xattr.c b/fs/xattr.c
64897index 3377dff..f394815 100644
64898--- a/fs/xattr.c
64899+++ b/fs/xattr.c
64900@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
64901 return rc;
64902 }
64903
64904+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
64905+ssize_t
64906+pax_getxattr(struct dentry *dentry, void *value, size_t size)
64907+{
64908+ struct inode *inode = dentry->d_inode;
64909+ ssize_t error;
64910+
64911+ error = inode_permission(inode, MAY_EXEC);
64912+ if (error)
64913+ return error;
64914+
64915+ if (inode->i_op->getxattr)
64916+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
64917+ else
64918+ error = -EOPNOTSUPP;
64919+
64920+ return error;
64921+}
64922+EXPORT_SYMBOL(pax_getxattr);
64923+#endif
64924+
64925 ssize_t
64926 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
64927 {
64928@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
64929 * Extended attribute SET operations
64930 */
64931 static long
64932-setxattr(struct dentry *d, const char __user *name, const void __user *value,
64933+setxattr(struct path *path, const char __user *name, const void __user *value,
64934 size_t size, int flags)
64935 {
64936 int error;
64937@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
64938 posix_acl_fix_xattr_from_user(kvalue, size);
64939 }
64940
64941- error = vfs_setxattr(d, kname, kvalue, size, flags);
64942+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
64943+ error = -EACCES;
64944+ goto out;
64945+ }
64946+
64947+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
64948 out:
64949 if (vvalue)
64950 vfree(vvalue);
64951@@ -377,7 +403,7 @@ retry:
64952 return error;
64953 error = mnt_want_write(path.mnt);
64954 if (!error) {
64955- error = setxattr(path.dentry, name, value, size, flags);
64956+ error = setxattr(&path, name, value, size, flags);
64957 mnt_drop_write(path.mnt);
64958 }
64959 path_put(&path);
64960@@ -401,7 +427,7 @@ retry:
64961 return error;
64962 error = mnt_want_write(path.mnt);
64963 if (!error) {
64964- error = setxattr(path.dentry, name, value, size, flags);
64965+ error = setxattr(&path, name, value, size, flags);
64966 mnt_drop_write(path.mnt);
64967 }
64968 path_put(&path);
64969@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
64970 const void __user *,value, size_t, size, int, flags)
64971 {
64972 struct fd f = fdget(fd);
64973- struct dentry *dentry;
64974 int error = -EBADF;
64975
64976 if (!f.file)
64977 return error;
64978- dentry = f.file->f_path.dentry;
64979- audit_inode(NULL, dentry, 0);
64980+ audit_inode(NULL, f.file->f_path.dentry, 0);
64981 error = mnt_want_write_file(f.file);
64982 if (!error) {
64983- error = setxattr(dentry, name, value, size, flags);
64984+ error = setxattr(&f.file->f_path, name, value, size, flags);
64985 mnt_drop_write_file(f.file);
64986 }
64987 fdput(f);
64988@@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
64989 * Extended attribute REMOVE operations
64990 */
64991 static long
64992-removexattr(struct dentry *d, const char __user *name)
64993+removexattr(struct path *path, const char __user *name)
64994 {
64995 int error;
64996 char kname[XATTR_NAME_MAX + 1];
64997@@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
64998 if (error < 0)
64999 return error;
65000
65001- return vfs_removexattr(d, kname);
65002+ if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
65003+ return -EACCES;
65004+
65005+ return vfs_removexattr(path->dentry, kname);
65006 }
65007
65008 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
65009@@ -652,7 +679,7 @@ retry:
65010 return error;
65011 error = mnt_want_write(path.mnt);
65012 if (!error) {
65013- error = removexattr(path.dentry, name);
65014+ error = removexattr(&path, name);
65015 mnt_drop_write(path.mnt);
65016 }
65017 path_put(&path);
65018@@ -675,7 +702,7 @@ retry:
65019 return error;
65020 error = mnt_want_write(path.mnt);
65021 if (!error) {
65022- error = removexattr(path.dentry, name);
65023+ error = removexattr(&path, name);
65024 mnt_drop_write(path.mnt);
65025 }
65026 path_put(&path);
65027@@ -689,16 +716,16 @@ retry:
65028 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
65029 {
65030 struct fd f = fdget(fd);
65031- struct dentry *dentry;
65032+ struct path *path;
65033 int error = -EBADF;
65034
65035 if (!f.file)
65036 return error;
65037- dentry = f.file->f_path.dentry;
65038- audit_inode(NULL, dentry, 0);
65039+ path = &f.file->f_path;
65040+ audit_inode(NULL, path->dentry, 0);
65041 error = mnt_want_write_file(f.file);
65042 if (!error) {
65043- error = removexattr(dentry, name);
65044+ error = removexattr(path, name);
65045 mnt_drop_write_file(f.file);
65046 }
65047 fdput(f);
65048diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
65049index 9fbea87..417b3c2 100644
65050--- a/fs/xattr_acl.c
65051+++ b/fs/xattr_acl.c
65052@@ -10,6 +10,7 @@
65053 #include <linux/posix_acl_xattr.h>
65054 #include <linux/gfp.h>
65055 #include <linux/user_namespace.h>
65056+#include <linux/grsecurity.h>
65057
65058 /*
65059 * Fix up the uids and gids in posix acl extended attributes in place.
65060@@ -76,11 +77,12 @@ struct posix_acl *
65061 posix_acl_from_xattr(struct user_namespace *user_ns,
65062 const void *value, size_t size)
65063 {
65064- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
65065- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
65066+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
65067+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
65068 int count;
65069 struct posix_acl *acl;
65070 struct posix_acl_entry *acl_e;
65071+ umode_t umask = gr_acl_umask();
65072
65073 if (!value)
65074 return NULL;
65075@@ -106,12 +108,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65076
65077 switch(acl_e->e_tag) {
65078 case ACL_USER_OBJ:
65079+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65080+ break;
65081 case ACL_GROUP_OBJ:
65082 case ACL_MASK:
65083+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65084+ break;
65085 case ACL_OTHER:
65086+ acl_e->e_perm &= ~(umask & S_IRWXO);
65087 break;
65088
65089 case ACL_USER:
65090+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65091 acl_e->e_uid =
65092 make_kuid(user_ns,
65093 le32_to_cpu(entry->e_id));
65094@@ -119,6 +127,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65095 goto fail;
65096 break;
65097 case ACL_GROUP:
65098+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65099 acl_e->e_gid =
65100 make_kgid(user_ns,
65101 le32_to_cpu(entry->e_id));
65102diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
65103index 3b2c14b..de031fe 100644
65104--- a/fs/xfs/xfs_bmap.c
65105+++ b/fs/xfs/xfs_bmap.c
65106@@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
65107
65108 #else
65109 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
65110-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
65111+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
65112 #endif /* DEBUG */
65113
65114 /*
65115diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
65116index c4e50c6..8ba93e3 100644
65117--- a/fs/xfs/xfs_dir2_readdir.c
65118+++ b/fs/xfs/xfs_dir2_readdir.c
65119@@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
65120 ino = dp->d_ops->sf_get_ino(sfp, sfep);
65121 filetype = dp->d_ops->sf_get_ftype(sfep);
65122 ctx->pos = off & 0x7fffffff;
65123- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65124+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
65125+ char name[sfep->namelen];
65126+ memcpy(name, sfep->name, sfep->namelen);
65127+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
65128+ return 0;
65129+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65130 xfs_dir3_get_dtype(mp, filetype)))
65131 return 0;
65132 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
65133diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
65134index 33ad9a7..82c18ba 100644
65135--- a/fs/xfs/xfs_ioctl.c
65136+++ b/fs/xfs/xfs_ioctl.c
65137@@ -126,7 +126,7 @@ xfs_find_handle(
65138 }
65139
65140 error = -EFAULT;
65141- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
65142+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
65143 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
65144 goto out_put;
65145
65146diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
65147index 104455b..764c512 100644
65148--- a/fs/xfs/xfs_iops.c
65149+++ b/fs/xfs/xfs_iops.c
65150@@ -397,7 +397,7 @@ xfs_vn_put_link(
65151 struct nameidata *nd,
65152 void *p)
65153 {
65154- char *s = nd_get_link(nd);
65155+ const char *s = nd_get_link(nd);
65156
65157 if (!IS_ERR(s))
65158 kfree(s);
65159diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
65160new file mode 100644
65161index 0000000..81a6826
65162--- /dev/null
65163+++ b/grsecurity/Kconfig
65164@@ -0,0 +1,1160 @@
65165+#
65166+# grecurity configuration
65167+#
65168+menu "Memory Protections"
65169+depends on GRKERNSEC
65170+
65171+config GRKERNSEC_KMEM
65172+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
65173+ default y if GRKERNSEC_CONFIG_AUTO
65174+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
65175+ help
65176+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
65177+ be written to or read from to modify or leak the contents of the running
65178+ kernel. /dev/port will also not be allowed to be opened, writing to
65179+ /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
65180+ If you have module support disabled, enabling this will close up several
65181+ ways that are currently used to insert malicious code into the running
65182+ kernel.
65183+
65184+ Even with this feature enabled, we still highly recommend that
65185+ you use the RBAC system, as it is still possible for an attacker to
65186+ modify the running kernel through other more obscure methods.
65187+
65188+ It is highly recommended that you say Y here if you meet all the
65189+ conditions above.
65190+
65191+config GRKERNSEC_VM86
65192+ bool "Restrict VM86 mode"
65193+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65194+ depends on X86_32
65195+
65196+ help
65197+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
65198+ make use of a special execution mode on 32bit x86 processors called
65199+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
65200+ video cards and will still work with this option enabled. The purpose
65201+ of the option is to prevent exploitation of emulation errors in
65202+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
65203+ Nearly all users should be able to enable this option.
65204+
65205+config GRKERNSEC_IO
65206+ bool "Disable privileged I/O"
65207+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65208+ depends on X86
65209+ select RTC_CLASS
65210+ select RTC_INTF_DEV
65211+ select RTC_DRV_CMOS
65212+
65213+ help
65214+ If you say Y here, all ioperm and iopl calls will return an error.
65215+ Ioperm and iopl can be used to modify the running kernel.
65216+ Unfortunately, some programs need this access to operate properly,
65217+ the most notable of which are XFree86 and hwclock. hwclock can be
65218+ remedied by having RTC support in the kernel, so real-time
65219+ clock support is enabled if this option is enabled, to ensure
65220+ that hwclock operates correctly.
65221+
65222+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
65223+ you may not be able to boot into a graphical environment with this
65224+ option enabled. In this case, you should use the RBAC system instead.
65225+
65226+config GRKERNSEC_JIT_HARDEN
65227+ bool "Harden BPF JIT against spray attacks"
65228+ default y if GRKERNSEC_CONFIG_AUTO
65229+ depends on BPF_JIT && X86
65230+ help
65231+ If you say Y here, the native code generated by the kernel's Berkeley
65232+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
65233+ attacks that attempt to fit attacker-beneficial instructions in
65234+ 32bit immediate fields of JIT-generated native instructions. The
65235+ attacker will generally aim to cause an unintended instruction sequence
65236+ of JIT-generated native code to execute by jumping into the middle of
65237+ a generated instruction. This feature effectively randomizes the 32bit
65238+ immediate constants present in the generated code to thwart such attacks.
65239+
65240+ If you're using KERNEXEC, it's recommended that you enable this option
65241+ to supplement the hardening of the kernel.
65242+
65243+config GRKERNSEC_PERF_HARDEN
65244+ bool "Disable unprivileged PERF_EVENTS usage by default"
65245+ default y if GRKERNSEC_CONFIG_AUTO
65246+ depends on PERF_EVENTS
65247+ help
65248+ If you say Y here, the range of acceptable values for the
65249+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
65250+ default to a new value: 3. When the sysctl is set to this value, no
65251+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
65252+
65253+ Though PERF_EVENTS can be used legitimately for performance monitoring
65254+ and low-level application profiling, it is forced on regardless of
65255+ configuration, has been at fault for several vulnerabilities, and
65256+ creates new opportunities for side channels and other information leaks.
65257+
65258+ This feature puts PERF_EVENTS into a secure default state and permits
65259+ the administrator to change out of it temporarily if unprivileged
65260+ application profiling is needed.
65261+
65262+config GRKERNSEC_RAND_THREADSTACK
65263+ bool "Insert random gaps between thread stacks"
65264+ default y if GRKERNSEC_CONFIG_AUTO
65265+ depends on PAX_RANDMMAP && !PPC
65266+ help
65267+ If you say Y here, a random-sized gap will be enforced between allocated
65268+ thread stacks. Glibc's NPTL and other threading libraries that
65269+ pass MAP_STACK to the kernel for thread stack allocation are supported.
65270+ The implementation currently provides 8 bits of entropy for the gap.
65271+
65272+ Many distributions do not compile threaded remote services with the
65273+ -fstack-check argument to GCC, causing the variable-sized stack-based
65274+ allocator, alloca(), to not probe the stack on allocation. This
65275+ permits an unbounded alloca() to skip over any guard page and potentially
65276+ modify another thread's stack reliably. An enforced random gap
65277+ reduces the reliability of such an attack and increases the chance
65278+ that such a read/write to another thread's stack instead lands in
65279+ an unmapped area, causing a crash and triggering grsecurity's
65280+ anti-bruteforcing logic.
65281+
65282+config GRKERNSEC_PROC_MEMMAP
65283+ bool "Harden ASLR against information leaks and entropy reduction"
65284+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
65285+ depends on PAX_NOEXEC || PAX_ASLR
65286+ help
65287+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
65288+ give no information about the addresses of its mappings if
65289+ PaX features that rely on random addresses are enabled on the task.
65290+ In addition to sanitizing this information and disabling other
65291+ dangerous sources of information, this option causes reads of sensitive
65292+ /proc/<pid> entries where the file descriptor was opened in a different
65293+ task than the one performing the read. Such attempts are logged.
65294+ This option also limits argv/env strings for suid/sgid binaries
65295+ to 512KB to prevent a complete exhaustion of the stack entropy provided
65296+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
65297+ binaries to prevent alternative mmap layouts from being abused.
65298+
65299+ If you use PaX it is essential that you say Y here as it closes up
65300+ several holes that make full ASLR useless locally.
65301+
65302+config GRKERNSEC_BRUTE
65303+ bool "Deter exploit bruteforcing"
65304+ default y if GRKERNSEC_CONFIG_AUTO
65305+ help
65306+ If you say Y here, attempts to bruteforce exploits against forking
65307+ daemons such as apache or sshd, as well as against suid/sgid binaries
65308+ will be deterred. When a child of a forking daemon is killed by PaX
65309+ or crashes due to an illegal instruction or other suspicious signal,
65310+ the parent process will be delayed 30 seconds upon every subsequent
65311+ fork until the administrator is able to assess the situation and
65312+ restart the daemon.
65313+ In the suid/sgid case, the attempt is logged, the user has all their
65314+ existing instances of the suid/sgid binary terminated and will
65315+ be unable to execute any suid/sgid binaries for 15 minutes.
65316+
65317+ It is recommended that you also enable signal logging in the auditing
65318+ section so that logs are generated when a process triggers a suspicious
65319+ signal.
65320+ If the sysctl option is enabled, a sysctl option with name
65321+ "deter_bruteforce" is created.
65322+
65323+config GRKERNSEC_MODHARDEN
65324+ bool "Harden module auto-loading"
65325+ default y if GRKERNSEC_CONFIG_AUTO
65326+ depends on MODULES
65327+ help
65328+ If you say Y here, module auto-loading in response to use of some
65329+ feature implemented by an unloaded module will be restricted to
65330+ root users. Enabling this option helps defend against attacks
65331+ by unprivileged users who abuse the auto-loading behavior to
65332+ cause a vulnerable module to load that is then exploited.
65333+
65334+ If this option prevents a legitimate use of auto-loading for a
65335+ non-root user, the administrator can execute modprobe manually
65336+ with the exact name of the module mentioned in the alert log.
65337+ Alternatively, the administrator can add the module to the list
65338+ of modules loaded at boot by modifying init scripts.
65339+
65340+ Modification of init scripts will most likely be needed on
65341+ Ubuntu servers with encrypted home directory support enabled,
65342+ as the first non-root user logging in will cause the ecb(aes),
65343+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
65344+
65345+config GRKERNSEC_HIDESYM
65346+ bool "Hide kernel symbols"
65347+ default y if GRKERNSEC_CONFIG_AUTO
65348+ select PAX_USERCOPY_SLABS
65349+ help
65350+ If you say Y here, getting information on loaded modules, and
65351+ displaying all kernel symbols through a syscall will be restricted
65352+ to users with CAP_SYS_MODULE. For software compatibility reasons,
65353+ /proc/kallsyms will be restricted to the root user. The RBAC
65354+ system can hide that entry even from root.
65355+
65356+ This option also prevents leaking of kernel addresses through
65357+ several /proc entries.
65358+
65359+ Note that this option is only effective provided the following
65360+ conditions are met:
65361+ 1) The kernel using grsecurity is not precompiled by some distribution
65362+ 2) You have also enabled GRKERNSEC_DMESG
65363+ 3) You are using the RBAC system and hiding other files such as your
65364+ kernel image and System.map. Alternatively, enabling this option
65365+ causes the permissions on /boot, /lib/modules, and the kernel
65366+ source directory to change at compile time to prevent
65367+ reading by non-root users.
65368+ If the above conditions are met, this option will aid in providing a
65369+ useful protection against local kernel exploitation of overflows
65370+ and arbitrary read/write vulnerabilities.
65371+
65372+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
65373+ in addition to this feature.
65374+
65375+config GRKERNSEC_RANDSTRUCT
65376+ bool "Randomize layout of sensitive kernel structures"
65377+ default y if GRKERNSEC_CONFIG_AUTO
65378+ select GRKERNSEC_HIDESYM
65379+ select MODVERSIONS if MODULES
65380+ help
65381+ If you say Y here, the layouts of a number of sensitive kernel
65382+ structures (task, fs, cred, etc) and all structures composed entirely
65383+ of function pointers (aka "ops" structs) will be randomized at compile-time.
65384+ This can introduce the requirement of an additional infoleak
65385+ vulnerability for exploits targeting these structure types.
65386+
65387+ Enabling this feature will introduce some performance impact, slightly
65388+ increase memory usage, and prevent the use of forensic tools like
65389+ Volatility against the system (unless the kernel source tree isn't
65390+ cleaned after kernel installation).
65391+
65392+ The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
65393+ It remains after a make clean to allow for external modules to be compiled
65394+ with the existing seed and will be removed by a make mrproper or
65395+ make distclean.
65396+
65397+ Note that the implementation requires gcc 4.6.4. or newer. You may need
65398+ to install the supporting headers explicitly in addition to the normal
65399+ gcc package.
65400+
65401+config GRKERNSEC_RANDSTRUCT_PERFORMANCE
65402+ bool "Use cacheline-aware structure randomization"
65403+ depends on GRKERNSEC_RANDSTRUCT
65404+ default y if GRKERNSEC_CONFIG_PRIORITY_PERF
65405+ help
65406+ If you say Y here, the RANDSTRUCT randomization will make a best effort
65407+ at restricting randomization to cacheline-sized groups of elements. It
65408+ will further not randomize bitfields in structures. This reduces the
65409+ performance hit of RANDSTRUCT at the cost of weakened randomization.
65410+
65411+config GRKERNSEC_KERN_LOCKOUT
65412+ bool "Active kernel exploit response"
65413+ default y if GRKERNSEC_CONFIG_AUTO
65414+ depends on X86 || ARM || PPC || SPARC
65415+ help
65416+ If you say Y here, when a PaX alert is triggered due to suspicious
65417+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
65418+ or an OOPS occurs due to bad memory accesses, instead of just
65419+ terminating the offending process (and potentially allowing
65420+ a subsequent exploit from the same user), we will take one of two
65421+ actions:
65422+ If the user was root, we will panic the system
65423+ If the user was non-root, we will log the attempt, terminate
65424+ all processes owned by the user, then prevent them from creating
65425+ any new processes until the system is restarted
65426+ This deters repeated kernel exploitation/bruteforcing attempts
65427+ and is useful for later forensics.
65428+
65429+config GRKERNSEC_OLD_ARM_USERLAND
65430+ bool "Old ARM userland compatibility"
65431+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
65432+ help
65433+ If you say Y here, stubs of executable code to perform such operations
65434+ as "compare-exchange" will be placed at fixed locations in the ARM vector
65435+ table. This is unfortunately needed for old ARM userland meant to run
65436+ across a wide range of processors. Without this option enabled,
65437+ the get_tls and data memory barrier stubs will be emulated by the kernel,
65438+ which is enough for Linaro userlands or other userlands designed for v6
65439+ and newer ARM CPUs. It's recommended that you try without this option enabled
65440+ first, and only enable it if your userland does not boot (it will likely fail
65441+ at init time).
65442+
65443+endmenu
65444+menu "Role Based Access Control Options"
65445+depends on GRKERNSEC
65446+
65447+config GRKERNSEC_RBAC_DEBUG
65448+ bool
65449+
65450+config GRKERNSEC_NO_RBAC
65451+ bool "Disable RBAC system"
65452+ help
65453+ If you say Y here, the /dev/grsec device will be removed from the kernel,
65454+ preventing the RBAC system from being enabled. You should only say Y
65455+ here if you have no intention of using the RBAC system, so as to prevent
65456+ an attacker with root access from misusing the RBAC system to hide files
65457+ and processes when loadable module support and /dev/[k]mem have been
65458+ locked down.
65459+
65460+config GRKERNSEC_ACL_HIDEKERN
65461+ bool "Hide kernel processes"
65462+ help
65463+ If you say Y here, all kernel threads will be hidden to all
65464+ processes but those whose subject has the "view hidden processes"
65465+ flag.
65466+
65467+config GRKERNSEC_ACL_MAXTRIES
65468+ int "Maximum tries before password lockout"
65469+ default 3
65470+ help
65471+ This option enforces the maximum number of times a user can attempt
65472+ to authorize themselves with the grsecurity RBAC system before being
65473+ denied the ability to attempt authorization again for a specified time.
65474+ The lower the number, the harder it will be to brute-force a password.
65475+
65476+config GRKERNSEC_ACL_TIMEOUT
65477+ int "Time to wait after max password tries, in seconds"
65478+ default 30
65479+ help
65480+ This option specifies the time the user must wait after attempting to
65481+ authorize to the RBAC system with the maximum number of invalid
65482+ passwords. The higher the number, the harder it will be to brute-force
65483+ a password.
65484+
65485+endmenu
65486+menu "Filesystem Protections"
65487+depends on GRKERNSEC
65488+
65489+config GRKERNSEC_PROC
65490+ bool "Proc restrictions"
65491+ default y if GRKERNSEC_CONFIG_AUTO
65492+ help
65493+ If you say Y here, the permissions of the /proc filesystem
65494+ will be altered to enhance system security and privacy. You MUST
65495+ choose either a user only restriction or a user and group restriction.
65496+ Depending upon the option you choose, you can either restrict users to
65497+ see only the processes they themselves run, or choose a group that can
65498+ view all processes and files normally restricted to root if you choose
65499+ the "restrict to user only" option. NOTE: If you're running identd or
65500+ ntpd as a non-root user, you will have to run it as the group you
65501+ specify here.
65502+
65503+config GRKERNSEC_PROC_USER
65504+ bool "Restrict /proc to user only"
65505+ depends on GRKERNSEC_PROC
65506+ help
65507+ If you say Y here, non-root users will only be able to view their own
65508+ processes, and restricts them from viewing network-related information,
65509+ and viewing kernel symbol and module information.
65510+
65511+config GRKERNSEC_PROC_USERGROUP
65512+ bool "Allow special group"
65513+ default y if GRKERNSEC_CONFIG_AUTO
65514+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
65515+ help
65516+ If you say Y here, you will be able to select a group that will be
65517+ able to view all processes and network-related information. If you've
65518+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
65519+ remain hidden. This option is useful if you want to run identd as
65520+ a non-root user. The group you select may also be chosen at boot time
65521+ via "grsec_proc_gid=" on the kernel commandline.
65522+
65523+config GRKERNSEC_PROC_GID
65524+ int "GID for special group"
65525+ depends on GRKERNSEC_PROC_USERGROUP
65526+ default 1001
65527+
65528+config GRKERNSEC_PROC_ADD
65529+ bool "Additional restrictions"
65530+ default y if GRKERNSEC_CONFIG_AUTO
65531+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
65532+ help
65533+ If you say Y here, additional restrictions will be placed on
65534+ /proc that keep normal users from viewing device information and
65535+ slabinfo information that could be useful for exploits.
65536+
65537+config GRKERNSEC_LINK
65538+ bool "Linking restrictions"
65539+ default y if GRKERNSEC_CONFIG_AUTO
65540+ help
65541+ If you say Y here, /tmp race exploits will be prevented, since users
65542+ will no longer be able to follow symlinks owned by other users in
65543+ world-writable +t directories (e.g. /tmp), unless the owner of the
65544+ symlink is the owner of the directory. users will also not be
65545+ able to hardlink to files they do not own. If the sysctl option is
65546+ enabled, a sysctl option with name "linking_restrictions" is created.
65547+
65548+config GRKERNSEC_SYMLINKOWN
65549+ bool "Kernel-enforced SymlinksIfOwnerMatch"
65550+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
65551+ help
65552+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
65553+ that prevents it from being used as a security feature. As Apache
65554+ verifies the symlink by performing a stat() against the target of
65555+ the symlink before it is followed, an attacker can setup a symlink
65556+ to point to a same-owned file, then replace the symlink with one
65557+ that targets another user's file just after Apache "validates" the
65558+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
65559+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
65560+ will be in place for the group you specify. If the sysctl option
65561+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
65562+ created.
65563+
65564+config GRKERNSEC_SYMLINKOWN_GID
65565+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
65566+ depends on GRKERNSEC_SYMLINKOWN
65567+ default 1006
65568+ help
65569+ Setting this GID determines what group kernel-enforced
65570+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
65571+ is enabled, a sysctl option with name "symlinkown_gid" is created.
65572+
65573+config GRKERNSEC_FIFO
65574+ bool "FIFO restrictions"
65575+ default y if GRKERNSEC_CONFIG_AUTO
65576+ help
65577+ If you say Y here, users will not be able to write to FIFOs they don't
65578+ own in world-writable +t directories (e.g. /tmp), unless the owner of
65579+ the FIFO is the same owner of the directory it's held in. If the sysctl
65580+ option is enabled, a sysctl option with name "fifo_restrictions" is
65581+ created.
65582+
65583+config GRKERNSEC_SYSFS_RESTRICT
65584+ bool "Sysfs/debugfs restriction"
65585+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65586+ depends on SYSFS
65587+ help
65588+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
65589+ any filesystem normally mounted under it (e.g. debugfs) will be
65590+ mostly accessible only by root. These filesystems generally provide access
65591+ to hardware and debug information that isn't appropriate for unprivileged
65592+ users of the system. Sysfs and debugfs have also become a large source
65593+ of new vulnerabilities, ranging from infoleaks to local compromise.
65594+ There has been very little oversight with an eye toward security involved
65595+ in adding new exporters of information to these filesystems, so their
65596+ use is discouraged.
65597+ For reasons of compatibility, a few directories have been whitelisted
65598+ for access by non-root users:
65599+ /sys/fs/selinux
65600+ /sys/fs/fuse
65601+ /sys/devices/system/cpu
65602+
65603+config GRKERNSEC_ROFS
65604+ bool "Runtime read-only mount protection"
65605+ depends on SYSCTL
65606+ help
65607+ If you say Y here, a sysctl option with name "romount_protect" will
65608+ be created. By setting this option to 1 at runtime, filesystems
65609+ will be protected in the following ways:
65610+ * No new writable mounts will be allowed
65611+ * Existing read-only mounts won't be able to be remounted read/write
65612+ * Write operations will be denied on all block devices
65613+ This option acts independently of grsec_lock: once it is set to 1,
65614+ it cannot be turned off. Therefore, please be mindful of the resulting
65615+ behavior if this option is enabled in an init script on a read-only
65616+ filesystem.
65617+ Also be aware that as with other root-focused features, GRKERNSEC_KMEM
65618+ and GRKERNSEC_IO should be enabled and module loading disabled via
65619+ config or at runtime.
65620+ This feature is mainly intended for secure embedded systems.
65621+
65622+
65623+config GRKERNSEC_DEVICE_SIDECHANNEL
65624+ bool "Eliminate stat/notify-based device sidechannels"
65625+ default y if GRKERNSEC_CONFIG_AUTO
65626+ help
65627+ If you say Y here, timing analyses on block or character
65628+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
65629+ will be thwarted for unprivileged users. If a process without
65630+ CAP_MKNOD stats such a device, the last access and last modify times
65631+ will match the device's create time. No access or modify events
65632+ will be triggered through inotify/dnotify/fanotify for such devices.
65633+ This feature will prevent attacks that may at a minimum
65634+ allow an attacker to determine the administrator's password length.
65635+
65636+config GRKERNSEC_CHROOT
65637+ bool "Chroot jail restrictions"
65638+ default y if GRKERNSEC_CONFIG_AUTO
65639+ help
65640+ If you say Y here, you will be able to choose several options that will
65641+ make breaking out of a chrooted jail much more difficult. If you
65642+ encounter no software incompatibilities with the following options, it
65643+ is recommended that you enable each one.
65644+
65645+ Note that the chroot restrictions are not intended to apply to "chroots"
65646+ to directories that are simple bind mounts of the global root filesystem.
65647+ For several other reasons, a user shouldn't expect any significant
65648+ security by performing such a chroot.
65649+
65650+config GRKERNSEC_CHROOT_MOUNT
65651+ bool "Deny mounts"
65652+ default y if GRKERNSEC_CONFIG_AUTO
65653+ depends on GRKERNSEC_CHROOT
65654+ help
65655+ If you say Y here, processes inside a chroot will not be able to
65656+ mount or remount filesystems. If the sysctl option is enabled, a
65657+ sysctl option with name "chroot_deny_mount" is created.
65658+
65659+config GRKERNSEC_CHROOT_DOUBLE
65660+ bool "Deny double-chroots"
65661+ default y if GRKERNSEC_CONFIG_AUTO
65662+ depends on GRKERNSEC_CHROOT
65663+ help
65664+ If you say Y here, processes inside a chroot will not be able to chroot
65665+ again outside the chroot. This is a widely used method of breaking
65666+ out of a chroot jail and should not be allowed. If the sysctl
65667+ option is enabled, a sysctl option with name
65668+ "chroot_deny_chroot" is created.
65669+
65670+config GRKERNSEC_CHROOT_PIVOT
65671+ bool "Deny pivot_root in chroot"
65672+ default y if GRKERNSEC_CONFIG_AUTO
65673+ depends on GRKERNSEC_CHROOT
65674+ help
65675+ If you say Y here, processes inside a chroot will not be able to use
65676+ a function called pivot_root() that was introduced in Linux 2.3.41. It
65677+ works similar to chroot in that it changes the root filesystem. This
65678+ function could be misused in a chrooted process to attempt to break out
65679+ of the chroot, and therefore should not be allowed. If the sysctl
65680+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
65681+ created.
65682+
65683+config GRKERNSEC_CHROOT_CHDIR
65684+ bool "Enforce chdir(\"/\") on all chroots"
65685+ default y if GRKERNSEC_CONFIG_AUTO
65686+ depends on GRKERNSEC_CHROOT
65687+ help
65688+ If you say Y here, the current working directory of all newly-chrooted
65689+ applications will be set to the the root directory of the chroot.
65690+ The man page on chroot(2) states:
65691+ Note that this call does not change the current working
65692+ directory, so that `.' can be outside the tree rooted at
65693+ `/'. In particular, the super-user can escape from a
65694+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
65695+
65696+ It is recommended that you say Y here, since it's not known to break
65697+ any software. If the sysctl option is enabled, a sysctl option with
65698+ name "chroot_enforce_chdir" is created.
65699+
65700+config GRKERNSEC_CHROOT_CHMOD
65701+ bool "Deny (f)chmod +s"
65702+ default y if GRKERNSEC_CONFIG_AUTO
65703+ depends on GRKERNSEC_CHROOT
65704+ help
65705+ If you say Y here, processes inside a chroot will not be able to chmod
65706+ or fchmod files to make them have suid or sgid bits. This protects
65707+ against another published method of breaking a chroot. If the sysctl
65708+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
65709+ created.
65710+
65711+config GRKERNSEC_CHROOT_FCHDIR
65712+ bool "Deny fchdir out of chroot"
65713+ default y if GRKERNSEC_CONFIG_AUTO
65714+ depends on GRKERNSEC_CHROOT
65715+ help
65716+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
65717+ to a file descriptor of the chrooting process that points to a directory
65718+ outside the filesystem will be stopped. If the sysctl option
65719+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
65720+
65721+config GRKERNSEC_CHROOT_MKNOD
65722+ bool "Deny mknod"
65723+ default y if GRKERNSEC_CONFIG_AUTO
65724+ depends on GRKERNSEC_CHROOT
65725+ help
65726+ If you say Y here, processes inside a chroot will not be allowed to
65727+ mknod. The problem with using mknod inside a chroot is that it
65728+ would allow an attacker to create a device entry that is the same
65729+ as one on the physical root of your system, which could range from
65730+ anything from the console device to a device for your harddrive (which
65731+ they could then use to wipe the drive or steal data). It is recommended
65732+ that you say Y here, unless you run into software incompatibilities.
65733+ If the sysctl option is enabled, a sysctl option with name
65734+ "chroot_deny_mknod" is created.
65735+
65736+config GRKERNSEC_CHROOT_SHMAT
65737+ bool "Deny shmat() out of chroot"
65738+ default y if GRKERNSEC_CONFIG_AUTO
65739+ depends on GRKERNSEC_CHROOT
65740+ help
65741+ If you say Y here, processes inside a chroot will not be able to attach
65742+ to shared memory segments that were created outside of the chroot jail.
65743+ It is recommended that you say Y here. If the sysctl option is enabled,
65744+ a sysctl option with name "chroot_deny_shmat" is created.
65745+
65746+config GRKERNSEC_CHROOT_UNIX
65747+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
65748+ default y if GRKERNSEC_CONFIG_AUTO
65749+ depends on GRKERNSEC_CHROOT
65750+ help
65751+ If you say Y here, processes inside a chroot will not be able to
65752+ connect to abstract (meaning not belonging to a filesystem) Unix
65753+ domain sockets that were bound outside of a chroot. It is recommended
65754+ that you say Y here. If the sysctl option is enabled, a sysctl option
65755+ with name "chroot_deny_unix" is created.
65756+
65757+config GRKERNSEC_CHROOT_FINDTASK
65758+ bool "Protect outside processes"
65759+ default y if GRKERNSEC_CONFIG_AUTO
65760+ depends on GRKERNSEC_CHROOT
65761+ help
65762+ If you say Y here, processes inside a chroot will not be able to
65763+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
65764+ getsid, or view any process outside of the chroot. If the sysctl
65765+ option is enabled, a sysctl option with name "chroot_findtask" is
65766+ created.
65767+
65768+config GRKERNSEC_CHROOT_NICE
65769+ bool "Restrict priority changes"
65770+ default y if GRKERNSEC_CONFIG_AUTO
65771+ depends on GRKERNSEC_CHROOT
65772+ help
65773+ If you say Y here, processes inside a chroot will not be able to raise
65774+ the priority of processes in the chroot, or alter the priority of
65775+ processes outside the chroot. This provides more security than simply
65776+ removing CAP_SYS_NICE from the process' capability set. If the
65777+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
65778+ is created.
65779+
65780+config GRKERNSEC_CHROOT_SYSCTL
65781+ bool "Deny sysctl writes"
65782+ default y if GRKERNSEC_CONFIG_AUTO
65783+ depends on GRKERNSEC_CHROOT
65784+ help
65785+ If you say Y here, an attacker in a chroot will not be able to
65786+ write to sysctl entries, either by sysctl(2) or through a /proc
65787+ interface. It is strongly recommended that you say Y here. If the
65788+ sysctl option is enabled, a sysctl option with name
65789+ "chroot_deny_sysctl" is created.
65790+
65791+config GRKERNSEC_CHROOT_CAPS
65792+ bool "Capability restrictions"
65793+ default y if GRKERNSEC_CONFIG_AUTO
65794+ depends on GRKERNSEC_CHROOT
65795+ help
65796+ If you say Y here, the capabilities on all processes within a
65797+ chroot jail will be lowered to stop module insertion, raw i/o,
65798+ system and net admin tasks, rebooting the system, modifying immutable
65799+ files, modifying IPC owned by another, and changing the system time.
65800+ This is left an option because it can break some apps. Disable this
65801+ if your chrooted apps are having problems performing those kinds of
65802+ tasks. If the sysctl option is enabled, a sysctl option with
65803+ name "chroot_caps" is created.
65804+
65805+config GRKERNSEC_CHROOT_INITRD
65806+ bool "Exempt initrd tasks from restrictions"
65807+ default y if GRKERNSEC_CONFIG_AUTO
65808+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
65809+ help
65810+ If you say Y here, tasks started prior to init will be exempted from
65811+ grsecurity's chroot restrictions. This option is mainly meant to
65812+ resolve Plymouth's performing privileged operations unnecessarily
65813+ in a chroot.
65814+
65815+endmenu
65816+menu "Kernel Auditing"
65817+depends on GRKERNSEC
65818+
65819+config GRKERNSEC_AUDIT_GROUP
65820+ bool "Single group for auditing"
65821+ help
65822+ If you say Y here, the exec and chdir logging features will only operate
65823+ on a group you specify. This option is recommended if you only want to
65824+ watch certain users instead of having a large amount of logs from the
65825+ entire system. If the sysctl option is enabled, a sysctl option with
65826+ name "audit_group" is created.
65827+
65828+config GRKERNSEC_AUDIT_GID
65829+ int "GID for auditing"
65830+ depends on GRKERNSEC_AUDIT_GROUP
65831+ default 1007
65832+
65833+config GRKERNSEC_EXECLOG
65834+ bool "Exec logging"
65835+ help
65836+ If you say Y here, all execve() calls will be logged (since the
65837+ other exec*() calls are frontends to execve(), all execution
65838+ will be logged). Useful for shell-servers that like to keep track
65839+ of their users. If the sysctl option is enabled, a sysctl option with
65840+ name "exec_logging" is created.
65841+ WARNING: This option when enabled will produce a LOT of logs, especially
65842+ on an active system.
65843+
65844+config GRKERNSEC_RESLOG
65845+ bool "Resource logging"
65846+ default y if GRKERNSEC_CONFIG_AUTO
65847+ help
65848+ If you say Y here, all attempts to overstep resource limits will
65849+ be logged with the resource name, the requested size, and the current
65850+ limit. It is highly recommended that you say Y here. If the sysctl
65851+ option is enabled, a sysctl option with name "resource_logging" is
65852+ created. If the RBAC system is enabled, the sysctl value is ignored.
65853+
65854+config GRKERNSEC_CHROOT_EXECLOG
65855+ bool "Log execs within chroot"
65856+ help
65857+ If you say Y here, all executions inside a chroot jail will be logged
65858+ to syslog. This can cause a large amount of logs if certain
65859+ applications (eg. djb's daemontools) are installed on the system, and
65860+ is therefore left as an option. If the sysctl option is enabled, a
65861+ sysctl option with name "chroot_execlog" is created.
65862+
65863+config GRKERNSEC_AUDIT_PTRACE
65864+ bool "Ptrace logging"
65865+ help
65866+ If you say Y here, all attempts to attach to a process via ptrace
65867+ will be logged. If the sysctl option is enabled, a sysctl option
65868+ with name "audit_ptrace" is created.
65869+
65870+config GRKERNSEC_AUDIT_CHDIR
65871+ bool "Chdir logging"
65872+ help
65873+ If you say Y here, all chdir() calls will be logged. If the sysctl
65874+ option is enabled, a sysctl option with name "audit_chdir" is created.
65875+
65876+config GRKERNSEC_AUDIT_MOUNT
65877+ bool "(Un)Mount logging"
65878+ help
65879+ If you say Y here, all mounts and unmounts will be logged. If the
65880+ sysctl option is enabled, a sysctl option with name "audit_mount" is
65881+ created.
65882+
65883+config GRKERNSEC_SIGNAL
65884+ bool "Signal logging"
65885+ default y if GRKERNSEC_CONFIG_AUTO
65886+ help
65887+ If you say Y here, certain important signals will be logged, such as
65888+ SIGSEGV, which will as a result inform you of when a error in a program
65889+ occurred, which in some cases could mean a possible exploit attempt.
65890+ If the sysctl option is enabled, a sysctl option with name
65891+ "signal_logging" is created.
65892+
65893+config GRKERNSEC_FORKFAIL
65894+ bool "Fork failure logging"
65895+ help
65896+ If you say Y here, all failed fork() attempts will be logged.
65897+ This could suggest a fork bomb, or someone attempting to overstep
65898+ their process limit. If the sysctl option is enabled, a sysctl option
65899+ with name "forkfail_logging" is created.
65900+
65901+config GRKERNSEC_TIME
65902+ bool "Time change logging"
65903+ default y if GRKERNSEC_CONFIG_AUTO
65904+ help
65905+ If you say Y here, any changes of the system clock will be logged.
65906+ If the sysctl option is enabled, a sysctl option with name
65907+ "timechange_logging" is created.
65908+
65909+config GRKERNSEC_PROC_IPADDR
65910+ bool "/proc/<pid>/ipaddr support"
65911+ default y if GRKERNSEC_CONFIG_AUTO
65912+ help
65913+ If you say Y here, a new entry will be added to each /proc/<pid>
65914+ directory that contains the IP address of the person using the task.
65915+ The IP is carried across local TCP and AF_UNIX stream sockets.
65916+ This information can be useful for IDS/IPSes to perform remote response
65917+ to a local attack. The entry is readable by only the owner of the
65918+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
65919+ the RBAC system), and thus does not create privacy concerns.
65920+
65921+config GRKERNSEC_RWXMAP_LOG
65922+ bool 'Denied RWX mmap/mprotect logging'
65923+ default y if GRKERNSEC_CONFIG_AUTO
65924+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
65925+ help
65926+ If you say Y here, calls to mmap() and mprotect() with explicit
65927+ usage of PROT_WRITE and PROT_EXEC together will be logged when
65928+ denied by the PAX_MPROTECT feature. This feature will also
65929+ log other problematic scenarios that can occur when PAX_MPROTECT
65930+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
65931+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
65932+ is created.
65933+
65934+endmenu
65935+
65936+menu "Executable Protections"
65937+depends on GRKERNSEC
65938+
65939+config GRKERNSEC_DMESG
65940+ bool "Dmesg(8) restriction"
65941+ default y if GRKERNSEC_CONFIG_AUTO
65942+ help
65943+ If you say Y here, non-root users will not be able to use dmesg(8)
65944+ to view the contents of the kernel's circular log buffer.
65945+ The kernel's log buffer often contains kernel addresses and other
65946+ identifying information useful to an attacker in fingerprinting a
65947+ system for a targeted exploit.
65948+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
65949+ created.
65950+
65951+config GRKERNSEC_HARDEN_PTRACE
65952+ bool "Deter ptrace-based process snooping"
65953+ default y if GRKERNSEC_CONFIG_AUTO
65954+ help
65955+ If you say Y here, TTY sniffers and other malicious monitoring
65956+ programs implemented through ptrace will be defeated. If you
65957+ have been using the RBAC system, this option has already been
65958+ enabled for several years for all users, with the ability to make
65959+ fine-grained exceptions.
65960+
65961+ This option only affects the ability of non-root users to ptrace
65962+ processes that are not a descendent of the ptracing process.
65963+ This means that strace ./binary and gdb ./binary will still work,
65964+ but attaching to arbitrary processes will not. If the sysctl
65965+ option is enabled, a sysctl option with name "harden_ptrace" is
65966+ created.
65967+
65968+config GRKERNSEC_PTRACE_READEXEC
65969+ bool "Require read access to ptrace sensitive binaries"
65970+ default y if GRKERNSEC_CONFIG_AUTO
65971+ help
65972+ If you say Y here, unprivileged users will not be able to ptrace unreadable
65973+ binaries. This option is useful in environments that
65974+ remove the read bits (e.g. file mode 4711) from suid binaries to
65975+ prevent infoleaking of their contents. This option adds
65976+ consistency to the use of that file mode, as the binary could normally
65977+ be read out when run without privileges while ptracing.
65978+
65979+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
65980+ is created.
65981+
65982+config GRKERNSEC_SETXID
65983+ bool "Enforce consistent multithreaded privileges"
65984+ default y if GRKERNSEC_CONFIG_AUTO
65985+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
65986+ help
65987+ If you say Y here, a change from a root uid to a non-root uid
65988+ in a multithreaded application will cause the resulting uids,
65989+ gids, supplementary groups, and capabilities in that thread
65990+ to be propagated to the other threads of the process. In most
65991+ cases this is unnecessary, as glibc will emulate this behavior
65992+ on behalf of the application. Other libcs do not act in the
65993+ same way, allowing the other threads of the process to continue
65994+ running with root privileges. If the sysctl option is enabled,
65995+ a sysctl option with name "consistent_setxid" is created.
65996+
65997+config GRKERNSEC_HARDEN_IPC
65998+ bool "Disallow access to overly-permissive IPC objects"
65999+ default y if GRKERNSEC_CONFIG_AUTO
66000+ depends on SYSVIPC
66001+ help
66002+ If you say Y here, access to overly-permissive IPC objects (shared
66003+ memory, message queues, and semaphores) will be denied for processes
66004+ given the following criteria beyond normal permission checks:
66005+ 1) If the IPC object is world-accessible and the euid doesn't match
66006+ that of the creator or current uid for the IPC object
66007+ 2) If the IPC object is group-accessible and the egid doesn't
66008+ match that of the creator or current gid for the IPC object
66009+ It's a common error to grant too much permission to these objects,
66010+ with impact ranging from denial of service and information leaking to
66011+ privilege escalation. This feature was developed in response to
66012+ research by Tim Brown:
66013+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
66014+ who found hundreds of such insecure usages. Processes with
66015+ CAP_IPC_OWNER are still permitted to access these IPC objects.
66016+ If the sysctl option is enabled, a sysctl option with name
66017+ "harden_ipc" is created.
66018+
66019+config GRKERNSEC_TPE
66020+ bool "Trusted Path Execution (TPE)"
66021+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66022+ help
66023+ If you say Y here, you will be able to choose a gid to add to the
66024+ supplementary groups of users you want to mark as "untrusted."
66025+ These users will not be able to execute any files that are not in
66026+ root-owned directories writable only by root. If the sysctl option
66027+ is enabled, a sysctl option with name "tpe" is created.
66028+
66029+config GRKERNSEC_TPE_ALL
66030+ bool "Partially restrict all non-root users"
66031+ depends on GRKERNSEC_TPE
66032+ help
66033+ If you say Y here, all non-root users will be covered under
66034+ a weaker TPE restriction. This is separate from, and in addition to,
66035+ the main TPE options that you have selected elsewhere. Thus, if a
66036+ "trusted" GID is chosen, this restriction applies to even that GID.
66037+ Under this restriction, all non-root users will only be allowed to
66038+ execute files in directories they own that are not group or
66039+ world-writable, or in directories owned by root and writable only by
66040+ root. If the sysctl option is enabled, a sysctl option with name
66041+ "tpe_restrict_all" is created.
66042+
66043+config GRKERNSEC_TPE_INVERT
66044+ bool "Invert GID option"
66045+ depends on GRKERNSEC_TPE
66046+ help
66047+ If you say Y here, the group you specify in the TPE configuration will
66048+ decide what group TPE restrictions will be *disabled* for. This
66049+ option is useful if you want TPE restrictions to be applied to most
66050+ users on the system. If the sysctl option is enabled, a sysctl option
66051+ with name "tpe_invert" is created. Unlike other sysctl options, this
66052+ entry will default to on for backward-compatibility.
66053+
66054+config GRKERNSEC_TPE_GID
66055+ int
66056+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
66057+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
66058+
66059+config GRKERNSEC_TPE_UNTRUSTED_GID
66060+ int "GID for TPE-untrusted users"
66061+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
66062+ default 1005
66063+ help
66064+ Setting this GID determines what group TPE restrictions will be
66065+ *enabled* for. If the sysctl option is enabled, a sysctl option
66066+ with name "tpe_gid" is created.
66067+
66068+config GRKERNSEC_TPE_TRUSTED_GID
66069+ int "GID for TPE-trusted users"
66070+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
66071+ default 1005
66072+ help
66073+ Setting this GID determines what group TPE restrictions will be
66074+ *disabled* for. If the sysctl option is enabled, a sysctl option
66075+ with name "tpe_gid" is created.
66076+
66077+endmenu
66078+menu "Network Protections"
66079+depends on GRKERNSEC
66080+
66081+config GRKERNSEC_RANDNET
66082+ bool "Larger entropy pools"
66083+ default y if GRKERNSEC_CONFIG_AUTO
66084+ help
66085+ If you say Y here, the entropy pools used for many features of Linux
66086+ and grsecurity will be doubled in size. Since several grsecurity
66087+ features use additional randomness, it is recommended that you say Y
66088+ here. Saying Y here has a similar effect as modifying
66089+ /proc/sys/kernel/random/poolsize.
66090+
66091+config GRKERNSEC_BLACKHOLE
66092+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
66093+ default y if GRKERNSEC_CONFIG_AUTO
66094+ depends on NET
66095+ help
66096+ If you say Y here, neither TCP resets nor ICMP
66097+ destination-unreachable packets will be sent in response to packets
66098+ sent to ports for which no associated listening process exists.
66099+ This feature supports both IPV4 and IPV6 and exempts the
66100+ loopback interface from blackholing. Enabling this feature
66101+ makes a host more resilient to DoS attacks and reduces network
66102+ visibility against scanners.
66103+
66104+ The blackhole feature as-implemented is equivalent to the FreeBSD
66105+ blackhole feature, as it prevents RST responses to all packets, not
66106+ just SYNs. Under most application behavior this causes no
66107+ problems, but applications (like haproxy) may not close certain
66108+ connections in a way that cleanly terminates them on the remote
66109+ end, leaving the remote host in LAST_ACK state. Because of this
66110+ side-effect and to prevent intentional LAST_ACK DoSes, this
66111+ feature also adds automatic mitigation against such attacks.
66112+ The mitigation drastically reduces the amount of time a socket
66113+ can spend in LAST_ACK state. If you're using haproxy and not
66114+ all servers it connects to have this option enabled, consider
66115+ disabling this feature on the haproxy host.
66116+
66117+ If the sysctl option is enabled, two sysctl options with names
66118+ "ip_blackhole" and "lastack_retries" will be created.
66119+ While "ip_blackhole" takes the standard zero/non-zero on/off
66120+ toggle, "lastack_retries" uses the same kinds of values as
66121+ "tcp_retries1" and "tcp_retries2". The default value of 4
66122+ prevents a socket from lasting more than 45 seconds in LAST_ACK
66123+ state.
66124+
66125+config GRKERNSEC_NO_SIMULT_CONNECT
66126+ bool "Disable TCP Simultaneous Connect"
66127+ default y if GRKERNSEC_CONFIG_AUTO
66128+ depends on NET
66129+ help
66130+ If you say Y here, a feature by Willy Tarreau will be enabled that
66131+ removes a weakness in Linux's strict implementation of TCP that
66132+ allows two clients to connect to each other without either entering
66133+ a listening state. The weakness allows an attacker to easily prevent
66134+ a client from connecting to a known server provided the source port
66135+ for the connection is guessed correctly.
66136+
66137+ As the weakness could be used to prevent an antivirus or IPS from
66138+ fetching updates, or prevent an SSL gateway from fetching a CRL,
66139+ it should be eliminated by enabling this option. Though Linux is
66140+ one of few operating systems supporting simultaneous connect, it
66141+ has no legitimate use in practice and is rarely supported by firewalls.
66142+
66143+config GRKERNSEC_SOCKET
66144+ bool "Socket restrictions"
66145+ depends on NET
66146+ help
66147+ If you say Y here, you will be able to choose from several options.
66148+ If you assign a GID on your system and add it to the supplementary
66149+ groups of users you want to restrict socket access to, this patch
66150+ will perform up to three things, based on the option(s) you choose.
66151+
66152+config GRKERNSEC_SOCKET_ALL
66153+ bool "Deny any sockets to group"
66154+ depends on GRKERNSEC_SOCKET
66155+ help
66156+ If you say Y here, you will be able to choose a GID of whose users will
66157+ be unable to connect to other hosts from your machine or run server
66158+ applications from your machine. If the sysctl option is enabled, a
66159+ sysctl option with name "socket_all" is created.
66160+
66161+config GRKERNSEC_SOCKET_ALL_GID
66162+ int "GID to deny all sockets for"
66163+ depends on GRKERNSEC_SOCKET_ALL
66164+ default 1004
66165+ help
66166+ Here you can choose the GID to disable socket access for. Remember to
66167+ add the users you want socket access disabled for to the GID
66168+ specified here. If the sysctl option is enabled, a sysctl option
66169+ with name "socket_all_gid" is created.
66170+
66171+config GRKERNSEC_SOCKET_CLIENT
66172+ bool "Deny client sockets to group"
66173+ depends on GRKERNSEC_SOCKET
66174+ help
66175+ If you say Y here, you will be able to choose a GID of whose users will
66176+ be unable to connect to other hosts from your machine, but will be
66177+ able to run servers. If this option is enabled, all users in the group
66178+ you specify will have to use passive mode when initiating ftp transfers
66179+ from the shell on your machine. If the sysctl option is enabled, a
66180+ sysctl option with name "socket_client" is created.
66181+
66182+config GRKERNSEC_SOCKET_CLIENT_GID
66183+ int "GID to deny client sockets for"
66184+ depends on GRKERNSEC_SOCKET_CLIENT
66185+ default 1003
66186+ help
66187+ Here you can choose the GID to disable client socket access for.
66188+ Remember to add the users you want client socket access disabled for to
66189+ the GID specified here. If the sysctl option is enabled, a sysctl
66190+ option with name "socket_client_gid" is created.
66191+
66192+config GRKERNSEC_SOCKET_SERVER
66193+ bool "Deny server sockets to group"
66194+ depends on GRKERNSEC_SOCKET
66195+ help
66196+ If you say Y here, you will be able to choose a GID of whose users will
66197+ be unable to run server applications from your machine. If the sysctl
66198+ option is enabled, a sysctl option with name "socket_server" is created.
66199+
66200+config GRKERNSEC_SOCKET_SERVER_GID
66201+ int "GID to deny server sockets for"
66202+ depends on GRKERNSEC_SOCKET_SERVER
66203+ default 1002
66204+ help
66205+ Here you can choose the GID to disable server socket access for.
66206+ Remember to add the users you want server socket access disabled for to
66207+ the GID specified here. If the sysctl option is enabled, a sysctl
66208+ option with name "socket_server_gid" is created.
66209+
66210+endmenu
66211+
66212+menu "Physical Protections"
66213+depends on GRKERNSEC
66214+
66215+config GRKERNSEC_DENYUSB
66216+ bool "Deny new USB connections after toggle"
66217+ default y if GRKERNSEC_CONFIG_AUTO
66218+ depends on SYSCTL && USB_SUPPORT
66219+ help
66220+ If you say Y here, a new sysctl option with name "deny_new_usb"
66221+ will be created. Setting its value to 1 will prevent any new
66222+ USB devices from being recognized by the OS. Any attempted USB
66223+ device insertion will be logged. This option is intended to be
66224+ used against custom USB devices designed to exploit vulnerabilities
66225+ in various USB device drivers.
66226+
66227+ For greatest effectiveness, this sysctl should be set after any
66228+ relevant init scripts. This option is safe to enable in distros
66229+ as each user can choose whether or not to toggle the sysctl.
66230+
66231+config GRKERNSEC_DENYUSB_FORCE
66232+ bool "Reject all USB devices not connected at boot"
66233+ select USB
66234+ depends on GRKERNSEC_DENYUSB
66235+ help
66236+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
66237+ that doesn't involve a sysctl entry. This option should only be
66238+ enabled if you're sure you want to deny all new USB connections
66239+ at runtime and don't want to modify init scripts. This should not
66240+ be enabled by distros. It forces the core USB code to be built
66241+ into the kernel image so that all devices connected at boot time
66242+ can be recognized and new USB device connections can be prevented
66243+ prior to init running.
66244+
66245+endmenu
66246+
66247+menu "Sysctl Support"
66248+depends on GRKERNSEC && SYSCTL
66249+
66250+config GRKERNSEC_SYSCTL
66251+ bool "Sysctl support"
66252+ default y if GRKERNSEC_CONFIG_AUTO
66253+ help
66254+ If you say Y here, you will be able to change the options that
66255+ grsecurity runs with at bootup, without having to recompile your
66256+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
66257+ to enable (1) or disable (0) various features. All the sysctl entries
66258+ are mutable until the "grsec_lock" entry is set to a non-zero value.
66259+ All features enabled in the kernel configuration are disabled at boot
66260+ if you do not say Y to the "Turn on features by default" option.
66261+ All options should be set at startup, and the grsec_lock entry should
66262+ be set to a non-zero value after all the options are set.
66263+ *THIS IS EXTREMELY IMPORTANT*
66264+
66265+config GRKERNSEC_SYSCTL_DISTRO
66266+ bool "Extra sysctl support for distro makers (READ HELP)"
66267+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
66268+ help
66269+ If you say Y here, additional sysctl options will be created
66270+ for features that affect processes running as root. Therefore,
66271+ it is critical when using this option that the grsec_lock entry be
66272+ enabled after boot. Only distros with prebuilt kernel packages
66273+ with this option enabled that can ensure grsec_lock is enabled
66274+ after boot should use this option.
66275+ *Failure to set grsec_lock after boot makes all grsec features
66276+ this option covers useless*
66277+
66278+ Currently this option creates the following sysctl entries:
66279+ "Disable Privileged I/O": "disable_priv_io"
66280+
66281+config GRKERNSEC_SYSCTL_ON
66282+ bool "Turn on features by default"
66283+ default y if GRKERNSEC_CONFIG_AUTO
66284+ depends on GRKERNSEC_SYSCTL
66285+ help
66286+ If you say Y here, instead of having all features enabled in the
66287+ kernel configuration disabled at boot time, the features will be
66288+ enabled at boot time. It is recommended you say Y here unless
66289+ there is some reason you would want all sysctl-tunable features to
66290+ be disabled by default. As mentioned elsewhere, it is important
66291+ to enable the grsec_lock entry once you have finished modifying
66292+ the sysctl entries.
66293+
66294+endmenu
66295+menu "Logging Options"
66296+depends on GRKERNSEC
66297+
66298+config GRKERNSEC_FLOODTIME
66299+ int "Seconds in between log messages (minimum)"
66300+ default 10
66301+ help
66302+ This option allows you to enforce the number of seconds between
66303+ grsecurity log messages. The default should be suitable for most
66304+ people, however, if you choose to change it, choose a value small enough
66305+ to allow informative logs to be produced, but large enough to
66306+ prevent flooding.
66307+
66308+ Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
66309+ any rate limiting on grsecurity log messages.
66310+
66311+config GRKERNSEC_FLOODBURST
66312+ int "Number of messages in a burst (maximum)"
66313+ default 6
66314+ help
66315+ This option allows you to choose the maximum number of messages allowed
66316+ within the flood time interval you chose in a separate option. The
66317+ default should be suitable for most people, however if you find that
66318+ many of your logs are being interpreted as flooding, you may want to
66319+ raise this value.
66320+
66321+ Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
66322+ any rate limiting on grsecurity log messages.
66323+
66324+endmenu
66325diff --git a/grsecurity/Makefile b/grsecurity/Makefile
66326new file mode 100644
66327index 0000000..5307c8a
66328--- /dev/null
66329+++ b/grsecurity/Makefile
66330@@ -0,0 +1,54 @@
66331+# grsecurity – access control and security hardening for Linux
66332+# All code in this directory and various hooks located throughout the Linux kernel are
66333+# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
66334+# http://www.grsecurity.net spender@grsecurity.net
66335+#
66336+# This program is free software; you can redistribute it and/or
66337+# modify it under the terms of the GNU General Public License version 2
66338+# as published by the Free Software Foundation.
66339+#
66340+# This program is distributed in the hope that it will be useful,
66341+# but WITHOUT ANY WARRANTY; without even the implied warranty of
66342+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66343+# GNU General Public License for more details.
66344+#
66345+# You should have received a copy of the GNU General Public License
66346+# along with this program; if not, write to the Free Software
66347+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
66348+
66349+KBUILD_CFLAGS += -Werror
66350+
66351+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
66352+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
66353+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
66354+ grsec_usb.o grsec_ipc.o
66355+
66356+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
66357+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
66358+ gracl_learn.o grsec_log.o gracl_policy.o
66359+ifdef CONFIG_COMPAT
66360+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
66361+endif
66362+
66363+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
66364+
66365+ifdef CONFIG_NET
66366+obj-y += grsec_sock.o
66367+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
66368+endif
66369+
66370+ifndef CONFIG_GRKERNSEC
66371+obj-y += grsec_disabled.o
66372+endif
66373+
66374+ifdef CONFIG_GRKERNSEC_HIDESYM
66375+extra-y := grsec_hidesym.o
66376+$(obj)/grsec_hidesym.o:
66377+ @-chmod -f 500 /boot
66378+ @-chmod -f 500 /lib/modules
66379+ @-chmod -f 500 /lib64/modules
66380+ @-chmod -f 500 /lib32/modules
66381+ @-chmod -f 700 .
66382+ @-chmod -f 700 $(objtree)
66383+ @echo ' grsec: protected kernel image paths'
66384+endif
66385diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
66386new file mode 100644
66387index 0000000..e56396f
66388--- /dev/null
66389+++ b/grsecurity/gracl.c
66390@@ -0,0 +1,2679 @@
66391+#include <linux/kernel.h>
66392+#include <linux/module.h>
66393+#include <linux/sched.h>
66394+#include <linux/mm.h>
66395+#include <linux/file.h>
66396+#include <linux/fs.h>
66397+#include <linux/namei.h>
66398+#include <linux/mount.h>
66399+#include <linux/tty.h>
66400+#include <linux/proc_fs.h>
66401+#include <linux/lglock.h>
66402+#include <linux/slab.h>
66403+#include <linux/vmalloc.h>
66404+#include <linux/types.h>
66405+#include <linux/sysctl.h>
66406+#include <linux/netdevice.h>
66407+#include <linux/ptrace.h>
66408+#include <linux/gracl.h>
66409+#include <linux/gralloc.h>
66410+#include <linux/security.h>
66411+#include <linux/grinternal.h>
66412+#include <linux/pid_namespace.h>
66413+#include <linux/stop_machine.h>
66414+#include <linux/fdtable.h>
66415+#include <linux/percpu.h>
66416+#include <linux/lglock.h>
66417+#include <linux/hugetlb.h>
66418+#include <linux/posix-timers.h>
66419+#include <linux/prefetch.h>
66420+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66421+#include <linux/magic.h>
66422+#include <linux/pagemap.h>
66423+#include "../fs/btrfs/async-thread.h"
66424+#include "../fs/btrfs/ctree.h"
66425+#include "../fs/btrfs/btrfs_inode.h"
66426+#endif
66427+#include "../fs/mount.h"
66428+
66429+#include <asm/uaccess.h>
66430+#include <asm/errno.h>
66431+#include <asm/mman.h>
66432+
66433+#define FOR_EACH_ROLE_START(role) \
66434+ role = running_polstate.role_list; \
66435+ while (role) {
66436+
66437+#define FOR_EACH_ROLE_END(role) \
66438+ role = role->prev; \
66439+ }
66440+
66441+extern struct path gr_real_root;
66442+
66443+static struct gr_policy_state running_polstate;
66444+struct gr_policy_state *polstate = &running_polstate;
66445+extern struct gr_alloc_state *current_alloc_state;
66446+
66447+extern char *gr_shared_page[4];
66448+DEFINE_RWLOCK(gr_inode_lock);
66449+
66450+static unsigned int gr_status __read_only = GR_STATUS_INIT;
66451+
66452+#ifdef CONFIG_NET
66453+extern struct vfsmount *sock_mnt;
66454+#endif
66455+
66456+extern struct vfsmount *pipe_mnt;
66457+extern struct vfsmount *shm_mnt;
66458+
66459+#ifdef CONFIG_HUGETLBFS
66460+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
66461+#endif
66462+
66463+extern u16 acl_sp_role_value;
66464+extern struct acl_object_label *fakefs_obj_rw;
66465+extern struct acl_object_label *fakefs_obj_rwx;
66466+
66467+int gr_acl_is_enabled(void)
66468+{
66469+ return (gr_status & GR_READY);
66470+}
66471+
66472+void gr_enable_rbac_system(void)
66473+{
66474+ pax_open_kernel();
66475+ gr_status |= GR_READY;
66476+ pax_close_kernel();
66477+}
66478+
66479+int gr_rbac_disable(void *unused)
66480+{
66481+ pax_open_kernel();
66482+ gr_status &= ~GR_READY;
66483+ pax_close_kernel();
66484+
66485+ return 0;
66486+}
66487+
66488+static inline dev_t __get_dev(const struct dentry *dentry)
66489+{
66490+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66491+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
66492+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
66493+ else
66494+#endif
66495+ return dentry->d_sb->s_dev;
66496+}
66497+
66498+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
66499+{
66500+ return __get_dev(dentry);
66501+}
66502+
66503+static char gr_task_roletype_to_char(struct task_struct *task)
66504+{
66505+ switch (task->role->roletype &
66506+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
66507+ GR_ROLE_SPECIAL)) {
66508+ case GR_ROLE_DEFAULT:
66509+ return 'D';
66510+ case GR_ROLE_USER:
66511+ return 'U';
66512+ case GR_ROLE_GROUP:
66513+ return 'G';
66514+ case GR_ROLE_SPECIAL:
66515+ return 'S';
66516+ }
66517+
66518+ return 'X';
66519+}
66520+
66521+char gr_roletype_to_char(void)
66522+{
66523+ return gr_task_roletype_to_char(current);
66524+}
66525+
66526+__inline__ int
66527+gr_acl_tpe_check(void)
66528+{
66529+ if (unlikely(!(gr_status & GR_READY)))
66530+ return 0;
66531+ if (current->role->roletype & GR_ROLE_TPE)
66532+ return 1;
66533+ else
66534+ return 0;
66535+}
66536+
66537+int
66538+gr_handle_rawio(const struct inode *inode)
66539+{
66540+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
66541+ if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
66542+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
66543+ !capable(CAP_SYS_RAWIO))
66544+ return 1;
66545+#endif
66546+ return 0;
66547+}
66548+
66549+int
66550+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
66551+{
66552+ if (likely(lena != lenb))
66553+ return 0;
66554+
66555+ return !memcmp(a, b, lena);
66556+}
66557+
66558+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
66559+{
66560+ *buflen -= namelen;
66561+ if (*buflen < 0)
66562+ return -ENAMETOOLONG;
66563+ *buffer -= namelen;
66564+ memcpy(*buffer, str, namelen);
66565+ return 0;
66566+}
66567+
66568+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
66569+{
66570+ return prepend(buffer, buflen, name->name, name->len);
66571+}
66572+
66573+static int prepend_path(const struct path *path, struct path *root,
66574+ char **buffer, int *buflen)
66575+{
66576+ struct dentry *dentry = path->dentry;
66577+ struct vfsmount *vfsmnt = path->mnt;
66578+ struct mount *mnt = real_mount(vfsmnt);
66579+ bool slash = false;
66580+ int error = 0;
66581+
66582+ while (dentry != root->dentry || vfsmnt != root->mnt) {
66583+ struct dentry * parent;
66584+
66585+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
66586+ /* Global root? */
66587+ if (!mnt_has_parent(mnt)) {
66588+ goto out;
66589+ }
66590+ dentry = mnt->mnt_mountpoint;
66591+ mnt = mnt->mnt_parent;
66592+ vfsmnt = &mnt->mnt;
66593+ continue;
66594+ }
66595+ parent = dentry->d_parent;
66596+ prefetch(parent);
66597+ spin_lock(&dentry->d_lock);
66598+ error = prepend_name(buffer, buflen, &dentry->d_name);
66599+ spin_unlock(&dentry->d_lock);
66600+ if (!error)
66601+ error = prepend(buffer, buflen, "/", 1);
66602+ if (error)
66603+ break;
66604+
66605+ slash = true;
66606+ dentry = parent;
66607+ }
66608+
66609+out:
66610+ if (!error && !slash)
66611+ error = prepend(buffer, buflen, "/", 1);
66612+
66613+ return error;
66614+}
66615+
66616+/* this must be called with mount_lock and rename_lock held */
66617+
66618+static char *__our_d_path(const struct path *path, struct path *root,
66619+ char *buf, int buflen)
66620+{
66621+ char *res = buf + buflen;
66622+ int error;
66623+
66624+ prepend(&res, &buflen, "\0", 1);
66625+ error = prepend_path(path, root, &res, &buflen);
66626+ if (error)
66627+ return ERR_PTR(error);
66628+
66629+ return res;
66630+}
66631+
66632+static char *
66633+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
66634+{
66635+ char *retval;
66636+
66637+ retval = __our_d_path(path, root, buf, buflen);
66638+ if (unlikely(IS_ERR(retval)))
66639+ retval = strcpy(buf, "<path too long>");
66640+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
66641+ retval[1] = '\0';
66642+
66643+ return retval;
66644+}
66645+
66646+static char *
66647+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
66648+ char *buf, int buflen)
66649+{
66650+ struct path path;
66651+ char *res;
66652+
66653+ path.dentry = (struct dentry *)dentry;
66654+ path.mnt = (struct vfsmount *)vfsmnt;
66655+
66656+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
66657+ by the RBAC system */
66658+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
66659+
66660+ return res;
66661+}
66662+
66663+static char *
66664+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
66665+ char *buf, int buflen)
66666+{
66667+ char *res;
66668+ struct path path;
66669+ struct path root;
66670+ struct task_struct *reaper = init_pid_ns.child_reaper;
66671+
66672+ path.dentry = (struct dentry *)dentry;
66673+ path.mnt = (struct vfsmount *)vfsmnt;
66674+
66675+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
66676+ get_fs_root(reaper->fs, &root);
66677+
66678+ read_seqlock_excl(&mount_lock);
66679+ write_seqlock(&rename_lock);
66680+ res = gen_full_path(&path, &root, buf, buflen);
66681+ write_sequnlock(&rename_lock);
66682+ read_sequnlock_excl(&mount_lock);
66683+
66684+ path_put(&root);
66685+ return res;
66686+}
66687+
66688+char *
66689+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
66690+{
66691+ char *ret;
66692+ read_seqlock_excl(&mount_lock);
66693+ write_seqlock(&rename_lock);
66694+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
66695+ PAGE_SIZE);
66696+ write_sequnlock(&rename_lock);
66697+ read_sequnlock_excl(&mount_lock);
66698+ return ret;
66699+}
66700+
66701+static char *
66702+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
66703+{
66704+ char *ret;
66705+ char *buf;
66706+ int buflen;
66707+
66708+ read_seqlock_excl(&mount_lock);
66709+ write_seqlock(&rename_lock);
66710+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
66711+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
66712+ buflen = (int)(ret - buf);
66713+ if (buflen >= 5)
66714+ prepend(&ret, &buflen, "/proc", 5);
66715+ else
66716+ ret = strcpy(buf, "<path too long>");
66717+ write_sequnlock(&rename_lock);
66718+ read_sequnlock_excl(&mount_lock);
66719+ return ret;
66720+}
66721+
66722+char *
66723+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
66724+{
66725+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
66726+ PAGE_SIZE);
66727+}
66728+
66729+char *
66730+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
66731+{
66732+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
66733+ PAGE_SIZE);
66734+}
66735+
66736+char *
66737+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
66738+{
66739+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
66740+ PAGE_SIZE);
66741+}
66742+
66743+char *
66744+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
66745+{
66746+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
66747+ PAGE_SIZE);
66748+}
66749+
66750+char *
66751+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
66752+{
66753+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
66754+ PAGE_SIZE);
66755+}
66756+
66757+__inline__ __u32
66758+to_gr_audit(const __u32 reqmode)
66759+{
66760+ /* masks off auditable permission flags, then shifts them to create
66761+ auditing flags, and adds the special case of append auditing if
66762+ we're requesting write */
66763+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
66764+}
66765+
66766+struct acl_role_label *
66767+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
66768+ const gid_t gid)
66769+{
66770+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
66771+ struct acl_role_label *match;
66772+ struct role_allowed_ip *ipp;
66773+ unsigned int x;
66774+ u32 curr_ip = task->signal->saved_ip;
66775+
66776+ match = state->acl_role_set.r_hash[index];
66777+
66778+ while (match) {
66779+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
66780+ for (x = 0; x < match->domain_child_num; x++) {
66781+ if (match->domain_children[x] == uid)
66782+ goto found;
66783+ }
66784+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
66785+ break;
66786+ match = match->next;
66787+ }
66788+found:
66789+ if (match == NULL) {
66790+ try_group:
66791+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
66792+ match = state->acl_role_set.r_hash[index];
66793+
66794+ while (match) {
66795+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
66796+ for (x = 0; x < match->domain_child_num; x++) {
66797+ if (match->domain_children[x] == gid)
66798+ goto found2;
66799+ }
66800+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
66801+ break;
66802+ match = match->next;
66803+ }
66804+found2:
66805+ if (match == NULL)
66806+ match = state->default_role;
66807+ if (match->allowed_ips == NULL)
66808+ return match;
66809+ else {
66810+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
66811+ if (likely
66812+ ((ntohl(curr_ip) & ipp->netmask) ==
66813+ (ntohl(ipp->addr) & ipp->netmask)))
66814+ return match;
66815+ }
66816+ match = state->default_role;
66817+ }
66818+ } else if (match->allowed_ips == NULL) {
66819+ return match;
66820+ } else {
66821+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
66822+ if (likely
66823+ ((ntohl(curr_ip) & ipp->netmask) ==
66824+ (ntohl(ipp->addr) & ipp->netmask)))
66825+ return match;
66826+ }
66827+ goto try_group;
66828+ }
66829+
66830+ return match;
66831+}
66832+
66833+static struct acl_role_label *
66834+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
66835+ const gid_t gid)
66836+{
66837+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
66838+}
66839+
66840+struct acl_subject_label *
66841+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
66842+ const struct acl_role_label *role)
66843+{
66844+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
66845+ struct acl_subject_label *match;
66846+
66847+ match = role->subj_hash[index];
66848+
66849+ while (match && (match->inode != ino || match->device != dev ||
66850+ (match->mode & GR_DELETED))) {
66851+ match = match->next;
66852+ }
66853+
66854+ if (match && !(match->mode & GR_DELETED))
66855+ return match;
66856+ else
66857+ return NULL;
66858+}
66859+
66860+struct acl_subject_label *
66861+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
66862+ const struct acl_role_label *role)
66863+{
66864+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
66865+ struct acl_subject_label *match;
66866+
66867+ match = role->subj_hash[index];
66868+
66869+ while (match && (match->inode != ino || match->device != dev ||
66870+ !(match->mode & GR_DELETED))) {
66871+ match = match->next;
66872+ }
66873+
66874+ if (match && (match->mode & GR_DELETED))
66875+ return match;
66876+ else
66877+ return NULL;
66878+}
66879+
66880+static struct acl_object_label *
66881+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
66882+ const struct acl_subject_label *subj)
66883+{
66884+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
66885+ struct acl_object_label *match;
66886+
66887+ match = subj->obj_hash[index];
66888+
66889+ while (match && (match->inode != ino || match->device != dev ||
66890+ (match->mode & GR_DELETED))) {
66891+ match = match->next;
66892+ }
66893+
66894+ if (match && !(match->mode & GR_DELETED))
66895+ return match;
66896+ else
66897+ return NULL;
66898+}
66899+
66900+static struct acl_object_label *
66901+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
66902+ const struct acl_subject_label *subj)
66903+{
66904+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
66905+ struct acl_object_label *match;
66906+
66907+ match = subj->obj_hash[index];
66908+
66909+ while (match && (match->inode != ino || match->device != dev ||
66910+ !(match->mode & GR_DELETED))) {
66911+ match = match->next;
66912+ }
66913+
66914+ if (match && (match->mode & GR_DELETED))
66915+ return match;
66916+
66917+ match = subj->obj_hash[index];
66918+
66919+ while (match && (match->inode != ino || match->device != dev ||
66920+ (match->mode & GR_DELETED))) {
66921+ match = match->next;
66922+ }
66923+
66924+ if (match && !(match->mode & GR_DELETED))
66925+ return match;
66926+ else
66927+ return NULL;
66928+}
66929+
66930+struct name_entry *
66931+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
66932+{
66933+ unsigned int len = strlen(name);
66934+ unsigned int key = full_name_hash(name, len);
66935+ unsigned int index = key % state->name_set.n_size;
66936+ struct name_entry *match;
66937+
66938+ match = state->name_set.n_hash[index];
66939+
66940+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
66941+ match = match->next;
66942+
66943+ return match;
66944+}
66945+
66946+static struct name_entry *
66947+lookup_name_entry(const char *name)
66948+{
66949+ return __lookup_name_entry(&running_polstate, name);
66950+}
66951+
66952+static struct name_entry *
66953+lookup_name_entry_create(const char *name)
66954+{
66955+ unsigned int len = strlen(name);
66956+ unsigned int key = full_name_hash(name, len);
66957+ unsigned int index = key % running_polstate.name_set.n_size;
66958+ struct name_entry *match;
66959+
66960+ match = running_polstate.name_set.n_hash[index];
66961+
66962+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
66963+ !match->deleted))
66964+ match = match->next;
66965+
66966+ if (match && match->deleted)
66967+ return match;
66968+
66969+ match = running_polstate.name_set.n_hash[index];
66970+
66971+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
66972+ match->deleted))
66973+ match = match->next;
66974+
66975+ if (match && !match->deleted)
66976+ return match;
66977+ else
66978+ return NULL;
66979+}
66980+
66981+static struct inodev_entry *
66982+lookup_inodev_entry(const ino_t ino, const dev_t dev)
66983+{
66984+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
66985+ struct inodev_entry *match;
66986+
66987+ match = running_polstate.inodev_set.i_hash[index];
66988+
66989+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
66990+ match = match->next;
66991+
66992+ return match;
66993+}
66994+
66995+void
66996+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
66997+{
66998+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
66999+ state->inodev_set.i_size);
67000+ struct inodev_entry **curr;
67001+
67002+ entry->prev = NULL;
67003+
67004+ curr = &state->inodev_set.i_hash[index];
67005+ if (*curr != NULL)
67006+ (*curr)->prev = entry;
67007+
67008+ entry->next = *curr;
67009+ *curr = entry;
67010+
67011+ return;
67012+}
67013+
67014+static void
67015+insert_inodev_entry(struct inodev_entry *entry)
67016+{
67017+ __insert_inodev_entry(&running_polstate, entry);
67018+}
67019+
67020+void
67021+insert_acl_obj_label(struct acl_object_label *obj,
67022+ struct acl_subject_label *subj)
67023+{
67024+ unsigned int index =
67025+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
67026+ struct acl_object_label **curr;
67027+
67028+ obj->prev = NULL;
67029+
67030+ curr = &subj->obj_hash[index];
67031+ if (*curr != NULL)
67032+ (*curr)->prev = obj;
67033+
67034+ obj->next = *curr;
67035+ *curr = obj;
67036+
67037+ return;
67038+}
67039+
67040+void
67041+insert_acl_subj_label(struct acl_subject_label *obj,
67042+ struct acl_role_label *role)
67043+{
67044+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
67045+ struct acl_subject_label **curr;
67046+
67047+ obj->prev = NULL;
67048+
67049+ curr = &role->subj_hash[index];
67050+ if (*curr != NULL)
67051+ (*curr)->prev = obj;
67052+
67053+ obj->next = *curr;
67054+ *curr = obj;
67055+
67056+ return;
67057+}
67058+
67059+/* derived from glibc fnmatch() 0: match, 1: no match*/
67060+
67061+static int
67062+glob_match(const char *p, const char *n)
67063+{
67064+ char c;
67065+
67066+ while ((c = *p++) != '\0') {
67067+ switch (c) {
67068+ case '?':
67069+ if (*n == '\0')
67070+ return 1;
67071+ else if (*n == '/')
67072+ return 1;
67073+ break;
67074+ case '\\':
67075+ if (*n != c)
67076+ return 1;
67077+ break;
67078+ case '*':
67079+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
67080+ if (*n == '/')
67081+ return 1;
67082+ else if (c == '?') {
67083+ if (*n == '\0')
67084+ return 1;
67085+ else
67086+ ++n;
67087+ }
67088+ }
67089+ if (c == '\0') {
67090+ return 0;
67091+ } else {
67092+ const char *endp;
67093+
67094+ if ((endp = strchr(n, '/')) == NULL)
67095+ endp = n + strlen(n);
67096+
67097+ if (c == '[') {
67098+ for (--p; n < endp; ++n)
67099+ if (!glob_match(p, n))
67100+ return 0;
67101+ } else if (c == '/') {
67102+ while (*n != '\0' && *n != '/')
67103+ ++n;
67104+ if (*n == '/' && !glob_match(p, n + 1))
67105+ return 0;
67106+ } else {
67107+ for (--p; n < endp; ++n)
67108+ if (*n == c && !glob_match(p, n))
67109+ return 0;
67110+ }
67111+
67112+ return 1;
67113+ }
67114+ case '[':
67115+ {
67116+ int not;
67117+ char cold;
67118+
67119+ if (*n == '\0' || *n == '/')
67120+ return 1;
67121+
67122+ not = (*p == '!' || *p == '^');
67123+ if (not)
67124+ ++p;
67125+
67126+ c = *p++;
67127+ for (;;) {
67128+ unsigned char fn = (unsigned char)*n;
67129+
67130+ if (c == '\0')
67131+ return 1;
67132+ else {
67133+ if (c == fn)
67134+ goto matched;
67135+ cold = c;
67136+ c = *p++;
67137+
67138+ if (c == '-' && *p != ']') {
67139+ unsigned char cend = *p++;
67140+
67141+ if (cend == '\0')
67142+ return 1;
67143+
67144+ if (cold <= fn && fn <= cend)
67145+ goto matched;
67146+
67147+ c = *p++;
67148+ }
67149+ }
67150+
67151+ if (c == ']')
67152+ break;
67153+ }
67154+ if (!not)
67155+ return 1;
67156+ break;
67157+ matched:
67158+ while (c != ']') {
67159+ if (c == '\0')
67160+ return 1;
67161+
67162+ c = *p++;
67163+ }
67164+ if (not)
67165+ return 1;
67166+ }
67167+ break;
67168+ default:
67169+ if (c != *n)
67170+ return 1;
67171+ }
67172+
67173+ ++n;
67174+ }
67175+
67176+ if (*n == '\0')
67177+ return 0;
67178+
67179+ if (*n == '/')
67180+ return 0;
67181+
67182+ return 1;
67183+}
67184+
67185+static struct acl_object_label *
67186+chk_glob_label(struct acl_object_label *globbed,
67187+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
67188+{
67189+ struct acl_object_label *tmp;
67190+
67191+ if (*path == NULL)
67192+ *path = gr_to_filename_nolock(dentry, mnt);
67193+
67194+ tmp = globbed;
67195+
67196+ while (tmp) {
67197+ if (!glob_match(tmp->filename, *path))
67198+ return tmp;
67199+ tmp = tmp->next;
67200+ }
67201+
67202+ return NULL;
67203+}
67204+
67205+static struct acl_object_label *
67206+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67207+ const ino_t curr_ino, const dev_t curr_dev,
67208+ const struct acl_subject_label *subj, char **path, const int checkglob)
67209+{
67210+ struct acl_subject_label *tmpsubj;
67211+ struct acl_object_label *retval;
67212+ struct acl_object_label *retval2;
67213+
67214+ tmpsubj = (struct acl_subject_label *) subj;
67215+ read_lock(&gr_inode_lock);
67216+ do {
67217+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
67218+ if (retval) {
67219+ if (checkglob && retval->globbed) {
67220+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
67221+ if (retval2)
67222+ retval = retval2;
67223+ }
67224+ break;
67225+ }
67226+ } while ((tmpsubj = tmpsubj->parent_subject));
67227+ read_unlock(&gr_inode_lock);
67228+
67229+ return retval;
67230+}
67231+
67232+static __inline__ struct acl_object_label *
67233+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67234+ struct dentry *curr_dentry,
67235+ const struct acl_subject_label *subj, char **path, const int checkglob)
67236+{
67237+ int newglob = checkglob;
67238+ ino_t inode;
67239+ dev_t device;
67240+
67241+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
67242+ as we don't want a / * rule to match instead of the / object
67243+ don't do this for create lookups that call this function though, since they're looking up
67244+ on the parent and thus need globbing checks on all paths
67245+ */
67246+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
67247+ newglob = GR_NO_GLOB;
67248+
67249+ spin_lock(&curr_dentry->d_lock);
67250+ inode = curr_dentry->d_inode->i_ino;
67251+ device = __get_dev(curr_dentry);
67252+ spin_unlock(&curr_dentry->d_lock);
67253+
67254+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
67255+}
67256+
67257+#ifdef CONFIG_HUGETLBFS
67258+static inline bool
67259+is_hugetlbfs_mnt(const struct vfsmount *mnt)
67260+{
67261+ int i;
67262+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
67263+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
67264+ return true;
67265+ }
67266+
67267+ return false;
67268+}
67269+#endif
67270+
67271+static struct acl_object_label *
67272+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67273+ const struct acl_subject_label *subj, char *path, const int checkglob)
67274+{
67275+ struct dentry *dentry = (struct dentry *) l_dentry;
67276+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67277+ struct mount *real_mnt = real_mount(mnt);
67278+ struct acl_object_label *retval;
67279+ struct dentry *parent;
67280+
67281+ read_seqlock_excl(&mount_lock);
67282+ write_seqlock(&rename_lock);
67283+
67284+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
67285+#ifdef CONFIG_NET
67286+ mnt == sock_mnt ||
67287+#endif
67288+#ifdef CONFIG_HUGETLBFS
67289+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
67290+#endif
67291+ /* ignore Eric Biederman */
67292+ IS_PRIVATE(l_dentry->d_inode))) {
67293+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
67294+ goto out;
67295+ }
67296+
67297+ for (;;) {
67298+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67299+ break;
67300+
67301+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67302+ if (!mnt_has_parent(real_mnt))
67303+ break;
67304+
67305+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67306+ if (retval != NULL)
67307+ goto out;
67308+
67309+ dentry = real_mnt->mnt_mountpoint;
67310+ real_mnt = real_mnt->mnt_parent;
67311+ mnt = &real_mnt->mnt;
67312+ continue;
67313+ }
67314+
67315+ parent = dentry->d_parent;
67316+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67317+ if (retval != NULL)
67318+ goto out;
67319+
67320+ dentry = parent;
67321+ }
67322+
67323+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67324+
67325+ /* gr_real_root is pinned so we don't have to hold a reference */
67326+ if (retval == NULL)
67327+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
67328+out:
67329+ write_sequnlock(&rename_lock);
67330+ read_sequnlock_excl(&mount_lock);
67331+
67332+ BUG_ON(retval == NULL);
67333+
67334+ return retval;
67335+}
67336+
67337+static __inline__ struct acl_object_label *
67338+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67339+ const struct acl_subject_label *subj)
67340+{
67341+ char *path = NULL;
67342+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
67343+}
67344+
67345+static __inline__ struct acl_object_label *
67346+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67347+ const struct acl_subject_label *subj)
67348+{
67349+ char *path = NULL;
67350+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
67351+}
67352+
67353+static __inline__ struct acl_object_label *
67354+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67355+ const struct acl_subject_label *subj, char *path)
67356+{
67357+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
67358+}
67359+
67360+struct acl_subject_label *
67361+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67362+ const struct acl_role_label *role)
67363+{
67364+ struct dentry *dentry = (struct dentry *) l_dentry;
67365+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67366+ struct mount *real_mnt = real_mount(mnt);
67367+ struct acl_subject_label *retval;
67368+ struct dentry *parent;
67369+
67370+ read_seqlock_excl(&mount_lock);
67371+ write_seqlock(&rename_lock);
67372+
67373+ for (;;) {
67374+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67375+ break;
67376+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67377+ if (!mnt_has_parent(real_mnt))
67378+ break;
67379+
67380+ spin_lock(&dentry->d_lock);
67381+ read_lock(&gr_inode_lock);
67382+ retval =
67383+ lookup_acl_subj_label(dentry->d_inode->i_ino,
67384+ __get_dev(dentry), role);
67385+ read_unlock(&gr_inode_lock);
67386+ spin_unlock(&dentry->d_lock);
67387+ if (retval != NULL)
67388+ goto out;
67389+
67390+ dentry = real_mnt->mnt_mountpoint;
67391+ real_mnt = real_mnt->mnt_parent;
67392+ mnt = &real_mnt->mnt;
67393+ continue;
67394+ }
67395+
67396+ spin_lock(&dentry->d_lock);
67397+ read_lock(&gr_inode_lock);
67398+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67399+ __get_dev(dentry), role);
67400+ read_unlock(&gr_inode_lock);
67401+ parent = dentry->d_parent;
67402+ spin_unlock(&dentry->d_lock);
67403+
67404+ if (retval != NULL)
67405+ goto out;
67406+
67407+ dentry = parent;
67408+ }
67409+
67410+ spin_lock(&dentry->d_lock);
67411+ read_lock(&gr_inode_lock);
67412+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67413+ __get_dev(dentry), role);
67414+ read_unlock(&gr_inode_lock);
67415+ spin_unlock(&dentry->d_lock);
67416+
67417+ if (unlikely(retval == NULL)) {
67418+ /* gr_real_root is pinned, we don't need to hold a reference */
67419+ read_lock(&gr_inode_lock);
67420+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
67421+ __get_dev(gr_real_root.dentry), role);
67422+ read_unlock(&gr_inode_lock);
67423+ }
67424+out:
67425+ write_sequnlock(&rename_lock);
67426+ read_sequnlock_excl(&mount_lock);
67427+
67428+ BUG_ON(retval == NULL);
67429+
67430+ return retval;
67431+}
67432+
67433+void
67434+assign_special_role(const char *rolename)
67435+{
67436+ struct acl_object_label *obj;
67437+ struct acl_role_label *r;
67438+ struct acl_role_label *assigned = NULL;
67439+ struct task_struct *tsk;
67440+ struct file *filp;
67441+
67442+ FOR_EACH_ROLE_START(r)
67443+ if (!strcmp(rolename, r->rolename) &&
67444+ (r->roletype & GR_ROLE_SPECIAL)) {
67445+ assigned = r;
67446+ break;
67447+ }
67448+ FOR_EACH_ROLE_END(r)
67449+
67450+ if (!assigned)
67451+ return;
67452+
67453+ read_lock(&tasklist_lock);
67454+ read_lock(&grsec_exec_file_lock);
67455+
67456+ tsk = current->real_parent;
67457+ if (tsk == NULL)
67458+ goto out_unlock;
67459+
67460+ filp = tsk->exec_file;
67461+ if (filp == NULL)
67462+ goto out_unlock;
67463+
67464+ tsk->is_writable = 0;
67465+ tsk->inherited = 0;
67466+
67467+ tsk->acl_sp_role = 1;
67468+ tsk->acl_role_id = ++acl_sp_role_value;
67469+ tsk->role = assigned;
67470+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
67471+
67472+ /* ignore additional mmap checks for processes that are writable
67473+ by the default ACL */
67474+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67475+ if (unlikely(obj->mode & GR_WRITE))
67476+ tsk->is_writable = 1;
67477+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
67478+ if (unlikely(obj->mode & GR_WRITE))
67479+ tsk->is_writable = 1;
67480+
67481+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67482+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
67483+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
67484+#endif
67485+
67486+out_unlock:
67487+ read_unlock(&grsec_exec_file_lock);
67488+ read_unlock(&tasklist_lock);
67489+ return;
67490+}
67491+
67492+
67493+static void
67494+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
67495+{
67496+ struct task_struct *task = current;
67497+ const struct cred *cred = current_cred();
67498+
67499+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
67500+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67501+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67502+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
67503+
67504+ return;
67505+}
67506+
67507+static void
67508+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
67509+{
67510+ struct task_struct *task = current;
67511+ const struct cred *cred = current_cred();
67512+
67513+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67514+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67515+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67516+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
67517+
67518+ return;
67519+}
67520+
67521+static void
67522+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
67523+{
67524+ struct task_struct *task = current;
67525+ const struct cred *cred = current_cred();
67526+
67527+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67528+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67529+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67530+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
67531+
67532+ return;
67533+}
67534+
67535+static void
67536+gr_set_proc_res(struct task_struct *task)
67537+{
67538+ struct acl_subject_label *proc;
67539+ unsigned short i;
67540+
67541+ proc = task->acl;
67542+
67543+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
67544+ return;
67545+
67546+ for (i = 0; i < RLIM_NLIMITS; i++) {
67547+ if (!(proc->resmask & (1U << i)))
67548+ continue;
67549+
67550+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
67551+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
67552+
67553+ if (i == RLIMIT_CPU)
67554+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
67555+ }
67556+
67557+ return;
67558+}
67559+
67560+/* both of the below must be called with
67561+ rcu_read_lock();
67562+ read_lock(&tasklist_lock);
67563+ read_lock(&grsec_exec_file_lock);
67564+*/
67565+
67566+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
67567+{
67568+ char *tmpname;
67569+ struct acl_subject_label *tmpsubj;
67570+ struct file *filp;
67571+ struct name_entry *nmatch;
67572+
67573+ filp = task->exec_file;
67574+ if (filp == NULL)
67575+ return NULL;
67576+
67577+ /* the following is to apply the correct subject
67578+ on binaries running when the RBAC system
67579+ is enabled, when the binaries have been
67580+ replaced or deleted since their execution
67581+ -----
67582+ when the RBAC system starts, the inode/dev
67583+ from exec_file will be one the RBAC system
67584+ is unaware of. It only knows the inode/dev
67585+ of the present file on disk, or the absence
67586+ of it.
67587+ */
67588+
67589+ if (filename)
67590+ nmatch = __lookup_name_entry(state, filename);
67591+ else {
67592+ preempt_disable();
67593+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
67594+
67595+ nmatch = __lookup_name_entry(state, tmpname);
67596+ preempt_enable();
67597+ }
67598+ tmpsubj = NULL;
67599+ if (nmatch) {
67600+ if (nmatch->deleted)
67601+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
67602+ else
67603+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
67604+ }
67605+ /* this also works for the reload case -- if we don't match a potentially inherited subject
67606+ then we fall back to a normal lookup based on the binary's ino/dev
67607+ */
67608+ if (tmpsubj == NULL)
67609+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
67610+
67611+ return tmpsubj;
67612+}
67613+
67614+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
67615+{
67616+ return __gr_get_subject_for_task(&running_polstate, task, filename);
67617+}
67618+
67619+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
67620+{
67621+ struct acl_object_label *obj;
67622+ struct file *filp;
67623+
67624+ filp = task->exec_file;
67625+
67626+ task->acl = subj;
67627+ task->is_writable = 0;
67628+ /* ignore additional mmap checks for processes that are writable
67629+ by the default ACL */
67630+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
67631+ if (unlikely(obj->mode & GR_WRITE))
67632+ task->is_writable = 1;
67633+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
67634+ if (unlikely(obj->mode & GR_WRITE))
67635+ task->is_writable = 1;
67636+
67637+ gr_set_proc_res(task);
67638+
67639+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67640+ 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);
67641+#endif
67642+}
67643+
67644+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
67645+{
67646+ __gr_apply_subject_to_task(&running_polstate, task, subj);
67647+}
67648+
67649+__u32
67650+gr_search_file(const struct dentry * dentry, const __u32 mode,
67651+ const struct vfsmount * mnt)
67652+{
67653+ __u32 retval = mode;
67654+ struct acl_subject_label *curracl;
67655+ struct acl_object_label *currobj;
67656+
67657+ if (unlikely(!(gr_status & GR_READY)))
67658+ return (mode & ~GR_AUDITS);
67659+
67660+ curracl = current->acl;
67661+
67662+ currobj = chk_obj_label(dentry, mnt, curracl);
67663+ retval = currobj->mode & mode;
67664+
67665+ /* if we're opening a specified transfer file for writing
67666+ (e.g. /dev/initctl), then transfer our role to init
67667+ */
67668+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
67669+ current->role->roletype & GR_ROLE_PERSIST)) {
67670+ struct task_struct *task = init_pid_ns.child_reaper;
67671+
67672+ if (task->role != current->role) {
67673+ struct acl_subject_label *subj;
67674+
67675+ task->acl_sp_role = 0;
67676+ task->acl_role_id = current->acl_role_id;
67677+ task->role = current->role;
67678+ rcu_read_lock();
67679+ read_lock(&grsec_exec_file_lock);
67680+ subj = gr_get_subject_for_task(task, NULL);
67681+ gr_apply_subject_to_task(task, subj);
67682+ read_unlock(&grsec_exec_file_lock);
67683+ rcu_read_unlock();
67684+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
67685+ }
67686+ }
67687+
67688+ if (unlikely
67689+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
67690+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
67691+ __u32 new_mode = mode;
67692+
67693+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
67694+
67695+ retval = new_mode;
67696+
67697+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
67698+ new_mode |= GR_INHERIT;
67699+
67700+ if (!(mode & GR_NOLEARN))
67701+ gr_log_learn(dentry, mnt, new_mode);
67702+ }
67703+
67704+ return retval;
67705+}
67706+
67707+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
67708+ const struct dentry *parent,
67709+ const struct vfsmount *mnt)
67710+{
67711+ struct name_entry *match;
67712+ struct acl_object_label *matchpo;
67713+ struct acl_subject_label *curracl;
67714+ char *path;
67715+
67716+ if (unlikely(!(gr_status & GR_READY)))
67717+ return NULL;
67718+
67719+ preempt_disable();
67720+ path = gr_to_filename_rbac(new_dentry, mnt);
67721+ match = lookup_name_entry_create(path);
67722+
67723+ curracl = current->acl;
67724+
67725+ if (match) {
67726+ read_lock(&gr_inode_lock);
67727+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
67728+ read_unlock(&gr_inode_lock);
67729+
67730+ if (matchpo) {
67731+ preempt_enable();
67732+ return matchpo;
67733+ }
67734+ }
67735+
67736+ // lookup parent
67737+
67738+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
67739+
67740+ preempt_enable();
67741+ return matchpo;
67742+}
67743+
67744+__u32
67745+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
67746+ const struct vfsmount * mnt, const __u32 mode)
67747+{
67748+ struct acl_object_label *matchpo;
67749+ __u32 retval;
67750+
67751+ if (unlikely(!(gr_status & GR_READY)))
67752+ return (mode & ~GR_AUDITS);
67753+
67754+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
67755+
67756+ retval = matchpo->mode & mode;
67757+
67758+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
67759+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
67760+ __u32 new_mode = mode;
67761+
67762+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
67763+
67764+ gr_log_learn(new_dentry, mnt, new_mode);
67765+ return new_mode;
67766+ }
67767+
67768+ return retval;
67769+}
67770+
67771+__u32
67772+gr_check_link(const struct dentry * new_dentry,
67773+ const struct dentry * parent_dentry,
67774+ const struct vfsmount * parent_mnt,
67775+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
67776+{
67777+ struct acl_object_label *obj;
67778+ __u32 oldmode, newmode;
67779+ __u32 needmode;
67780+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
67781+ GR_DELETE | GR_INHERIT;
67782+
67783+ if (unlikely(!(gr_status & GR_READY)))
67784+ return (GR_CREATE | GR_LINK);
67785+
67786+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
67787+ oldmode = obj->mode;
67788+
67789+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
67790+ newmode = obj->mode;
67791+
67792+ needmode = newmode & checkmodes;
67793+
67794+ // old name for hardlink must have at least the permissions of the new name
67795+ if ((oldmode & needmode) != needmode)
67796+ goto bad;
67797+
67798+ // if old name had restrictions/auditing, make sure the new name does as well
67799+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
67800+
67801+ // don't allow hardlinking of suid/sgid/fcapped files without permission
67802+ if (is_privileged_binary(old_dentry))
67803+ needmode |= GR_SETID;
67804+
67805+ if ((newmode & needmode) != needmode)
67806+ goto bad;
67807+
67808+ // enforce minimum permissions
67809+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
67810+ return newmode;
67811+bad:
67812+ needmode = oldmode;
67813+ if (is_privileged_binary(old_dentry))
67814+ needmode |= GR_SETID;
67815+
67816+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
67817+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
67818+ return (GR_CREATE | GR_LINK);
67819+ } else if (newmode & GR_SUPPRESS)
67820+ return GR_SUPPRESS;
67821+ else
67822+ return 0;
67823+}
67824+
67825+int
67826+gr_check_hidden_task(const struct task_struct *task)
67827+{
67828+ if (unlikely(!(gr_status & GR_READY)))
67829+ return 0;
67830+
67831+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
67832+ return 1;
67833+
67834+ return 0;
67835+}
67836+
67837+int
67838+gr_check_protected_task(const struct task_struct *task)
67839+{
67840+ if (unlikely(!(gr_status & GR_READY) || !task))
67841+ return 0;
67842+
67843+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
67844+ task->acl != current->acl)
67845+ return 1;
67846+
67847+ return 0;
67848+}
67849+
67850+int
67851+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
67852+{
67853+ struct task_struct *p;
67854+ int ret = 0;
67855+
67856+ if (unlikely(!(gr_status & GR_READY) || !pid))
67857+ return ret;
67858+
67859+ read_lock(&tasklist_lock);
67860+ do_each_pid_task(pid, type, p) {
67861+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
67862+ p->acl != current->acl) {
67863+ ret = 1;
67864+ goto out;
67865+ }
67866+ } while_each_pid_task(pid, type, p);
67867+out:
67868+ read_unlock(&tasklist_lock);
67869+
67870+ return ret;
67871+}
67872+
67873+void
67874+gr_copy_label(struct task_struct *tsk)
67875+{
67876+ struct task_struct *p = current;
67877+
67878+ tsk->inherited = p->inherited;
67879+ tsk->acl_sp_role = 0;
67880+ tsk->acl_role_id = p->acl_role_id;
67881+ tsk->acl = p->acl;
67882+ tsk->role = p->role;
67883+ tsk->signal->used_accept = 0;
67884+ tsk->signal->curr_ip = p->signal->curr_ip;
67885+ tsk->signal->saved_ip = p->signal->saved_ip;
67886+ if (p->exec_file)
67887+ get_file(p->exec_file);
67888+ tsk->exec_file = p->exec_file;
67889+ tsk->is_writable = p->is_writable;
67890+ if (unlikely(p->signal->used_accept)) {
67891+ p->signal->curr_ip = 0;
67892+ p->signal->saved_ip = 0;
67893+ }
67894+
67895+ return;
67896+}
67897+
67898+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
67899+
67900+int
67901+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
67902+{
67903+ unsigned int i;
67904+ __u16 num;
67905+ uid_t *uidlist;
67906+ uid_t curuid;
67907+ int realok = 0;
67908+ int effectiveok = 0;
67909+ int fsok = 0;
67910+ uid_t globalreal, globaleffective, globalfs;
67911+
67912+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
67913+ struct user_struct *user;
67914+
67915+ if (!uid_valid(real))
67916+ goto skipit;
67917+
67918+ /* find user based on global namespace */
67919+
67920+ globalreal = GR_GLOBAL_UID(real);
67921+
67922+ user = find_user(make_kuid(&init_user_ns, globalreal));
67923+ if (user == NULL)
67924+ goto skipit;
67925+
67926+ if (gr_process_kernel_setuid_ban(user)) {
67927+ /* for find_user */
67928+ free_uid(user);
67929+ return 1;
67930+ }
67931+
67932+ /* for find_user */
67933+ free_uid(user);
67934+
67935+skipit:
67936+#endif
67937+
67938+ if (unlikely(!(gr_status & GR_READY)))
67939+ return 0;
67940+
67941+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
67942+ gr_log_learn_uid_change(real, effective, fs);
67943+
67944+ num = current->acl->user_trans_num;
67945+ uidlist = current->acl->user_transitions;
67946+
67947+ if (uidlist == NULL)
67948+ return 0;
67949+
67950+ if (!uid_valid(real)) {
67951+ realok = 1;
67952+ globalreal = (uid_t)-1;
67953+ } else {
67954+ globalreal = GR_GLOBAL_UID(real);
67955+ }
67956+ if (!uid_valid(effective)) {
67957+ effectiveok = 1;
67958+ globaleffective = (uid_t)-1;
67959+ } else {
67960+ globaleffective = GR_GLOBAL_UID(effective);
67961+ }
67962+ if (!uid_valid(fs)) {
67963+ fsok = 1;
67964+ globalfs = (uid_t)-1;
67965+ } else {
67966+ globalfs = GR_GLOBAL_UID(fs);
67967+ }
67968+
67969+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
67970+ for (i = 0; i < num; i++) {
67971+ curuid = uidlist[i];
67972+ if (globalreal == curuid)
67973+ realok = 1;
67974+ if (globaleffective == curuid)
67975+ effectiveok = 1;
67976+ if (globalfs == curuid)
67977+ fsok = 1;
67978+ }
67979+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
67980+ for (i = 0; i < num; i++) {
67981+ curuid = uidlist[i];
67982+ if (globalreal == curuid)
67983+ break;
67984+ if (globaleffective == curuid)
67985+ break;
67986+ if (globalfs == curuid)
67987+ break;
67988+ }
67989+ /* not in deny list */
67990+ if (i == num) {
67991+ realok = 1;
67992+ effectiveok = 1;
67993+ fsok = 1;
67994+ }
67995+ }
67996+
67997+ if (realok && effectiveok && fsok)
67998+ return 0;
67999+ else {
68000+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68001+ return 1;
68002+ }
68003+}
68004+
68005+int
68006+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
68007+{
68008+ unsigned int i;
68009+ __u16 num;
68010+ gid_t *gidlist;
68011+ gid_t curgid;
68012+ int realok = 0;
68013+ int effectiveok = 0;
68014+ int fsok = 0;
68015+ gid_t globalreal, globaleffective, globalfs;
68016+
68017+ if (unlikely(!(gr_status & GR_READY)))
68018+ return 0;
68019+
68020+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68021+ gr_log_learn_gid_change(real, effective, fs);
68022+
68023+ num = current->acl->group_trans_num;
68024+ gidlist = current->acl->group_transitions;
68025+
68026+ if (gidlist == NULL)
68027+ return 0;
68028+
68029+ if (!gid_valid(real)) {
68030+ realok = 1;
68031+ globalreal = (gid_t)-1;
68032+ } else {
68033+ globalreal = GR_GLOBAL_GID(real);
68034+ }
68035+ if (!gid_valid(effective)) {
68036+ effectiveok = 1;
68037+ globaleffective = (gid_t)-1;
68038+ } else {
68039+ globaleffective = GR_GLOBAL_GID(effective);
68040+ }
68041+ if (!gid_valid(fs)) {
68042+ fsok = 1;
68043+ globalfs = (gid_t)-1;
68044+ } else {
68045+ globalfs = GR_GLOBAL_GID(fs);
68046+ }
68047+
68048+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
68049+ for (i = 0; i < num; i++) {
68050+ curgid = gidlist[i];
68051+ if (globalreal == curgid)
68052+ realok = 1;
68053+ if (globaleffective == curgid)
68054+ effectiveok = 1;
68055+ if (globalfs == curgid)
68056+ fsok = 1;
68057+ }
68058+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
68059+ for (i = 0; i < num; i++) {
68060+ curgid = gidlist[i];
68061+ if (globalreal == curgid)
68062+ break;
68063+ if (globaleffective == curgid)
68064+ break;
68065+ if (globalfs == curgid)
68066+ break;
68067+ }
68068+ /* not in deny list */
68069+ if (i == num) {
68070+ realok = 1;
68071+ effectiveok = 1;
68072+ fsok = 1;
68073+ }
68074+ }
68075+
68076+ if (realok && effectiveok && fsok)
68077+ return 0;
68078+ else {
68079+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68080+ return 1;
68081+ }
68082+}
68083+
68084+extern int gr_acl_is_capable(const int cap);
68085+
68086+void
68087+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
68088+{
68089+ struct acl_role_label *role = task->role;
68090+ struct acl_subject_label *subj = NULL;
68091+ struct acl_object_label *obj;
68092+ struct file *filp;
68093+ uid_t uid;
68094+ gid_t gid;
68095+
68096+ if (unlikely(!(gr_status & GR_READY)))
68097+ return;
68098+
68099+ uid = GR_GLOBAL_UID(kuid);
68100+ gid = GR_GLOBAL_GID(kgid);
68101+
68102+ filp = task->exec_file;
68103+
68104+ /* kernel process, we'll give them the kernel role */
68105+ if (unlikely(!filp)) {
68106+ task->role = running_polstate.kernel_role;
68107+ task->acl = running_polstate.kernel_role->root_label;
68108+ return;
68109+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
68110+ /* save the current ip at time of role lookup so that the proper
68111+ IP will be learned for role_allowed_ip */
68112+ task->signal->saved_ip = task->signal->curr_ip;
68113+ role = lookup_acl_role_label(task, uid, gid);
68114+ }
68115+
68116+ /* don't change the role if we're not a privileged process */
68117+ if (role && task->role != role &&
68118+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
68119+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
68120+ return;
68121+
68122+ /* perform subject lookup in possibly new role
68123+ we can use this result below in the case where role == task->role
68124+ */
68125+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
68126+
68127+ /* if we changed uid/gid, but result in the same role
68128+ and are using inheritance, don't lose the inherited subject
68129+ if current subject is other than what normal lookup
68130+ would result in, we arrived via inheritance, don't
68131+ lose subject
68132+ */
68133+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
68134+ (subj == task->acl)))
68135+ task->acl = subj;
68136+
68137+ /* leave task->inherited unaffected */
68138+
68139+ task->role = role;
68140+
68141+ task->is_writable = 0;
68142+
68143+ /* ignore additional mmap checks for processes that are writable
68144+ by the default ACL */
68145+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68146+ if (unlikely(obj->mode & GR_WRITE))
68147+ task->is_writable = 1;
68148+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68149+ if (unlikely(obj->mode & GR_WRITE))
68150+ task->is_writable = 1;
68151+
68152+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68153+ 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);
68154+#endif
68155+
68156+ gr_set_proc_res(task);
68157+
68158+ return;
68159+}
68160+
68161+int
68162+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68163+ const int unsafe_flags)
68164+{
68165+ struct task_struct *task = current;
68166+ struct acl_subject_label *newacl;
68167+ struct acl_object_label *obj;
68168+ __u32 retmode;
68169+
68170+ if (unlikely(!(gr_status & GR_READY)))
68171+ return 0;
68172+
68173+ newacl = chk_subj_label(dentry, mnt, task->role);
68174+
68175+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
68176+ did an exec
68177+ */
68178+ rcu_read_lock();
68179+ read_lock(&tasklist_lock);
68180+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
68181+ (task->parent->acl->mode & GR_POVERRIDE))) {
68182+ read_unlock(&tasklist_lock);
68183+ rcu_read_unlock();
68184+ goto skip_check;
68185+ }
68186+ read_unlock(&tasklist_lock);
68187+ rcu_read_unlock();
68188+
68189+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
68190+ !(task->role->roletype & GR_ROLE_GOD) &&
68191+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
68192+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68193+ if (unsafe_flags & LSM_UNSAFE_SHARE)
68194+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
68195+ else
68196+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
68197+ return -EACCES;
68198+ }
68199+
68200+skip_check:
68201+
68202+ obj = chk_obj_label(dentry, mnt, task->acl);
68203+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
68204+
68205+ if (!(task->acl->mode & GR_INHERITLEARN) &&
68206+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
68207+ if (obj->nested)
68208+ task->acl = obj->nested;
68209+ else
68210+ task->acl = newacl;
68211+ task->inherited = 0;
68212+ } else {
68213+ task->inherited = 1;
68214+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
68215+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
68216+ }
68217+
68218+ task->is_writable = 0;
68219+
68220+ /* ignore additional mmap checks for processes that are writable
68221+ by the default ACL */
68222+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
68223+ if (unlikely(obj->mode & GR_WRITE))
68224+ task->is_writable = 1;
68225+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
68226+ if (unlikely(obj->mode & GR_WRITE))
68227+ task->is_writable = 1;
68228+
68229+ gr_set_proc_res(task);
68230+
68231+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68232+ 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);
68233+#endif
68234+ return 0;
68235+}
68236+
68237+/* always called with valid inodev ptr */
68238+static void
68239+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
68240+{
68241+ struct acl_object_label *matchpo;
68242+ struct acl_subject_label *matchps;
68243+ struct acl_subject_label *subj;
68244+ struct acl_role_label *role;
68245+ unsigned int x;
68246+
68247+ FOR_EACH_ROLE_START(role)
68248+ FOR_EACH_SUBJECT_START(role, subj, x)
68249+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68250+ matchpo->mode |= GR_DELETED;
68251+ FOR_EACH_SUBJECT_END(subj,x)
68252+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
68253+ /* nested subjects aren't in the role's subj_hash table */
68254+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68255+ matchpo->mode |= GR_DELETED;
68256+ FOR_EACH_NESTED_SUBJECT_END(subj)
68257+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
68258+ matchps->mode |= GR_DELETED;
68259+ FOR_EACH_ROLE_END(role)
68260+
68261+ inodev->nentry->deleted = 1;
68262+
68263+ return;
68264+}
68265+
68266+void
68267+gr_handle_delete(const ino_t ino, const dev_t dev)
68268+{
68269+ struct inodev_entry *inodev;
68270+
68271+ if (unlikely(!(gr_status & GR_READY)))
68272+ return;
68273+
68274+ write_lock(&gr_inode_lock);
68275+ inodev = lookup_inodev_entry(ino, dev);
68276+ if (inodev != NULL)
68277+ do_handle_delete(inodev, ino, dev);
68278+ write_unlock(&gr_inode_lock);
68279+
68280+ return;
68281+}
68282+
68283+static void
68284+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
68285+ const ino_t newinode, const dev_t newdevice,
68286+ struct acl_subject_label *subj)
68287+{
68288+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
68289+ struct acl_object_label *match;
68290+
68291+ match = subj->obj_hash[index];
68292+
68293+ while (match && (match->inode != oldinode ||
68294+ match->device != olddevice ||
68295+ !(match->mode & GR_DELETED)))
68296+ match = match->next;
68297+
68298+ if (match && (match->inode == oldinode)
68299+ && (match->device == olddevice)
68300+ && (match->mode & GR_DELETED)) {
68301+ if (match->prev == NULL) {
68302+ subj->obj_hash[index] = match->next;
68303+ if (match->next != NULL)
68304+ match->next->prev = NULL;
68305+ } else {
68306+ match->prev->next = match->next;
68307+ if (match->next != NULL)
68308+ match->next->prev = match->prev;
68309+ }
68310+ match->prev = NULL;
68311+ match->next = NULL;
68312+ match->inode = newinode;
68313+ match->device = newdevice;
68314+ match->mode &= ~GR_DELETED;
68315+
68316+ insert_acl_obj_label(match, subj);
68317+ }
68318+
68319+ return;
68320+}
68321+
68322+static void
68323+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
68324+ const ino_t newinode, const dev_t newdevice,
68325+ struct acl_role_label *role)
68326+{
68327+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
68328+ struct acl_subject_label *match;
68329+
68330+ match = role->subj_hash[index];
68331+
68332+ while (match && (match->inode != oldinode ||
68333+ match->device != olddevice ||
68334+ !(match->mode & GR_DELETED)))
68335+ match = match->next;
68336+
68337+ if (match && (match->inode == oldinode)
68338+ && (match->device == olddevice)
68339+ && (match->mode & GR_DELETED)) {
68340+ if (match->prev == NULL) {
68341+ role->subj_hash[index] = match->next;
68342+ if (match->next != NULL)
68343+ match->next->prev = NULL;
68344+ } else {
68345+ match->prev->next = match->next;
68346+ if (match->next != NULL)
68347+ match->next->prev = match->prev;
68348+ }
68349+ match->prev = NULL;
68350+ match->next = NULL;
68351+ match->inode = newinode;
68352+ match->device = newdevice;
68353+ match->mode &= ~GR_DELETED;
68354+
68355+ insert_acl_subj_label(match, role);
68356+ }
68357+
68358+ return;
68359+}
68360+
68361+static void
68362+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
68363+ const ino_t newinode, const dev_t newdevice)
68364+{
68365+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
68366+ struct inodev_entry *match;
68367+
68368+ match = running_polstate.inodev_set.i_hash[index];
68369+
68370+ while (match && (match->nentry->inode != oldinode ||
68371+ match->nentry->device != olddevice || !match->nentry->deleted))
68372+ match = match->next;
68373+
68374+ if (match && (match->nentry->inode == oldinode)
68375+ && (match->nentry->device == olddevice) &&
68376+ match->nentry->deleted) {
68377+ if (match->prev == NULL) {
68378+ running_polstate.inodev_set.i_hash[index] = match->next;
68379+ if (match->next != NULL)
68380+ match->next->prev = NULL;
68381+ } else {
68382+ match->prev->next = match->next;
68383+ if (match->next != NULL)
68384+ match->next->prev = match->prev;
68385+ }
68386+ match->prev = NULL;
68387+ match->next = NULL;
68388+ match->nentry->inode = newinode;
68389+ match->nentry->device = newdevice;
68390+ match->nentry->deleted = 0;
68391+
68392+ insert_inodev_entry(match);
68393+ }
68394+
68395+ return;
68396+}
68397+
68398+static void
68399+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
68400+{
68401+ struct acl_subject_label *subj;
68402+ struct acl_role_label *role;
68403+ unsigned int x;
68404+
68405+ FOR_EACH_ROLE_START(role)
68406+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
68407+
68408+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
68409+ if ((subj->inode == ino) && (subj->device == dev)) {
68410+ subj->inode = ino;
68411+ subj->device = dev;
68412+ }
68413+ /* nested subjects aren't in the role's subj_hash table */
68414+ update_acl_obj_label(matchn->inode, matchn->device,
68415+ ino, dev, subj);
68416+ FOR_EACH_NESTED_SUBJECT_END(subj)
68417+ FOR_EACH_SUBJECT_START(role, subj, x)
68418+ update_acl_obj_label(matchn->inode, matchn->device,
68419+ ino, dev, subj);
68420+ FOR_EACH_SUBJECT_END(subj,x)
68421+ FOR_EACH_ROLE_END(role)
68422+
68423+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
68424+
68425+ return;
68426+}
68427+
68428+static void
68429+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
68430+ const struct vfsmount *mnt)
68431+{
68432+ ino_t ino = dentry->d_inode->i_ino;
68433+ dev_t dev = __get_dev(dentry);
68434+
68435+ __do_handle_create(matchn, ino, dev);
68436+
68437+ return;
68438+}
68439+
68440+void
68441+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68442+{
68443+ struct name_entry *matchn;
68444+
68445+ if (unlikely(!(gr_status & GR_READY)))
68446+ return;
68447+
68448+ preempt_disable();
68449+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
68450+
68451+ if (unlikely((unsigned long)matchn)) {
68452+ write_lock(&gr_inode_lock);
68453+ do_handle_create(matchn, dentry, mnt);
68454+ write_unlock(&gr_inode_lock);
68455+ }
68456+ preempt_enable();
68457+
68458+ return;
68459+}
68460+
68461+void
68462+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68463+{
68464+ struct name_entry *matchn;
68465+
68466+ if (unlikely(!(gr_status & GR_READY)))
68467+ return;
68468+
68469+ preempt_disable();
68470+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
68471+
68472+ if (unlikely((unsigned long)matchn)) {
68473+ write_lock(&gr_inode_lock);
68474+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
68475+ write_unlock(&gr_inode_lock);
68476+ }
68477+ preempt_enable();
68478+
68479+ return;
68480+}
68481+
68482+void
68483+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68484+ struct dentry *old_dentry,
68485+ struct dentry *new_dentry,
68486+ struct vfsmount *mnt, const __u8 replace)
68487+{
68488+ struct name_entry *matchn;
68489+ struct inodev_entry *inodev;
68490+ struct inode *inode = new_dentry->d_inode;
68491+ ino_t old_ino = old_dentry->d_inode->i_ino;
68492+ dev_t old_dev = __get_dev(old_dentry);
68493+
68494+ /* vfs_rename swaps the name and parent link for old_dentry and
68495+ new_dentry
68496+ at this point, old_dentry has the new name, parent link, and inode
68497+ for the renamed file
68498+ if a file is being replaced by a rename, new_dentry has the inode
68499+ and name for the replaced file
68500+ */
68501+
68502+ if (unlikely(!(gr_status & GR_READY)))
68503+ return;
68504+
68505+ preempt_disable();
68506+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
68507+
68508+ /* we wouldn't have to check d_inode if it weren't for
68509+ NFS silly-renaming
68510+ */
68511+
68512+ write_lock(&gr_inode_lock);
68513+ if (unlikely(replace && inode)) {
68514+ ino_t new_ino = inode->i_ino;
68515+ dev_t new_dev = __get_dev(new_dentry);
68516+
68517+ inodev = lookup_inodev_entry(new_ino, new_dev);
68518+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
68519+ do_handle_delete(inodev, new_ino, new_dev);
68520+ }
68521+
68522+ inodev = lookup_inodev_entry(old_ino, old_dev);
68523+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
68524+ do_handle_delete(inodev, old_ino, old_dev);
68525+
68526+ if (unlikely((unsigned long)matchn))
68527+ do_handle_create(matchn, old_dentry, mnt);
68528+
68529+ write_unlock(&gr_inode_lock);
68530+ preempt_enable();
68531+
68532+ return;
68533+}
68534+
68535+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
68536+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
68537+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
68538+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
68539+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
68540+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
68541+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
68542+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
68543+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
68544+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
68545+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
68546+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
68547+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
68548+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
68549+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
68550+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
68551+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
68552+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
68553+};
68554+
68555+void
68556+gr_learn_resource(const struct task_struct *task,
68557+ const int res, const unsigned long wanted, const int gt)
68558+{
68559+ struct acl_subject_label *acl;
68560+ const struct cred *cred;
68561+
68562+ if (unlikely((gr_status & GR_READY) &&
68563+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
68564+ goto skip_reslog;
68565+
68566+ gr_log_resource(task, res, wanted, gt);
68567+skip_reslog:
68568+
68569+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
68570+ return;
68571+
68572+ acl = task->acl;
68573+
68574+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
68575+ !(acl->resmask & (1U << (unsigned short) res))))
68576+ return;
68577+
68578+ if (wanted >= acl->res[res].rlim_cur) {
68579+ unsigned long res_add;
68580+
68581+ res_add = wanted + res_learn_bumps[res];
68582+
68583+ acl->res[res].rlim_cur = res_add;
68584+
68585+ if (wanted > acl->res[res].rlim_max)
68586+ acl->res[res].rlim_max = res_add;
68587+
68588+ /* only log the subject filename, since resource logging is supported for
68589+ single-subject learning only */
68590+ rcu_read_lock();
68591+ cred = __task_cred(task);
68592+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
68593+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
68594+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
68595+ "", (unsigned long) res, &task->signal->saved_ip);
68596+ rcu_read_unlock();
68597+ }
68598+
68599+ return;
68600+}
68601+EXPORT_SYMBOL_GPL(gr_learn_resource);
68602+#endif
68603+
68604+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
68605+void
68606+pax_set_initial_flags(struct linux_binprm *bprm)
68607+{
68608+ struct task_struct *task = current;
68609+ struct acl_subject_label *proc;
68610+ unsigned long flags;
68611+
68612+ if (unlikely(!(gr_status & GR_READY)))
68613+ return;
68614+
68615+ flags = pax_get_flags(task);
68616+
68617+ proc = task->acl;
68618+
68619+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
68620+ flags &= ~MF_PAX_PAGEEXEC;
68621+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
68622+ flags &= ~MF_PAX_SEGMEXEC;
68623+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
68624+ flags &= ~MF_PAX_RANDMMAP;
68625+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
68626+ flags &= ~MF_PAX_EMUTRAMP;
68627+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
68628+ flags &= ~MF_PAX_MPROTECT;
68629+
68630+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
68631+ flags |= MF_PAX_PAGEEXEC;
68632+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
68633+ flags |= MF_PAX_SEGMEXEC;
68634+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
68635+ flags |= MF_PAX_RANDMMAP;
68636+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
68637+ flags |= MF_PAX_EMUTRAMP;
68638+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
68639+ flags |= MF_PAX_MPROTECT;
68640+
68641+ pax_set_flags(task, flags);
68642+
68643+ return;
68644+}
68645+#endif
68646+
68647+int
68648+gr_handle_proc_ptrace(struct task_struct *task)
68649+{
68650+ struct file *filp;
68651+ struct task_struct *tmp = task;
68652+ struct task_struct *curtemp = current;
68653+ __u32 retmode;
68654+
68655+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
68656+ if (unlikely(!(gr_status & GR_READY)))
68657+ return 0;
68658+#endif
68659+
68660+ read_lock(&tasklist_lock);
68661+ read_lock(&grsec_exec_file_lock);
68662+ filp = task->exec_file;
68663+
68664+ while (task_pid_nr(tmp) > 0) {
68665+ if (tmp == curtemp)
68666+ break;
68667+ tmp = tmp->real_parent;
68668+ }
68669+
68670+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
68671+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
68672+ read_unlock(&grsec_exec_file_lock);
68673+ read_unlock(&tasklist_lock);
68674+ return 1;
68675+ }
68676+
68677+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
68678+ if (!(gr_status & GR_READY)) {
68679+ read_unlock(&grsec_exec_file_lock);
68680+ read_unlock(&tasklist_lock);
68681+ return 0;
68682+ }
68683+#endif
68684+
68685+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
68686+ read_unlock(&grsec_exec_file_lock);
68687+ read_unlock(&tasklist_lock);
68688+
68689+ if (retmode & GR_NOPTRACE)
68690+ return 1;
68691+
68692+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
68693+ && (current->acl != task->acl || (current->acl != current->role->root_label
68694+ && task_pid_nr(current) != task_pid_nr(task))))
68695+ return 1;
68696+
68697+ return 0;
68698+}
68699+
68700+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
68701+{
68702+ if (unlikely(!(gr_status & GR_READY)))
68703+ return;
68704+
68705+ if (!(current->role->roletype & GR_ROLE_GOD))
68706+ return;
68707+
68708+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
68709+ p->role->rolename, gr_task_roletype_to_char(p),
68710+ p->acl->filename);
68711+}
68712+
68713+int
68714+gr_handle_ptrace(struct task_struct *task, const long request)
68715+{
68716+ struct task_struct *tmp = task;
68717+ struct task_struct *curtemp = current;
68718+ __u32 retmode;
68719+
68720+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
68721+ if (unlikely(!(gr_status & GR_READY)))
68722+ return 0;
68723+#endif
68724+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68725+ read_lock(&tasklist_lock);
68726+ while (task_pid_nr(tmp) > 0) {
68727+ if (tmp == curtemp)
68728+ break;
68729+ tmp = tmp->real_parent;
68730+ }
68731+
68732+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
68733+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
68734+ read_unlock(&tasklist_lock);
68735+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68736+ return 1;
68737+ }
68738+ read_unlock(&tasklist_lock);
68739+ }
68740+
68741+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
68742+ if (!(gr_status & GR_READY))
68743+ return 0;
68744+#endif
68745+
68746+ read_lock(&grsec_exec_file_lock);
68747+ if (unlikely(!task->exec_file)) {
68748+ read_unlock(&grsec_exec_file_lock);
68749+ return 0;
68750+ }
68751+
68752+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
68753+ read_unlock(&grsec_exec_file_lock);
68754+
68755+ if (retmode & GR_NOPTRACE) {
68756+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68757+ return 1;
68758+ }
68759+
68760+ if (retmode & GR_PTRACERD) {
68761+ switch (request) {
68762+ case PTRACE_SEIZE:
68763+ case PTRACE_POKETEXT:
68764+ case PTRACE_POKEDATA:
68765+ case PTRACE_POKEUSR:
68766+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
68767+ case PTRACE_SETREGS:
68768+ case PTRACE_SETFPREGS:
68769+#endif
68770+#ifdef CONFIG_X86
68771+ case PTRACE_SETFPXREGS:
68772+#endif
68773+#ifdef CONFIG_ALTIVEC
68774+ case PTRACE_SETVRREGS:
68775+#endif
68776+ return 1;
68777+ default:
68778+ return 0;
68779+ }
68780+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
68781+ !(current->role->roletype & GR_ROLE_GOD) &&
68782+ (current->acl != task->acl)) {
68783+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68784+ return 1;
68785+ }
68786+
68787+ return 0;
68788+}
68789+
68790+static int is_writable_mmap(const struct file *filp)
68791+{
68792+ struct task_struct *task = current;
68793+ struct acl_object_label *obj, *obj2;
68794+
68795+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
68796+ !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))) {
68797+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68798+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
68799+ task->role->root_label);
68800+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
68801+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
68802+ return 1;
68803+ }
68804+ }
68805+ return 0;
68806+}
68807+
68808+int
68809+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
68810+{
68811+ __u32 mode;
68812+
68813+ if (unlikely(!file || !(prot & PROT_EXEC)))
68814+ return 1;
68815+
68816+ if (is_writable_mmap(file))
68817+ return 0;
68818+
68819+ mode =
68820+ gr_search_file(file->f_path.dentry,
68821+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
68822+ file->f_path.mnt);
68823+
68824+ if (!gr_tpe_allow(file))
68825+ return 0;
68826+
68827+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
68828+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68829+ return 0;
68830+ } else if (unlikely(!(mode & GR_EXEC))) {
68831+ return 0;
68832+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
68833+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68834+ return 1;
68835+ }
68836+
68837+ return 1;
68838+}
68839+
68840+int
68841+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
68842+{
68843+ __u32 mode;
68844+
68845+ if (unlikely(!file || !(prot & PROT_EXEC)))
68846+ return 1;
68847+
68848+ if (is_writable_mmap(file))
68849+ return 0;
68850+
68851+ mode =
68852+ gr_search_file(file->f_path.dentry,
68853+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
68854+ file->f_path.mnt);
68855+
68856+ if (!gr_tpe_allow(file))
68857+ return 0;
68858+
68859+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
68860+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68861+ return 0;
68862+ } else if (unlikely(!(mode & GR_EXEC))) {
68863+ return 0;
68864+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
68865+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68866+ return 1;
68867+ }
68868+
68869+ return 1;
68870+}
68871+
68872+void
68873+gr_acl_handle_psacct(struct task_struct *task, const long code)
68874+{
68875+ unsigned long runtime, cputime;
68876+ cputime_t utime, stime;
68877+ unsigned int wday, cday;
68878+ __u8 whr, chr;
68879+ __u8 wmin, cmin;
68880+ __u8 wsec, csec;
68881+ struct timespec timeval;
68882+
68883+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
68884+ !(task->acl->mode & GR_PROCACCT)))
68885+ return;
68886+
68887+ do_posix_clock_monotonic_gettime(&timeval);
68888+ runtime = timeval.tv_sec - task->start_time.tv_sec;
68889+ wday = runtime / (60 * 60 * 24);
68890+ runtime -= wday * (60 * 60 * 24);
68891+ whr = runtime / (60 * 60);
68892+ runtime -= whr * (60 * 60);
68893+ wmin = runtime / 60;
68894+ runtime -= wmin * 60;
68895+ wsec = runtime;
68896+
68897+ task_cputime(task, &utime, &stime);
68898+ cputime = cputime_to_secs(utime + stime);
68899+ cday = cputime / (60 * 60 * 24);
68900+ cputime -= cday * (60 * 60 * 24);
68901+ chr = cputime / (60 * 60);
68902+ cputime -= chr * (60 * 60);
68903+ cmin = cputime / 60;
68904+ cputime -= cmin * 60;
68905+ csec = cputime;
68906+
68907+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
68908+
68909+ return;
68910+}
68911+
68912+#ifdef CONFIG_TASKSTATS
68913+int gr_is_taskstats_denied(int pid)
68914+{
68915+ struct task_struct *task;
68916+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68917+ const struct cred *cred;
68918+#endif
68919+ int ret = 0;
68920+
68921+ /* restrict taskstats viewing to un-chrooted root users
68922+ who have the 'view' subject flag if the RBAC system is enabled
68923+ */
68924+
68925+ rcu_read_lock();
68926+ read_lock(&tasklist_lock);
68927+ task = find_task_by_vpid(pid);
68928+ if (task) {
68929+#ifdef CONFIG_GRKERNSEC_CHROOT
68930+ if (proc_is_chrooted(task))
68931+ ret = -EACCES;
68932+#endif
68933+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68934+ cred = __task_cred(task);
68935+#ifdef CONFIG_GRKERNSEC_PROC_USER
68936+ if (gr_is_global_nonroot(cred->uid))
68937+ ret = -EACCES;
68938+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68939+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
68940+ ret = -EACCES;
68941+#endif
68942+#endif
68943+ if (gr_status & GR_READY) {
68944+ if (!(task->acl->mode & GR_VIEW))
68945+ ret = -EACCES;
68946+ }
68947+ } else
68948+ ret = -ENOENT;
68949+
68950+ read_unlock(&tasklist_lock);
68951+ rcu_read_unlock();
68952+
68953+ return ret;
68954+}
68955+#endif
68956+
68957+/* AUXV entries are filled via a descendant of search_binary_handler
68958+ after we've already applied the subject for the target
68959+*/
68960+int gr_acl_enable_at_secure(void)
68961+{
68962+ if (unlikely(!(gr_status & GR_READY)))
68963+ return 0;
68964+
68965+ if (current->acl->mode & GR_ATSECURE)
68966+ return 1;
68967+
68968+ return 0;
68969+}
68970+
68971+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
68972+{
68973+ struct task_struct *task = current;
68974+ struct dentry *dentry = file->f_path.dentry;
68975+ struct vfsmount *mnt = file->f_path.mnt;
68976+ struct acl_object_label *obj, *tmp;
68977+ struct acl_subject_label *subj;
68978+ unsigned int bufsize;
68979+ int is_not_root;
68980+ char *path;
68981+ dev_t dev = __get_dev(dentry);
68982+
68983+ if (unlikely(!(gr_status & GR_READY)))
68984+ return 1;
68985+
68986+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68987+ return 1;
68988+
68989+ /* ignore Eric Biederman */
68990+ if (IS_PRIVATE(dentry->d_inode))
68991+ return 1;
68992+
68993+ subj = task->acl;
68994+ read_lock(&gr_inode_lock);
68995+ do {
68996+ obj = lookup_acl_obj_label(ino, dev, subj);
68997+ if (obj != NULL) {
68998+ read_unlock(&gr_inode_lock);
68999+ return (obj->mode & GR_FIND) ? 1 : 0;
69000+ }
69001+ } while ((subj = subj->parent_subject));
69002+ read_unlock(&gr_inode_lock);
69003+
69004+ /* this is purely an optimization since we're looking for an object
69005+ for the directory we're doing a readdir on
69006+ if it's possible for any globbed object to match the entry we're
69007+ filling into the directory, then the object we find here will be
69008+ an anchor point with attached globbed objects
69009+ */
69010+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
69011+ if (obj->globbed == NULL)
69012+ return (obj->mode & GR_FIND) ? 1 : 0;
69013+
69014+ is_not_root = ((obj->filename[0] == '/') &&
69015+ (obj->filename[1] == '\0')) ? 0 : 1;
69016+ bufsize = PAGE_SIZE - namelen - is_not_root;
69017+
69018+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
69019+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
69020+ return 1;
69021+
69022+ preempt_disable();
69023+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69024+ bufsize);
69025+
69026+ bufsize = strlen(path);
69027+
69028+ /* if base is "/", don't append an additional slash */
69029+ if (is_not_root)
69030+ *(path + bufsize) = '/';
69031+ memcpy(path + bufsize + is_not_root, name, namelen);
69032+ *(path + bufsize + namelen + is_not_root) = '\0';
69033+
69034+ tmp = obj->globbed;
69035+ while (tmp) {
69036+ if (!glob_match(tmp->filename, path)) {
69037+ preempt_enable();
69038+ return (tmp->mode & GR_FIND) ? 1 : 0;
69039+ }
69040+ tmp = tmp->next;
69041+ }
69042+ preempt_enable();
69043+ return (obj->mode & GR_FIND) ? 1 : 0;
69044+}
69045+
69046+void gr_put_exec_file(struct task_struct *task)
69047+{
69048+ struct file *filp;
69049+
69050+ write_lock(&grsec_exec_file_lock);
69051+ filp = task->exec_file;
69052+ task->exec_file = NULL;
69053+ write_unlock(&grsec_exec_file_lock);
69054+
69055+ if (filp)
69056+ fput(filp);
69057+
69058+ return;
69059+}
69060+
69061+
69062+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
69063+EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
69064+#endif
69065+#ifdef CONFIG_SECURITY
69066+EXPORT_SYMBOL_GPL(gr_check_user_change);
69067+EXPORT_SYMBOL_GPL(gr_check_group_change);
69068+#endif
69069+
69070diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
69071new file mode 100644
69072index 0000000..18ffbbd
69073--- /dev/null
69074+++ b/grsecurity/gracl_alloc.c
69075@@ -0,0 +1,105 @@
69076+#include <linux/kernel.h>
69077+#include <linux/mm.h>
69078+#include <linux/slab.h>
69079+#include <linux/vmalloc.h>
69080+#include <linux/gracl.h>
69081+#include <linux/grsecurity.h>
69082+
69083+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
69084+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
69085+
69086+static __inline__ int
69087+alloc_pop(void)
69088+{
69089+ if (current_alloc_state->alloc_stack_next == 1)
69090+ return 0;
69091+
69092+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
69093+
69094+ current_alloc_state->alloc_stack_next--;
69095+
69096+ return 1;
69097+}
69098+
69099+static __inline__ int
69100+alloc_push(void *buf)
69101+{
69102+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
69103+ return 1;
69104+
69105+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
69106+
69107+ current_alloc_state->alloc_stack_next++;
69108+
69109+ return 0;
69110+}
69111+
69112+void *
69113+acl_alloc(unsigned long len)
69114+{
69115+ void *ret = NULL;
69116+
69117+ if (!len || len > PAGE_SIZE)
69118+ goto out;
69119+
69120+ ret = kmalloc(len, GFP_KERNEL);
69121+
69122+ if (ret) {
69123+ if (alloc_push(ret)) {
69124+ kfree(ret);
69125+ ret = NULL;
69126+ }
69127+ }
69128+
69129+out:
69130+ return ret;
69131+}
69132+
69133+void *
69134+acl_alloc_num(unsigned long num, unsigned long len)
69135+{
69136+ if (!len || (num > (PAGE_SIZE / len)))
69137+ return NULL;
69138+
69139+ return acl_alloc(num * len);
69140+}
69141+
69142+void
69143+acl_free_all(void)
69144+{
69145+ if (!current_alloc_state->alloc_stack)
69146+ return;
69147+
69148+ while (alloc_pop()) ;
69149+
69150+ if (current_alloc_state->alloc_stack) {
69151+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
69152+ kfree(current_alloc_state->alloc_stack);
69153+ else
69154+ vfree(current_alloc_state->alloc_stack);
69155+ }
69156+
69157+ current_alloc_state->alloc_stack = NULL;
69158+ current_alloc_state->alloc_stack_size = 1;
69159+ current_alloc_state->alloc_stack_next = 1;
69160+
69161+ return;
69162+}
69163+
69164+int
69165+acl_alloc_stack_init(unsigned long size)
69166+{
69167+ if ((size * sizeof (void *)) <= PAGE_SIZE)
69168+ current_alloc_state->alloc_stack =
69169+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
69170+ else
69171+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
69172+
69173+ current_alloc_state->alloc_stack_size = size;
69174+ current_alloc_state->alloc_stack_next = 1;
69175+
69176+ if (!current_alloc_state->alloc_stack)
69177+ return 0;
69178+ else
69179+ return 1;
69180+}
69181diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
69182new file mode 100644
69183index 0000000..bdd51ea
69184--- /dev/null
69185+++ b/grsecurity/gracl_cap.c
69186@@ -0,0 +1,110 @@
69187+#include <linux/kernel.h>
69188+#include <linux/module.h>
69189+#include <linux/sched.h>
69190+#include <linux/gracl.h>
69191+#include <linux/grsecurity.h>
69192+#include <linux/grinternal.h>
69193+
69194+extern const char *captab_log[];
69195+extern int captab_log_entries;
69196+
69197+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69198+{
69199+ struct acl_subject_label *curracl;
69200+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69201+ kernel_cap_t cap_audit = __cap_empty_set;
69202+
69203+ if (!gr_acl_is_enabled())
69204+ return 1;
69205+
69206+ curracl = task->acl;
69207+
69208+ cap_drop = curracl->cap_lower;
69209+ cap_mask = curracl->cap_mask;
69210+ cap_audit = curracl->cap_invert_audit;
69211+
69212+ while ((curracl = curracl->parent_subject)) {
69213+ /* if the cap isn't specified in the current computed mask but is specified in the
69214+ current level subject, and is lowered in the current level subject, then add
69215+ it to the set of dropped capabilities
69216+ otherwise, add the current level subject's mask to the current computed mask
69217+ */
69218+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69219+ cap_raise(cap_mask, cap);
69220+ if (cap_raised(curracl->cap_lower, cap))
69221+ cap_raise(cap_drop, cap);
69222+ if (cap_raised(curracl->cap_invert_audit, cap))
69223+ cap_raise(cap_audit, cap);
69224+ }
69225+ }
69226+
69227+ if (!cap_raised(cap_drop, cap)) {
69228+ if (cap_raised(cap_audit, cap))
69229+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
69230+ return 1;
69231+ }
69232+
69233+ curracl = task->acl;
69234+
69235+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
69236+ && cap_raised(cred->cap_effective, cap)) {
69237+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69238+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
69239+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
69240+ gr_to_filename(task->exec_file->f_path.dentry,
69241+ task->exec_file->f_path.mnt) : curracl->filename,
69242+ curracl->filename, 0UL,
69243+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
69244+ return 1;
69245+ }
69246+
69247+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
69248+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
69249+
69250+ return 0;
69251+}
69252+
69253+int
69254+gr_acl_is_capable(const int cap)
69255+{
69256+ return gr_task_acl_is_capable(current, current_cred(), cap);
69257+}
69258+
69259+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
69260+{
69261+ struct acl_subject_label *curracl;
69262+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69263+
69264+ if (!gr_acl_is_enabled())
69265+ return 1;
69266+
69267+ curracl = task->acl;
69268+
69269+ cap_drop = curracl->cap_lower;
69270+ cap_mask = curracl->cap_mask;
69271+
69272+ while ((curracl = curracl->parent_subject)) {
69273+ /* if the cap isn't specified in the current computed mask but is specified in the
69274+ current level subject, and is lowered in the current level subject, then add
69275+ it to the set of dropped capabilities
69276+ otherwise, add the current level subject's mask to the current computed mask
69277+ */
69278+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69279+ cap_raise(cap_mask, cap);
69280+ if (cap_raised(curracl->cap_lower, cap))
69281+ cap_raise(cap_drop, cap);
69282+ }
69283+ }
69284+
69285+ if (!cap_raised(cap_drop, cap))
69286+ return 1;
69287+
69288+ return 0;
69289+}
69290+
69291+int
69292+gr_acl_is_capable_nolog(const int cap)
69293+{
69294+ return gr_task_acl_is_capable_nolog(current, cap);
69295+}
69296+
69297diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
69298new file mode 100644
69299index 0000000..ca25605
69300--- /dev/null
69301+++ b/grsecurity/gracl_compat.c
69302@@ -0,0 +1,270 @@
69303+#include <linux/kernel.h>
69304+#include <linux/gracl.h>
69305+#include <linux/compat.h>
69306+#include <linux/gracl_compat.h>
69307+
69308+#include <asm/uaccess.h>
69309+
69310+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
69311+{
69312+ struct gr_arg_wrapper_compat uwrapcompat;
69313+
69314+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
69315+ return -EFAULT;
69316+
69317+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
69318+ (uwrapcompat.version != 0x2901)) ||
69319+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
69320+ return -EINVAL;
69321+
69322+ uwrap->arg = compat_ptr(uwrapcompat.arg);
69323+ uwrap->version = uwrapcompat.version;
69324+ uwrap->size = sizeof(struct gr_arg);
69325+
69326+ return 0;
69327+}
69328+
69329+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
69330+{
69331+ struct gr_arg_compat argcompat;
69332+
69333+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
69334+ return -EFAULT;
69335+
69336+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
69337+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
69338+ arg->role_db.num_roles = argcompat.role_db.num_roles;
69339+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
69340+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
69341+ arg->role_db.num_objects = argcompat.role_db.num_objects;
69342+
69343+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
69344+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
69345+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
69346+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
69347+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
69348+ arg->segv_device = argcompat.segv_device;
69349+ arg->segv_inode = argcompat.segv_inode;
69350+ arg->segv_uid = argcompat.segv_uid;
69351+ arg->num_sprole_pws = argcompat.num_sprole_pws;
69352+ arg->mode = argcompat.mode;
69353+
69354+ return 0;
69355+}
69356+
69357+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
69358+{
69359+ struct acl_object_label_compat objcompat;
69360+
69361+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
69362+ return -EFAULT;
69363+
69364+ obj->filename = compat_ptr(objcompat.filename);
69365+ obj->inode = objcompat.inode;
69366+ obj->device = objcompat.device;
69367+ obj->mode = objcompat.mode;
69368+
69369+ obj->nested = compat_ptr(objcompat.nested);
69370+ obj->globbed = compat_ptr(objcompat.globbed);
69371+
69372+ obj->prev = compat_ptr(objcompat.prev);
69373+ obj->next = compat_ptr(objcompat.next);
69374+
69375+ return 0;
69376+}
69377+
69378+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
69379+{
69380+ unsigned int i;
69381+ struct acl_subject_label_compat subjcompat;
69382+
69383+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
69384+ return -EFAULT;
69385+
69386+ subj->filename = compat_ptr(subjcompat.filename);
69387+ subj->inode = subjcompat.inode;
69388+ subj->device = subjcompat.device;
69389+ subj->mode = subjcompat.mode;
69390+ subj->cap_mask = subjcompat.cap_mask;
69391+ subj->cap_lower = subjcompat.cap_lower;
69392+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
69393+
69394+ for (i = 0; i < GR_NLIMITS; i++) {
69395+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
69396+ subj->res[i].rlim_cur = RLIM_INFINITY;
69397+ else
69398+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
69399+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
69400+ subj->res[i].rlim_max = RLIM_INFINITY;
69401+ else
69402+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
69403+ }
69404+ subj->resmask = subjcompat.resmask;
69405+
69406+ subj->user_trans_type = subjcompat.user_trans_type;
69407+ subj->group_trans_type = subjcompat.group_trans_type;
69408+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
69409+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
69410+ subj->user_trans_num = subjcompat.user_trans_num;
69411+ subj->group_trans_num = subjcompat.group_trans_num;
69412+
69413+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
69414+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
69415+ subj->ip_type = subjcompat.ip_type;
69416+ subj->ips = compat_ptr(subjcompat.ips);
69417+ subj->ip_num = subjcompat.ip_num;
69418+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
69419+
69420+ subj->crashes = subjcompat.crashes;
69421+ subj->expires = subjcompat.expires;
69422+
69423+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
69424+ subj->hash = compat_ptr(subjcompat.hash);
69425+ subj->prev = compat_ptr(subjcompat.prev);
69426+ subj->next = compat_ptr(subjcompat.next);
69427+
69428+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
69429+ subj->obj_hash_size = subjcompat.obj_hash_size;
69430+ subj->pax_flags = subjcompat.pax_flags;
69431+
69432+ return 0;
69433+}
69434+
69435+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
69436+{
69437+ struct acl_role_label_compat rolecompat;
69438+
69439+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
69440+ return -EFAULT;
69441+
69442+ role->rolename = compat_ptr(rolecompat.rolename);
69443+ role->uidgid = rolecompat.uidgid;
69444+ role->roletype = rolecompat.roletype;
69445+
69446+ role->auth_attempts = rolecompat.auth_attempts;
69447+ role->expires = rolecompat.expires;
69448+
69449+ role->root_label = compat_ptr(rolecompat.root_label);
69450+ role->hash = compat_ptr(rolecompat.hash);
69451+
69452+ role->prev = compat_ptr(rolecompat.prev);
69453+ role->next = compat_ptr(rolecompat.next);
69454+
69455+ role->transitions = compat_ptr(rolecompat.transitions);
69456+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
69457+ role->domain_children = compat_ptr(rolecompat.domain_children);
69458+ role->domain_child_num = rolecompat.domain_child_num;
69459+
69460+ role->umask = rolecompat.umask;
69461+
69462+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
69463+ role->subj_hash_size = rolecompat.subj_hash_size;
69464+
69465+ return 0;
69466+}
69467+
69468+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
69469+{
69470+ struct role_allowed_ip_compat roleip_compat;
69471+
69472+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
69473+ return -EFAULT;
69474+
69475+ roleip->addr = roleip_compat.addr;
69476+ roleip->netmask = roleip_compat.netmask;
69477+
69478+ roleip->prev = compat_ptr(roleip_compat.prev);
69479+ roleip->next = compat_ptr(roleip_compat.next);
69480+
69481+ return 0;
69482+}
69483+
69484+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
69485+{
69486+ struct role_transition_compat trans_compat;
69487+
69488+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
69489+ return -EFAULT;
69490+
69491+ trans->rolename = compat_ptr(trans_compat.rolename);
69492+
69493+ trans->prev = compat_ptr(trans_compat.prev);
69494+ trans->next = compat_ptr(trans_compat.next);
69495+
69496+ return 0;
69497+
69498+}
69499+
69500+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
69501+{
69502+ struct gr_hash_struct_compat hash_compat;
69503+
69504+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
69505+ return -EFAULT;
69506+
69507+ hash->table = compat_ptr(hash_compat.table);
69508+ hash->nametable = compat_ptr(hash_compat.nametable);
69509+ hash->first = compat_ptr(hash_compat.first);
69510+
69511+ hash->table_size = hash_compat.table_size;
69512+ hash->used_size = hash_compat.used_size;
69513+
69514+ hash->type = hash_compat.type;
69515+
69516+ return 0;
69517+}
69518+
69519+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
69520+{
69521+ compat_uptr_t ptrcompat;
69522+
69523+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
69524+ return -EFAULT;
69525+
69526+ *(void **)ptr = compat_ptr(ptrcompat);
69527+
69528+ return 0;
69529+}
69530+
69531+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
69532+{
69533+ struct acl_ip_label_compat ip_compat;
69534+
69535+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
69536+ return -EFAULT;
69537+
69538+ ip->iface = compat_ptr(ip_compat.iface);
69539+ ip->addr = ip_compat.addr;
69540+ ip->netmask = ip_compat.netmask;
69541+ ip->low = ip_compat.low;
69542+ ip->high = ip_compat.high;
69543+ ip->mode = ip_compat.mode;
69544+ ip->type = ip_compat.type;
69545+
69546+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
69547+
69548+ ip->prev = compat_ptr(ip_compat.prev);
69549+ ip->next = compat_ptr(ip_compat.next);
69550+
69551+ return 0;
69552+}
69553+
69554+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
69555+{
69556+ struct sprole_pw_compat pw_compat;
69557+
69558+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
69559+ return -EFAULT;
69560+
69561+ pw->rolename = compat_ptr(pw_compat.rolename);
69562+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
69563+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
69564+
69565+ return 0;
69566+}
69567+
69568+size_t get_gr_arg_wrapper_size_compat(void)
69569+{
69570+ return sizeof(struct gr_arg_wrapper_compat);
69571+}
69572+
69573diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
69574new file mode 100644
69575index 0000000..a89b1f4
69576--- /dev/null
69577+++ b/grsecurity/gracl_fs.c
69578@@ -0,0 +1,437 @@
69579+#include <linux/kernel.h>
69580+#include <linux/sched.h>
69581+#include <linux/types.h>
69582+#include <linux/fs.h>
69583+#include <linux/file.h>
69584+#include <linux/stat.h>
69585+#include <linux/grsecurity.h>
69586+#include <linux/grinternal.h>
69587+#include <linux/gracl.h>
69588+
69589+umode_t
69590+gr_acl_umask(void)
69591+{
69592+ if (unlikely(!gr_acl_is_enabled()))
69593+ return 0;
69594+
69595+ return current->role->umask;
69596+}
69597+
69598+__u32
69599+gr_acl_handle_hidden_file(const struct dentry * dentry,
69600+ const struct vfsmount * mnt)
69601+{
69602+ __u32 mode;
69603+
69604+ if (unlikely(d_is_negative(dentry)))
69605+ return GR_FIND;
69606+
69607+ mode =
69608+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
69609+
69610+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
69611+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
69612+ return mode;
69613+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
69614+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
69615+ return 0;
69616+ } else if (unlikely(!(mode & GR_FIND)))
69617+ return 0;
69618+
69619+ return GR_FIND;
69620+}
69621+
69622+__u32
69623+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
69624+ int acc_mode)
69625+{
69626+ __u32 reqmode = GR_FIND;
69627+ __u32 mode;
69628+
69629+ if (unlikely(d_is_negative(dentry)))
69630+ return reqmode;
69631+
69632+ if (acc_mode & MAY_APPEND)
69633+ reqmode |= GR_APPEND;
69634+ else if (acc_mode & MAY_WRITE)
69635+ reqmode |= GR_WRITE;
69636+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
69637+ reqmode |= GR_READ;
69638+
69639+ mode =
69640+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
69641+ mnt);
69642+
69643+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69644+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
69645+ reqmode & GR_READ ? " reading" : "",
69646+ reqmode & GR_WRITE ? " writing" : reqmode &
69647+ GR_APPEND ? " appending" : "");
69648+ return reqmode;
69649+ } else
69650+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69651+ {
69652+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
69653+ reqmode & GR_READ ? " reading" : "",
69654+ reqmode & GR_WRITE ? " writing" : reqmode &
69655+ GR_APPEND ? " appending" : "");
69656+ return 0;
69657+ } else if (unlikely((mode & reqmode) != reqmode))
69658+ return 0;
69659+
69660+ return reqmode;
69661+}
69662+
69663+__u32
69664+gr_acl_handle_creat(const struct dentry * dentry,
69665+ const struct dentry * p_dentry,
69666+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
69667+ const int imode)
69668+{
69669+ __u32 reqmode = GR_WRITE | GR_CREATE;
69670+ __u32 mode;
69671+
69672+ if (acc_mode & MAY_APPEND)
69673+ reqmode |= GR_APPEND;
69674+ // if a directory was required or the directory already exists, then
69675+ // don't count this open as a read
69676+ if ((acc_mode & MAY_READ) &&
69677+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
69678+ reqmode |= GR_READ;
69679+ if ((open_flags & O_CREAT) &&
69680+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
69681+ reqmode |= GR_SETID;
69682+
69683+ mode =
69684+ gr_check_create(dentry, p_dentry, p_mnt,
69685+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
69686+
69687+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69688+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
69689+ reqmode & GR_READ ? " reading" : "",
69690+ reqmode & GR_WRITE ? " writing" : reqmode &
69691+ GR_APPEND ? " appending" : "");
69692+ return reqmode;
69693+ } else
69694+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69695+ {
69696+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
69697+ reqmode & GR_READ ? " reading" : "",
69698+ reqmode & GR_WRITE ? " writing" : reqmode &
69699+ GR_APPEND ? " appending" : "");
69700+ return 0;
69701+ } else if (unlikely((mode & reqmode) != reqmode))
69702+ return 0;
69703+
69704+ return reqmode;
69705+}
69706+
69707+__u32
69708+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
69709+ const int fmode)
69710+{
69711+ __u32 mode, reqmode = GR_FIND;
69712+
69713+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
69714+ reqmode |= GR_EXEC;
69715+ if (fmode & S_IWOTH)
69716+ reqmode |= GR_WRITE;
69717+ if (fmode & S_IROTH)
69718+ reqmode |= GR_READ;
69719+
69720+ mode =
69721+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
69722+ mnt);
69723+
69724+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69725+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
69726+ reqmode & GR_READ ? " reading" : "",
69727+ reqmode & GR_WRITE ? " writing" : "",
69728+ reqmode & GR_EXEC ? " executing" : "");
69729+ return reqmode;
69730+ } else
69731+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69732+ {
69733+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
69734+ reqmode & GR_READ ? " reading" : "",
69735+ reqmode & GR_WRITE ? " writing" : "",
69736+ reqmode & GR_EXEC ? " executing" : "");
69737+ return 0;
69738+ } else if (unlikely((mode & reqmode) != reqmode))
69739+ return 0;
69740+
69741+ return reqmode;
69742+}
69743+
69744+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
69745+{
69746+ __u32 mode;
69747+
69748+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
69749+
69750+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
69751+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
69752+ return mode;
69753+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
69754+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
69755+ return 0;
69756+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
69757+ return 0;
69758+
69759+ return (reqmode);
69760+}
69761+
69762+__u32
69763+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
69764+{
69765+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
69766+}
69767+
69768+__u32
69769+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
69770+{
69771+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
69772+}
69773+
69774+__u32
69775+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
69776+{
69777+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
69778+}
69779+
69780+__u32
69781+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
69782+{
69783+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
69784+}
69785+
69786+__u32
69787+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
69788+ umode_t *modeptr)
69789+{
69790+ umode_t mode;
69791+
69792+ *modeptr &= ~gr_acl_umask();
69793+ mode = *modeptr;
69794+
69795+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
69796+ return 1;
69797+
69798+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
69799+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
69800+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
69801+ GR_CHMOD_ACL_MSG);
69802+ } else {
69803+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
69804+ }
69805+}
69806+
69807+__u32
69808+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
69809+{
69810+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
69811+}
69812+
69813+__u32
69814+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
69815+{
69816+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
69817+}
69818+
69819+__u32
69820+gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
69821+{
69822+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
69823+}
69824+
69825+__u32
69826+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
69827+{
69828+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
69829+}
69830+
69831+__u32
69832+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
69833+{
69834+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
69835+ GR_UNIXCONNECT_ACL_MSG);
69836+}
69837+
69838+/* hardlinks require at minimum create and link permission,
69839+ any additional privilege required is based on the
69840+ privilege of the file being linked to
69841+*/
69842+__u32
69843+gr_acl_handle_link(const struct dentry * new_dentry,
69844+ const struct dentry * parent_dentry,
69845+ const struct vfsmount * parent_mnt,
69846+ const struct dentry * old_dentry,
69847+ const struct vfsmount * old_mnt, const struct filename *to)
69848+{
69849+ __u32 mode;
69850+ __u32 needmode = GR_CREATE | GR_LINK;
69851+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
69852+
69853+ mode =
69854+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
69855+ old_mnt);
69856+
69857+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
69858+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
69859+ return mode;
69860+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
69861+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
69862+ return 0;
69863+ } else if (unlikely((mode & needmode) != needmode))
69864+ return 0;
69865+
69866+ return 1;
69867+}
69868+
69869+__u32
69870+gr_acl_handle_symlink(const struct dentry * new_dentry,
69871+ const struct dentry * parent_dentry,
69872+ const struct vfsmount * parent_mnt, const struct filename *from)
69873+{
69874+ __u32 needmode = GR_WRITE | GR_CREATE;
69875+ __u32 mode;
69876+
69877+ mode =
69878+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
69879+ GR_CREATE | GR_AUDIT_CREATE |
69880+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
69881+
69882+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
69883+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
69884+ return mode;
69885+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
69886+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
69887+ return 0;
69888+ } else if (unlikely((mode & needmode) != needmode))
69889+ return 0;
69890+
69891+ return (GR_WRITE | GR_CREATE);
69892+}
69893+
69894+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)
69895+{
69896+ __u32 mode;
69897+
69898+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
69899+
69900+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
69901+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
69902+ return mode;
69903+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
69904+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
69905+ return 0;
69906+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
69907+ return 0;
69908+
69909+ return (reqmode);
69910+}
69911+
69912+__u32
69913+gr_acl_handle_mknod(const struct dentry * new_dentry,
69914+ const struct dentry * parent_dentry,
69915+ const struct vfsmount * parent_mnt,
69916+ const int mode)
69917+{
69918+ __u32 reqmode = GR_WRITE | GR_CREATE;
69919+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
69920+ reqmode |= GR_SETID;
69921+
69922+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
69923+ reqmode, GR_MKNOD_ACL_MSG);
69924+}
69925+
69926+__u32
69927+gr_acl_handle_mkdir(const struct dentry *new_dentry,
69928+ const struct dentry *parent_dentry,
69929+ const struct vfsmount *parent_mnt)
69930+{
69931+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
69932+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
69933+}
69934+
69935+#define RENAME_CHECK_SUCCESS(old, new) \
69936+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
69937+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
69938+
69939+int
69940+gr_acl_handle_rename(struct dentry *new_dentry,
69941+ struct dentry *parent_dentry,
69942+ const struct vfsmount *parent_mnt,
69943+ struct dentry *old_dentry,
69944+ struct inode *old_parent_inode,
69945+ struct vfsmount *old_mnt, const struct filename *newname)
69946+{
69947+ __u32 comp1, comp2;
69948+ int error = 0;
69949+
69950+ if (unlikely(!gr_acl_is_enabled()))
69951+ return 0;
69952+
69953+ if (d_is_negative(new_dentry)) {
69954+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
69955+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
69956+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
69957+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
69958+ GR_DELETE | GR_AUDIT_DELETE |
69959+ GR_AUDIT_READ | GR_AUDIT_WRITE |
69960+ GR_SUPPRESS, old_mnt);
69961+ } else {
69962+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
69963+ GR_CREATE | GR_DELETE |
69964+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
69965+ GR_AUDIT_READ | GR_AUDIT_WRITE |
69966+ GR_SUPPRESS, parent_mnt);
69967+ comp2 =
69968+ gr_search_file(old_dentry,
69969+ GR_READ | GR_WRITE | GR_AUDIT_READ |
69970+ GR_DELETE | GR_AUDIT_DELETE |
69971+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
69972+ }
69973+
69974+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
69975+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
69976+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
69977+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
69978+ && !(comp2 & GR_SUPPRESS)) {
69979+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
69980+ error = -EACCES;
69981+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
69982+ error = -EACCES;
69983+
69984+ return error;
69985+}
69986+
69987+void
69988+gr_acl_handle_exit(void)
69989+{
69990+ u16 id;
69991+ char *rolename;
69992+
69993+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
69994+ !(current->role->roletype & GR_ROLE_PERSIST))) {
69995+ id = current->acl_role_id;
69996+ rolename = current->role->rolename;
69997+ gr_set_acls(1);
69998+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
69999+ }
70000+
70001+ gr_put_exec_file(current);
70002+ return;
70003+}
70004+
70005+int
70006+gr_acl_handle_procpidmem(const struct task_struct *task)
70007+{
70008+ if (unlikely(!gr_acl_is_enabled()))
70009+ return 0;
70010+
70011+ if (task != current && task->acl->mode & GR_PROTPROCFD)
70012+ return -EACCES;
70013+
70014+ return 0;
70015+}
70016diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
70017new file mode 100644
70018index 0000000..f056b81
70019--- /dev/null
70020+++ b/grsecurity/gracl_ip.c
70021@@ -0,0 +1,386 @@
70022+#include <linux/kernel.h>
70023+#include <asm/uaccess.h>
70024+#include <asm/errno.h>
70025+#include <net/sock.h>
70026+#include <linux/file.h>
70027+#include <linux/fs.h>
70028+#include <linux/net.h>
70029+#include <linux/in.h>
70030+#include <linux/skbuff.h>
70031+#include <linux/ip.h>
70032+#include <linux/udp.h>
70033+#include <linux/types.h>
70034+#include <linux/sched.h>
70035+#include <linux/netdevice.h>
70036+#include <linux/inetdevice.h>
70037+#include <linux/gracl.h>
70038+#include <linux/grsecurity.h>
70039+#include <linux/grinternal.h>
70040+
70041+#define GR_BIND 0x01
70042+#define GR_CONNECT 0x02
70043+#define GR_INVERT 0x04
70044+#define GR_BINDOVERRIDE 0x08
70045+#define GR_CONNECTOVERRIDE 0x10
70046+#define GR_SOCK_FAMILY 0x20
70047+
70048+static const char * gr_protocols[IPPROTO_MAX] = {
70049+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
70050+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
70051+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
70052+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
70053+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
70054+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
70055+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
70056+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
70057+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
70058+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
70059+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
70060+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
70061+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
70062+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
70063+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
70064+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
70065+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
70066+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
70067+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
70068+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
70069+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
70070+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
70071+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
70072+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
70073+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
70074+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
70075+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
70076+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
70077+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
70078+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
70079+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
70080+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
70081+ };
70082+
70083+static const char * gr_socktypes[SOCK_MAX] = {
70084+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
70085+ "unknown:7", "unknown:8", "unknown:9", "packet"
70086+ };
70087+
70088+static const char * gr_sockfamilies[AF_MAX+1] = {
70089+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
70090+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
70091+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
70092+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
70093+ };
70094+
70095+const char *
70096+gr_proto_to_name(unsigned char proto)
70097+{
70098+ return gr_protocols[proto];
70099+}
70100+
70101+const char *
70102+gr_socktype_to_name(unsigned char type)
70103+{
70104+ return gr_socktypes[type];
70105+}
70106+
70107+const char *
70108+gr_sockfamily_to_name(unsigned char family)
70109+{
70110+ return gr_sockfamilies[family];
70111+}
70112+
70113+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
70114+
70115+int
70116+gr_search_socket(const int domain, const int type, const int protocol)
70117+{
70118+ struct acl_subject_label *curr;
70119+ const struct cred *cred = current_cred();
70120+
70121+ if (unlikely(!gr_acl_is_enabled()))
70122+ goto exit;
70123+
70124+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
70125+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
70126+ goto exit; // let the kernel handle it
70127+
70128+ curr = current->acl;
70129+
70130+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
70131+ /* the family is allowed, if this is PF_INET allow it only if
70132+ the extra sock type/protocol checks pass */
70133+ if (domain == PF_INET)
70134+ goto inet_check;
70135+ goto exit;
70136+ } else {
70137+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70138+ __u32 fakeip = 0;
70139+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70140+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70141+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70142+ gr_to_filename(current->exec_file->f_path.dentry,
70143+ current->exec_file->f_path.mnt) :
70144+ curr->filename, curr->filename,
70145+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
70146+ &current->signal->saved_ip);
70147+ goto exit;
70148+ }
70149+ goto exit_fail;
70150+ }
70151+
70152+inet_check:
70153+ /* the rest of this checking is for IPv4 only */
70154+ if (!curr->ips)
70155+ goto exit;
70156+
70157+ if ((curr->ip_type & (1U << type)) &&
70158+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
70159+ goto exit;
70160+
70161+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70162+ /* we don't place acls on raw sockets , and sometimes
70163+ dgram/ip sockets are opened for ioctl and not
70164+ bind/connect, so we'll fake a bind learn log */
70165+ if (type == SOCK_RAW || type == SOCK_PACKET) {
70166+ __u32 fakeip = 0;
70167+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70168+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70169+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70170+ gr_to_filename(current->exec_file->f_path.dentry,
70171+ current->exec_file->f_path.mnt) :
70172+ curr->filename, curr->filename,
70173+ &fakeip, 0, type,
70174+ protocol, GR_CONNECT, &current->signal->saved_ip);
70175+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
70176+ __u32 fakeip = 0;
70177+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70178+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70179+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70180+ gr_to_filename(current->exec_file->f_path.dentry,
70181+ current->exec_file->f_path.mnt) :
70182+ curr->filename, curr->filename,
70183+ &fakeip, 0, type,
70184+ protocol, GR_BIND, &current->signal->saved_ip);
70185+ }
70186+ /* we'll log when they use connect or bind */
70187+ goto exit;
70188+ }
70189+
70190+exit_fail:
70191+ if (domain == PF_INET)
70192+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
70193+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
70194+ else if (rcu_access_pointer(net_families[domain]) != NULL)
70195+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
70196+ gr_socktype_to_name(type), protocol);
70197+
70198+ return 0;
70199+exit:
70200+ return 1;
70201+}
70202+
70203+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)
70204+{
70205+ if ((ip->mode & mode) &&
70206+ (ip_port >= ip->low) &&
70207+ (ip_port <= ip->high) &&
70208+ ((ntohl(ip_addr) & our_netmask) ==
70209+ (ntohl(our_addr) & our_netmask))
70210+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
70211+ && (ip->type & (1U << type))) {
70212+ if (ip->mode & GR_INVERT)
70213+ return 2; // specifically denied
70214+ else
70215+ return 1; // allowed
70216+ }
70217+
70218+ return 0; // not specifically allowed, may continue parsing
70219+}
70220+
70221+static int
70222+gr_search_connectbind(const int full_mode, struct sock *sk,
70223+ struct sockaddr_in *addr, const int type)
70224+{
70225+ char iface[IFNAMSIZ] = {0};
70226+ struct acl_subject_label *curr;
70227+ struct acl_ip_label *ip;
70228+ struct inet_sock *isk;
70229+ struct net_device *dev;
70230+ struct in_device *idev;
70231+ unsigned long i;
70232+ int ret;
70233+ int mode = full_mode & (GR_BIND | GR_CONNECT);
70234+ __u32 ip_addr = 0;
70235+ __u32 our_addr;
70236+ __u32 our_netmask;
70237+ char *p;
70238+ __u16 ip_port = 0;
70239+ const struct cred *cred = current_cred();
70240+
70241+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
70242+ return 0;
70243+
70244+ curr = current->acl;
70245+ isk = inet_sk(sk);
70246+
70247+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
70248+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
70249+ addr->sin_addr.s_addr = curr->inaddr_any_override;
70250+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
70251+ struct sockaddr_in saddr;
70252+ int err;
70253+
70254+ saddr.sin_family = AF_INET;
70255+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
70256+ saddr.sin_port = isk->inet_sport;
70257+
70258+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70259+ if (err)
70260+ return err;
70261+
70262+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70263+ if (err)
70264+ return err;
70265+ }
70266+
70267+ if (!curr->ips)
70268+ return 0;
70269+
70270+ ip_addr = addr->sin_addr.s_addr;
70271+ ip_port = ntohs(addr->sin_port);
70272+
70273+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70274+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70275+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70276+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70277+ gr_to_filename(current->exec_file->f_path.dentry,
70278+ current->exec_file->f_path.mnt) :
70279+ curr->filename, curr->filename,
70280+ &ip_addr, ip_port, type,
70281+ sk->sk_protocol, mode, &current->signal->saved_ip);
70282+ return 0;
70283+ }
70284+
70285+ for (i = 0; i < curr->ip_num; i++) {
70286+ ip = *(curr->ips + i);
70287+ if (ip->iface != NULL) {
70288+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
70289+ p = strchr(iface, ':');
70290+ if (p != NULL)
70291+ *p = '\0';
70292+ dev = dev_get_by_name(sock_net(sk), iface);
70293+ if (dev == NULL)
70294+ continue;
70295+ idev = in_dev_get(dev);
70296+ if (idev == NULL) {
70297+ dev_put(dev);
70298+ continue;
70299+ }
70300+ rcu_read_lock();
70301+ for_ifa(idev) {
70302+ if (!strcmp(ip->iface, ifa->ifa_label)) {
70303+ our_addr = ifa->ifa_address;
70304+ our_netmask = 0xffffffff;
70305+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70306+ if (ret == 1) {
70307+ rcu_read_unlock();
70308+ in_dev_put(idev);
70309+ dev_put(dev);
70310+ return 0;
70311+ } else if (ret == 2) {
70312+ rcu_read_unlock();
70313+ in_dev_put(idev);
70314+ dev_put(dev);
70315+ goto denied;
70316+ }
70317+ }
70318+ } endfor_ifa(idev);
70319+ rcu_read_unlock();
70320+ in_dev_put(idev);
70321+ dev_put(dev);
70322+ } else {
70323+ our_addr = ip->addr;
70324+ our_netmask = ip->netmask;
70325+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70326+ if (ret == 1)
70327+ return 0;
70328+ else if (ret == 2)
70329+ goto denied;
70330+ }
70331+ }
70332+
70333+denied:
70334+ if (mode == GR_BIND)
70335+ 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));
70336+ else if (mode == GR_CONNECT)
70337+ 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));
70338+
70339+ return -EACCES;
70340+}
70341+
70342+int
70343+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
70344+{
70345+ /* always allow disconnection of dgram sockets with connect */
70346+ if (addr->sin_family == AF_UNSPEC)
70347+ return 0;
70348+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
70349+}
70350+
70351+int
70352+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
70353+{
70354+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
70355+}
70356+
70357+int gr_search_listen(struct socket *sock)
70358+{
70359+ struct sock *sk = sock->sk;
70360+ struct sockaddr_in addr;
70361+
70362+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70363+ addr.sin_port = inet_sk(sk)->inet_sport;
70364+
70365+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70366+}
70367+
70368+int gr_search_accept(struct socket *sock)
70369+{
70370+ struct sock *sk = sock->sk;
70371+ struct sockaddr_in addr;
70372+
70373+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70374+ addr.sin_port = inet_sk(sk)->inet_sport;
70375+
70376+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70377+}
70378+
70379+int
70380+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
70381+{
70382+ if (addr)
70383+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
70384+ else {
70385+ struct sockaddr_in sin;
70386+ const struct inet_sock *inet = inet_sk(sk);
70387+
70388+ sin.sin_addr.s_addr = inet->inet_daddr;
70389+ sin.sin_port = inet->inet_dport;
70390+
70391+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70392+ }
70393+}
70394+
70395+int
70396+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
70397+{
70398+ struct sockaddr_in sin;
70399+
70400+ if (unlikely(skb->len < sizeof (struct udphdr)))
70401+ return 0; // skip this packet
70402+
70403+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
70404+ sin.sin_port = udp_hdr(skb)->source;
70405+
70406+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70407+}
70408diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
70409new file mode 100644
70410index 0000000..25f54ef
70411--- /dev/null
70412+++ b/grsecurity/gracl_learn.c
70413@@ -0,0 +1,207 @@
70414+#include <linux/kernel.h>
70415+#include <linux/mm.h>
70416+#include <linux/sched.h>
70417+#include <linux/poll.h>
70418+#include <linux/string.h>
70419+#include <linux/file.h>
70420+#include <linux/types.h>
70421+#include <linux/vmalloc.h>
70422+#include <linux/grinternal.h>
70423+
70424+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
70425+ size_t count, loff_t *ppos);
70426+extern int gr_acl_is_enabled(void);
70427+
70428+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
70429+static int gr_learn_attached;
70430+
70431+/* use a 512k buffer */
70432+#define LEARN_BUFFER_SIZE (512 * 1024)
70433+
70434+static DEFINE_SPINLOCK(gr_learn_lock);
70435+static DEFINE_MUTEX(gr_learn_user_mutex);
70436+
70437+/* we need to maintain two buffers, so that the kernel context of grlearn
70438+ uses a semaphore around the userspace copying, and the other kernel contexts
70439+ use a spinlock when copying into the buffer, since they cannot sleep
70440+*/
70441+static char *learn_buffer;
70442+static char *learn_buffer_user;
70443+static int learn_buffer_len;
70444+static int learn_buffer_user_len;
70445+
70446+static ssize_t
70447+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
70448+{
70449+ DECLARE_WAITQUEUE(wait, current);
70450+ ssize_t retval = 0;
70451+
70452+ add_wait_queue(&learn_wait, &wait);
70453+ set_current_state(TASK_INTERRUPTIBLE);
70454+ do {
70455+ mutex_lock(&gr_learn_user_mutex);
70456+ spin_lock(&gr_learn_lock);
70457+ if (learn_buffer_len)
70458+ break;
70459+ spin_unlock(&gr_learn_lock);
70460+ mutex_unlock(&gr_learn_user_mutex);
70461+ if (file->f_flags & O_NONBLOCK) {
70462+ retval = -EAGAIN;
70463+ goto out;
70464+ }
70465+ if (signal_pending(current)) {
70466+ retval = -ERESTARTSYS;
70467+ goto out;
70468+ }
70469+
70470+ schedule();
70471+ } while (1);
70472+
70473+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
70474+ learn_buffer_user_len = learn_buffer_len;
70475+ retval = learn_buffer_len;
70476+ learn_buffer_len = 0;
70477+
70478+ spin_unlock(&gr_learn_lock);
70479+
70480+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
70481+ retval = -EFAULT;
70482+
70483+ mutex_unlock(&gr_learn_user_mutex);
70484+out:
70485+ set_current_state(TASK_RUNNING);
70486+ remove_wait_queue(&learn_wait, &wait);
70487+ return retval;
70488+}
70489+
70490+static unsigned int
70491+poll_learn(struct file * file, poll_table * wait)
70492+{
70493+ poll_wait(file, &learn_wait, wait);
70494+
70495+ if (learn_buffer_len)
70496+ return (POLLIN | POLLRDNORM);
70497+
70498+ return 0;
70499+}
70500+
70501+void
70502+gr_clear_learn_entries(void)
70503+{
70504+ char *tmp;
70505+
70506+ mutex_lock(&gr_learn_user_mutex);
70507+ spin_lock(&gr_learn_lock);
70508+ tmp = learn_buffer;
70509+ learn_buffer = NULL;
70510+ spin_unlock(&gr_learn_lock);
70511+ if (tmp)
70512+ vfree(tmp);
70513+ if (learn_buffer_user != NULL) {
70514+ vfree(learn_buffer_user);
70515+ learn_buffer_user = NULL;
70516+ }
70517+ learn_buffer_len = 0;
70518+ mutex_unlock(&gr_learn_user_mutex);
70519+
70520+ return;
70521+}
70522+
70523+void
70524+gr_add_learn_entry(const char *fmt, ...)
70525+{
70526+ va_list args;
70527+ unsigned int len;
70528+
70529+ if (!gr_learn_attached)
70530+ return;
70531+
70532+ spin_lock(&gr_learn_lock);
70533+
70534+ /* leave a gap at the end so we know when it's "full" but don't have to
70535+ compute the exact length of the string we're trying to append
70536+ */
70537+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
70538+ spin_unlock(&gr_learn_lock);
70539+ wake_up_interruptible(&learn_wait);
70540+ return;
70541+ }
70542+ if (learn_buffer == NULL) {
70543+ spin_unlock(&gr_learn_lock);
70544+ return;
70545+ }
70546+
70547+ va_start(args, fmt);
70548+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
70549+ va_end(args);
70550+
70551+ learn_buffer_len += len + 1;
70552+
70553+ spin_unlock(&gr_learn_lock);
70554+ wake_up_interruptible(&learn_wait);
70555+
70556+ return;
70557+}
70558+
70559+static int
70560+open_learn(struct inode *inode, struct file *file)
70561+{
70562+ if (file->f_mode & FMODE_READ && gr_learn_attached)
70563+ return -EBUSY;
70564+ if (file->f_mode & FMODE_READ) {
70565+ int retval = 0;
70566+ mutex_lock(&gr_learn_user_mutex);
70567+ if (learn_buffer == NULL)
70568+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
70569+ if (learn_buffer_user == NULL)
70570+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
70571+ if (learn_buffer == NULL) {
70572+ retval = -ENOMEM;
70573+ goto out_error;
70574+ }
70575+ if (learn_buffer_user == NULL) {
70576+ retval = -ENOMEM;
70577+ goto out_error;
70578+ }
70579+ learn_buffer_len = 0;
70580+ learn_buffer_user_len = 0;
70581+ gr_learn_attached = 1;
70582+out_error:
70583+ mutex_unlock(&gr_learn_user_mutex);
70584+ return retval;
70585+ }
70586+ return 0;
70587+}
70588+
70589+static int
70590+close_learn(struct inode *inode, struct file *file)
70591+{
70592+ if (file->f_mode & FMODE_READ) {
70593+ char *tmp = NULL;
70594+ mutex_lock(&gr_learn_user_mutex);
70595+ spin_lock(&gr_learn_lock);
70596+ tmp = learn_buffer;
70597+ learn_buffer = NULL;
70598+ spin_unlock(&gr_learn_lock);
70599+ if (tmp)
70600+ vfree(tmp);
70601+ if (learn_buffer_user != NULL) {
70602+ vfree(learn_buffer_user);
70603+ learn_buffer_user = NULL;
70604+ }
70605+ learn_buffer_len = 0;
70606+ learn_buffer_user_len = 0;
70607+ gr_learn_attached = 0;
70608+ mutex_unlock(&gr_learn_user_mutex);
70609+ }
70610+
70611+ return 0;
70612+}
70613+
70614+const struct file_operations grsec_fops = {
70615+ .read = read_learn,
70616+ .write = write_grsec_handler,
70617+ .open = open_learn,
70618+ .release = close_learn,
70619+ .poll = poll_learn,
70620+};
70621diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
70622new file mode 100644
70623index 0000000..361a099
70624--- /dev/null
70625+++ b/grsecurity/gracl_policy.c
70626@@ -0,0 +1,1782 @@
70627+#include <linux/kernel.h>
70628+#include <linux/module.h>
70629+#include <linux/sched.h>
70630+#include <linux/mm.h>
70631+#include <linux/file.h>
70632+#include <linux/fs.h>
70633+#include <linux/namei.h>
70634+#include <linux/mount.h>
70635+#include <linux/tty.h>
70636+#include <linux/proc_fs.h>
70637+#include <linux/lglock.h>
70638+#include <linux/slab.h>
70639+#include <linux/vmalloc.h>
70640+#include <linux/types.h>
70641+#include <linux/sysctl.h>
70642+#include <linux/netdevice.h>
70643+#include <linux/ptrace.h>
70644+#include <linux/gracl.h>
70645+#include <linux/gralloc.h>
70646+#include <linux/security.h>
70647+#include <linux/grinternal.h>
70648+#include <linux/pid_namespace.h>
70649+#include <linux/stop_machine.h>
70650+#include <linux/fdtable.h>
70651+#include <linux/percpu.h>
70652+#include <linux/lglock.h>
70653+#include <linux/hugetlb.h>
70654+#include <linux/posix-timers.h>
70655+#include "../fs/mount.h"
70656+
70657+#include <asm/uaccess.h>
70658+#include <asm/errno.h>
70659+#include <asm/mman.h>
70660+
70661+extern struct gr_policy_state *polstate;
70662+
70663+#define FOR_EACH_ROLE_START(role) \
70664+ role = polstate->role_list; \
70665+ while (role) {
70666+
70667+#define FOR_EACH_ROLE_END(role) \
70668+ role = role->prev; \
70669+ }
70670+
70671+struct path gr_real_root;
70672+
70673+extern struct gr_alloc_state *current_alloc_state;
70674+
70675+u16 acl_sp_role_value;
70676+
70677+static DEFINE_MUTEX(gr_dev_mutex);
70678+
70679+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
70680+extern void gr_clear_learn_entries(void);
70681+
70682+static struct gr_arg gr_usermode;
70683+static unsigned char gr_system_salt[GR_SALT_LEN];
70684+static unsigned char gr_system_sum[GR_SHA_LEN];
70685+
70686+static unsigned int gr_auth_attempts = 0;
70687+static unsigned long gr_auth_expires = 0UL;
70688+
70689+struct acl_object_label *fakefs_obj_rw;
70690+struct acl_object_label *fakefs_obj_rwx;
70691+
70692+extern int gr_init_uidset(void);
70693+extern void gr_free_uidset(void);
70694+extern void gr_remove_uid(uid_t uid);
70695+extern int gr_find_uid(uid_t uid);
70696+
70697+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
70698+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
70699+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
70700+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
70701+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);
70702+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
70703+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
70704+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
70705+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
70706+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
70707+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
70708+extern void assign_special_role(const char *rolename);
70709+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
70710+extern int gr_rbac_disable(void *unused);
70711+extern void gr_enable_rbac_system(void);
70712+
70713+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
70714+{
70715+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
70716+ return -EFAULT;
70717+
70718+ return 0;
70719+}
70720+
70721+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
70722+{
70723+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
70724+ return -EFAULT;
70725+
70726+ return 0;
70727+}
70728+
70729+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
70730+{
70731+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
70732+ return -EFAULT;
70733+
70734+ return 0;
70735+}
70736+
70737+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
70738+{
70739+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
70740+ return -EFAULT;
70741+
70742+ return 0;
70743+}
70744+
70745+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
70746+{
70747+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
70748+ return -EFAULT;
70749+
70750+ return 0;
70751+}
70752+
70753+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
70754+{
70755+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
70756+ return -EFAULT;
70757+
70758+ return 0;
70759+}
70760+
70761+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
70762+{
70763+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
70764+ return -EFAULT;
70765+
70766+ return 0;
70767+}
70768+
70769+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
70770+{
70771+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
70772+ return -EFAULT;
70773+
70774+ return 0;
70775+}
70776+
70777+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
70778+{
70779+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
70780+ return -EFAULT;
70781+
70782+ return 0;
70783+}
70784+
70785+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
70786+{
70787+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
70788+ return -EFAULT;
70789+
70790+ if (((uwrap->version != GRSECURITY_VERSION) &&
70791+ (uwrap->version != 0x2901)) ||
70792+ (uwrap->size != sizeof(struct gr_arg)))
70793+ return -EINVAL;
70794+
70795+ return 0;
70796+}
70797+
70798+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
70799+{
70800+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
70801+ return -EFAULT;
70802+
70803+ return 0;
70804+}
70805+
70806+static size_t get_gr_arg_wrapper_size_normal(void)
70807+{
70808+ return sizeof(struct gr_arg_wrapper);
70809+}
70810+
70811+#ifdef CONFIG_COMPAT
70812+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
70813+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
70814+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
70815+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
70816+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
70817+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
70818+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
70819+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
70820+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
70821+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
70822+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
70823+extern size_t get_gr_arg_wrapper_size_compat(void);
70824+
70825+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
70826+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
70827+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
70828+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
70829+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
70830+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
70831+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
70832+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
70833+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
70834+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
70835+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
70836+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
70837+
70838+#else
70839+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
70840+#define copy_gr_arg copy_gr_arg_normal
70841+#define copy_gr_hash_struct copy_gr_hash_struct_normal
70842+#define copy_acl_object_label copy_acl_object_label_normal
70843+#define copy_acl_subject_label copy_acl_subject_label_normal
70844+#define copy_acl_role_label copy_acl_role_label_normal
70845+#define copy_acl_ip_label copy_acl_ip_label_normal
70846+#define copy_pointer_from_array copy_pointer_from_array_normal
70847+#define copy_sprole_pw copy_sprole_pw_normal
70848+#define copy_role_transition copy_role_transition_normal
70849+#define copy_role_allowed_ip copy_role_allowed_ip_normal
70850+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
70851+#endif
70852+
70853+static struct acl_subject_label *
70854+lookup_subject_map(const struct acl_subject_label *userp)
70855+{
70856+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
70857+ struct subject_map *match;
70858+
70859+ match = polstate->subj_map_set.s_hash[index];
70860+
70861+ while (match && match->user != userp)
70862+ match = match->next;
70863+
70864+ if (match != NULL)
70865+ return match->kernel;
70866+ else
70867+ return NULL;
70868+}
70869+
70870+static void
70871+insert_subj_map_entry(struct subject_map *subjmap)
70872+{
70873+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
70874+ struct subject_map **curr;
70875+
70876+ subjmap->prev = NULL;
70877+
70878+ curr = &polstate->subj_map_set.s_hash[index];
70879+ if (*curr != NULL)
70880+ (*curr)->prev = subjmap;
70881+
70882+ subjmap->next = *curr;
70883+ *curr = subjmap;
70884+
70885+ return;
70886+}
70887+
70888+static void
70889+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
70890+{
70891+ unsigned int index =
70892+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
70893+ struct acl_role_label **curr;
70894+ struct acl_role_label *tmp, *tmp2;
70895+
70896+ curr = &polstate->acl_role_set.r_hash[index];
70897+
70898+ /* simple case, slot is empty, just set it to our role */
70899+ if (*curr == NULL) {
70900+ *curr = role;
70901+ } else {
70902+ /* example:
70903+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
70904+ 2 -> 3
70905+ */
70906+ /* first check to see if we can already be reached via this slot */
70907+ tmp = *curr;
70908+ while (tmp && tmp != role)
70909+ tmp = tmp->next;
70910+ if (tmp == role) {
70911+ /* we don't need to add ourselves to this slot's chain */
70912+ return;
70913+ }
70914+ /* we need to add ourselves to this chain, two cases */
70915+ if (role->next == NULL) {
70916+ /* simple case, append the current chain to our role */
70917+ role->next = *curr;
70918+ *curr = role;
70919+ } else {
70920+ /* 1 -> 2 -> 3 -> 4
70921+ 2 -> 3 -> 4
70922+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
70923+ */
70924+ /* trickier case: walk our role's chain until we find
70925+ the role for the start of the current slot's chain */
70926+ tmp = role;
70927+ tmp2 = *curr;
70928+ while (tmp->next && tmp->next != tmp2)
70929+ tmp = tmp->next;
70930+ if (tmp->next == tmp2) {
70931+ /* from example above, we found 3, so just
70932+ replace this slot's chain with ours */
70933+ *curr = role;
70934+ } else {
70935+ /* we didn't find a subset of our role's chain
70936+ in the current slot's chain, so append their
70937+ chain to ours, and set us as the first role in
70938+ the slot's chain
70939+
70940+ we could fold this case with the case above,
70941+ but making it explicit for clarity
70942+ */
70943+ tmp->next = tmp2;
70944+ *curr = role;
70945+ }
70946+ }
70947+ }
70948+
70949+ return;
70950+}
70951+
70952+static void
70953+insert_acl_role_label(struct acl_role_label *role)
70954+{
70955+ int i;
70956+
70957+ if (polstate->role_list == NULL) {
70958+ polstate->role_list = role;
70959+ role->prev = NULL;
70960+ } else {
70961+ role->prev = polstate->role_list;
70962+ polstate->role_list = role;
70963+ }
70964+
70965+ /* used for hash chains */
70966+ role->next = NULL;
70967+
70968+ if (role->roletype & GR_ROLE_DOMAIN) {
70969+ for (i = 0; i < role->domain_child_num; i++)
70970+ __insert_acl_role_label(role, role->domain_children[i]);
70971+ } else
70972+ __insert_acl_role_label(role, role->uidgid);
70973+}
70974+
70975+static int
70976+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
70977+{
70978+ struct name_entry **curr, *nentry;
70979+ struct inodev_entry *ientry;
70980+ unsigned int len = strlen(name);
70981+ unsigned int key = full_name_hash(name, len);
70982+ unsigned int index = key % polstate->name_set.n_size;
70983+
70984+ curr = &polstate->name_set.n_hash[index];
70985+
70986+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
70987+ curr = &((*curr)->next);
70988+
70989+ if (*curr != NULL)
70990+ return 1;
70991+
70992+ nentry = acl_alloc(sizeof (struct name_entry));
70993+ if (nentry == NULL)
70994+ return 0;
70995+ ientry = acl_alloc(sizeof (struct inodev_entry));
70996+ if (ientry == NULL)
70997+ return 0;
70998+ ientry->nentry = nentry;
70999+
71000+ nentry->key = key;
71001+ nentry->name = name;
71002+ nentry->inode = inode;
71003+ nentry->device = device;
71004+ nentry->len = len;
71005+ nentry->deleted = deleted;
71006+
71007+ nentry->prev = NULL;
71008+ curr = &polstate->name_set.n_hash[index];
71009+ if (*curr != NULL)
71010+ (*curr)->prev = nentry;
71011+ nentry->next = *curr;
71012+ *curr = nentry;
71013+
71014+ /* insert us into the table searchable by inode/dev */
71015+ __insert_inodev_entry(polstate, ientry);
71016+
71017+ return 1;
71018+}
71019+
71020+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
71021+
71022+static void *
71023+create_table(__u32 * len, int elementsize)
71024+{
71025+ unsigned int table_sizes[] = {
71026+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
71027+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
71028+ 4194301, 8388593, 16777213, 33554393, 67108859
71029+ };
71030+ void *newtable = NULL;
71031+ unsigned int pwr = 0;
71032+
71033+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
71034+ table_sizes[pwr] <= *len)
71035+ pwr++;
71036+
71037+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
71038+ return newtable;
71039+
71040+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
71041+ newtable =
71042+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
71043+ else
71044+ newtable = vmalloc(table_sizes[pwr] * elementsize);
71045+
71046+ *len = table_sizes[pwr];
71047+
71048+ return newtable;
71049+}
71050+
71051+static int
71052+init_variables(const struct gr_arg *arg, bool reload)
71053+{
71054+ struct task_struct *reaper = init_pid_ns.child_reaper;
71055+ unsigned int stacksize;
71056+
71057+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
71058+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
71059+ polstate->name_set.n_size = arg->role_db.num_objects;
71060+ polstate->inodev_set.i_size = arg->role_db.num_objects;
71061+
71062+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
71063+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
71064+ return 1;
71065+
71066+ if (!reload) {
71067+ if (!gr_init_uidset())
71068+ return 1;
71069+ }
71070+
71071+ /* set up the stack that holds allocation info */
71072+
71073+ stacksize = arg->role_db.num_pointers + 5;
71074+
71075+ if (!acl_alloc_stack_init(stacksize))
71076+ return 1;
71077+
71078+ if (!reload) {
71079+ /* grab reference for the real root dentry and vfsmount */
71080+ get_fs_root(reaper->fs, &gr_real_root);
71081+
71082+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71083+ 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);
71084+#endif
71085+
71086+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71087+ if (fakefs_obj_rw == NULL)
71088+ return 1;
71089+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
71090+
71091+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71092+ if (fakefs_obj_rwx == NULL)
71093+ return 1;
71094+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
71095+ }
71096+
71097+ polstate->subj_map_set.s_hash =
71098+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
71099+ polstate->acl_role_set.r_hash =
71100+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
71101+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
71102+ polstate->inodev_set.i_hash =
71103+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
71104+
71105+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
71106+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
71107+ return 1;
71108+
71109+ memset(polstate->subj_map_set.s_hash, 0,
71110+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
71111+ memset(polstate->acl_role_set.r_hash, 0,
71112+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
71113+ memset(polstate->name_set.n_hash, 0,
71114+ sizeof (struct name_entry *) * polstate->name_set.n_size);
71115+ memset(polstate->inodev_set.i_hash, 0,
71116+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
71117+
71118+ return 0;
71119+}
71120+
71121+/* free information not needed after startup
71122+ currently contains user->kernel pointer mappings for subjects
71123+*/
71124+
71125+static void
71126+free_init_variables(void)
71127+{
71128+ __u32 i;
71129+
71130+ if (polstate->subj_map_set.s_hash) {
71131+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
71132+ if (polstate->subj_map_set.s_hash[i]) {
71133+ kfree(polstate->subj_map_set.s_hash[i]);
71134+ polstate->subj_map_set.s_hash[i] = NULL;
71135+ }
71136+ }
71137+
71138+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
71139+ PAGE_SIZE)
71140+ kfree(polstate->subj_map_set.s_hash);
71141+ else
71142+ vfree(polstate->subj_map_set.s_hash);
71143+ }
71144+
71145+ return;
71146+}
71147+
71148+static void
71149+free_variables(bool reload)
71150+{
71151+ struct acl_subject_label *s;
71152+ struct acl_role_label *r;
71153+ struct task_struct *task, *task2;
71154+ unsigned int x;
71155+
71156+ if (!reload) {
71157+ gr_clear_learn_entries();
71158+
71159+ read_lock(&tasklist_lock);
71160+ do_each_thread(task2, task) {
71161+ task->acl_sp_role = 0;
71162+ task->acl_role_id = 0;
71163+ task->inherited = 0;
71164+ task->acl = NULL;
71165+ task->role = NULL;
71166+ } while_each_thread(task2, task);
71167+ read_unlock(&tasklist_lock);
71168+
71169+ kfree(fakefs_obj_rw);
71170+ fakefs_obj_rw = NULL;
71171+ kfree(fakefs_obj_rwx);
71172+ fakefs_obj_rwx = NULL;
71173+
71174+ /* release the reference to the real root dentry and vfsmount */
71175+ path_put(&gr_real_root);
71176+ memset(&gr_real_root, 0, sizeof(gr_real_root));
71177+ }
71178+
71179+ /* free all object hash tables */
71180+
71181+ FOR_EACH_ROLE_START(r)
71182+ if (r->subj_hash == NULL)
71183+ goto next_role;
71184+ FOR_EACH_SUBJECT_START(r, s, x)
71185+ if (s->obj_hash == NULL)
71186+ break;
71187+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71188+ kfree(s->obj_hash);
71189+ else
71190+ vfree(s->obj_hash);
71191+ FOR_EACH_SUBJECT_END(s, x)
71192+ FOR_EACH_NESTED_SUBJECT_START(r, s)
71193+ if (s->obj_hash == NULL)
71194+ break;
71195+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71196+ kfree(s->obj_hash);
71197+ else
71198+ vfree(s->obj_hash);
71199+ FOR_EACH_NESTED_SUBJECT_END(s)
71200+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
71201+ kfree(r->subj_hash);
71202+ else
71203+ vfree(r->subj_hash);
71204+ r->subj_hash = NULL;
71205+next_role:
71206+ FOR_EACH_ROLE_END(r)
71207+
71208+ acl_free_all();
71209+
71210+ if (polstate->acl_role_set.r_hash) {
71211+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
71212+ PAGE_SIZE)
71213+ kfree(polstate->acl_role_set.r_hash);
71214+ else
71215+ vfree(polstate->acl_role_set.r_hash);
71216+ }
71217+ if (polstate->name_set.n_hash) {
71218+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
71219+ PAGE_SIZE)
71220+ kfree(polstate->name_set.n_hash);
71221+ else
71222+ vfree(polstate->name_set.n_hash);
71223+ }
71224+
71225+ if (polstate->inodev_set.i_hash) {
71226+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
71227+ PAGE_SIZE)
71228+ kfree(polstate->inodev_set.i_hash);
71229+ else
71230+ vfree(polstate->inodev_set.i_hash);
71231+ }
71232+
71233+ if (!reload)
71234+ gr_free_uidset();
71235+
71236+ memset(&polstate->name_set, 0, sizeof (struct name_db));
71237+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
71238+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
71239+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
71240+
71241+ polstate->default_role = NULL;
71242+ polstate->kernel_role = NULL;
71243+ polstate->role_list = NULL;
71244+
71245+ return;
71246+}
71247+
71248+static struct acl_subject_label *
71249+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
71250+
71251+static int alloc_and_copy_string(char **name, unsigned int maxlen)
71252+{
71253+ unsigned int len = strnlen_user(*name, maxlen);
71254+ char *tmp;
71255+
71256+ if (!len || len >= maxlen)
71257+ return -EINVAL;
71258+
71259+ if ((tmp = (char *) acl_alloc(len)) == NULL)
71260+ return -ENOMEM;
71261+
71262+ if (copy_from_user(tmp, *name, len))
71263+ return -EFAULT;
71264+
71265+ tmp[len-1] = '\0';
71266+ *name = tmp;
71267+
71268+ return 0;
71269+}
71270+
71271+static int
71272+copy_user_glob(struct acl_object_label *obj)
71273+{
71274+ struct acl_object_label *g_tmp, **guser;
71275+ int error;
71276+
71277+ if (obj->globbed == NULL)
71278+ return 0;
71279+
71280+ guser = &obj->globbed;
71281+ while (*guser) {
71282+ g_tmp = (struct acl_object_label *)
71283+ acl_alloc(sizeof (struct acl_object_label));
71284+ if (g_tmp == NULL)
71285+ return -ENOMEM;
71286+
71287+ if (copy_acl_object_label(g_tmp, *guser))
71288+ return -EFAULT;
71289+
71290+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
71291+ if (error)
71292+ return error;
71293+
71294+ *guser = g_tmp;
71295+ guser = &(g_tmp->next);
71296+ }
71297+
71298+ return 0;
71299+}
71300+
71301+static int
71302+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
71303+ struct acl_role_label *role)
71304+{
71305+ struct acl_object_label *o_tmp;
71306+ int ret;
71307+
71308+ while (userp) {
71309+ if ((o_tmp = (struct acl_object_label *)
71310+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
71311+ return -ENOMEM;
71312+
71313+ if (copy_acl_object_label(o_tmp, userp))
71314+ return -EFAULT;
71315+
71316+ userp = o_tmp->prev;
71317+
71318+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
71319+ if (ret)
71320+ return ret;
71321+
71322+ insert_acl_obj_label(o_tmp, subj);
71323+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
71324+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
71325+ return -ENOMEM;
71326+
71327+ ret = copy_user_glob(o_tmp);
71328+ if (ret)
71329+ return ret;
71330+
71331+ if (o_tmp->nested) {
71332+ int already_copied;
71333+
71334+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
71335+ if (IS_ERR(o_tmp->nested))
71336+ return PTR_ERR(o_tmp->nested);
71337+
71338+ /* insert into nested subject list if we haven't copied this one yet
71339+ to prevent duplicate entries */
71340+ if (!already_copied) {
71341+ o_tmp->nested->next = role->hash->first;
71342+ role->hash->first = o_tmp->nested;
71343+ }
71344+ }
71345+ }
71346+
71347+ return 0;
71348+}
71349+
71350+static __u32
71351+count_user_subjs(struct acl_subject_label *userp)
71352+{
71353+ struct acl_subject_label s_tmp;
71354+ __u32 num = 0;
71355+
71356+ while (userp) {
71357+ if (copy_acl_subject_label(&s_tmp, userp))
71358+ break;
71359+
71360+ userp = s_tmp.prev;
71361+ }
71362+
71363+ return num;
71364+}
71365+
71366+static int
71367+copy_user_allowedips(struct acl_role_label *rolep)
71368+{
71369+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
71370+
71371+ ruserip = rolep->allowed_ips;
71372+
71373+ while (ruserip) {
71374+ rlast = rtmp;
71375+
71376+ if ((rtmp = (struct role_allowed_ip *)
71377+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
71378+ return -ENOMEM;
71379+
71380+ if (copy_role_allowed_ip(rtmp, ruserip))
71381+ return -EFAULT;
71382+
71383+ ruserip = rtmp->prev;
71384+
71385+ if (!rlast) {
71386+ rtmp->prev = NULL;
71387+ rolep->allowed_ips = rtmp;
71388+ } else {
71389+ rlast->next = rtmp;
71390+ rtmp->prev = rlast;
71391+ }
71392+
71393+ if (!ruserip)
71394+ rtmp->next = NULL;
71395+ }
71396+
71397+ return 0;
71398+}
71399+
71400+static int
71401+copy_user_transitions(struct acl_role_label *rolep)
71402+{
71403+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
71404+ int error;
71405+
71406+ rusertp = rolep->transitions;
71407+
71408+ while (rusertp) {
71409+ rlast = rtmp;
71410+
71411+ if ((rtmp = (struct role_transition *)
71412+ acl_alloc(sizeof (struct role_transition))) == NULL)
71413+ return -ENOMEM;
71414+
71415+ if (copy_role_transition(rtmp, rusertp))
71416+ return -EFAULT;
71417+
71418+ rusertp = rtmp->prev;
71419+
71420+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
71421+ if (error)
71422+ return error;
71423+
71424+ if (!rlast) {
71425+ rtmp->prev = NULL;
71426+ rolep->transitions = rtmp;
71427+ } else {
71428+ rlast->next = rtmp;
71429+ rtmp->prev = rlast;
71430+ }
71431+
71432+ if (!rusertp)
71433+ rtmp->next = NULL;
71434+ }
71435+
71436+ return 0;
71437+}
71438+
71439+static __u32 count_user_objs(const struct acl_object_label __user *userp)
71440+{
71441+ struct acl_object_label o_tmp;
71442+ __u32 num = 0;
71443+
71444+ while (userp) {
71445+ if (copy_acl_object_label(&o_tmp, userp))
71446+ break;
71447+
71448+ userp = o_tmp.prev;
71449+ num++;
71450+ }
71451+
71452+ return num;
71453+}
71454+
71455+static struct acl_subject_label *
71456+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
71457+{
71458+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
71459+ __u32 num_objs;
71460+ struct acl_ip_label **i_tmp, *i_utmp2;
71461+ struct gr_hash_struct ghash;
71462+ struct subject_map *subjmap;
71463+ unsigned int i_num;
71464+ int err;
71465+
71466+ if (already_copied != NULL)
71467+ *already_copied = 0;
71468+
71469+ s_tmp = lookup_subject_map(userp);
71470+
71471+ /* we've already copied this subject into the kernel, just return
71472+ the reference to it, and don't copy it over again
71473+ */
71474+ if (s_tmp) {
71475+ if (already_copied != NULL)
71476+ *already_copied = 1;
71477+ return(s_tmp);
71478+ }
71479+
71480+ if ((s_tmp = (struct acl_subject_label *)
71481+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
71482+ return ERR_PTR(-ENOMEM);
71483+
71484+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
71485+ if (subjmap == NULL)
71486+ return ERR_PTR(-ENOMEM);
71487+
71488+ subjmap->user = userp;
71489+ subjmap->kernel = s_tmp;
71490+ insert_subj_map_entry(subjmap);
71491+
71492+ if (copy_acl_subject_label(s_tmp, userp))
71493+ return ERR_PTR(-EFAULT);
71494+
71495+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
71496+ if (err)
71497+ return ERR_PTR(err);
71498+
71499+ if (!strcmp(s_tmp->filename, "/"))
71500+ role->root_label = s_tmp;
71501+
71502+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
71503+ return ERR_PTR(-EFAULT);
71504+
71505+ /* copy user and group transition tables */
71506+
71507+ if (s_tmp->user_trans_num) {
71508+ uid_t *uidlist;
71509+
71510+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
71511+ if (uidlist == NULL)
71512+ return ERR_PTR(-ENOMEM);
71513+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
71514+ return ERR_PTR(-EFAULT);
71515+
71516+ s_tmp->user_transitions = uidlist;
71517+ }
71518+
71519+ if (s_tmp->group_trans_num) {
71520+ gid_t *gidlist;
71521+
71522+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
71523+ if (gidlist == NULL)
71524+ return ERR_PTR(-ENOMEM);
71525+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
71526+ return ERR_PTR(-EFAULT);
71527+
71528+ s_tmp->group_transitions = gidlist;
71529+ }
71530+
71531+ /* set up object hash table */
71532+ num_objs = count_user_objs(ghash.first);
71533+
71534+ s_tmp->obj_hash_size = num_objs;
71535+ s_tmp->obj_hash =
71536+ (struct acl_object_label **)
71537+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
71538+
71539+ if (!s_tmp->obj_hash)
71540+ return ERR_PTR(-ENOMEM);
71541+
71542+ memset(s_tmp->obj_hash, 0,
71543+ s_tmp->obj_hash_size *
71544+ sizeof (struct acl_object_label *));
71545+
71546+ /* add in objects */
71547+ err = copy_user_objs(ghash.first, s_tmp, role);
71548+
71549+ if (err)
71550+ return ERR_PTR(err);
71551+
71552+ /* set pointer for parent subject */
71553+ if (s_tmp->parent_subject) {
71554+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
71555+
71556+ if (IS_ERR(s_tmp2))
71557+ return s_tmp2;
71558+
71559+ s_tmp->parent_subject = s_tmp2;
71560+ }
71561+
71562+ /* add in ip acls */
71563+
71564+ if (!s_tmp->ip_num) {
71565+ s_tmp->ips = NULL;
71566+ goto insert;
71567+ }
71568+
71569+ i_tmp =
71570+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
71571+ sizeof (struct acl_ip_label *));
71572+
71573+ if (!i_tmp)
71574+ return ERR_PTR(-ENOMEM);
71575+
71576+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
71577+ *(i_tmp + i_num) =
71578+ (struct acl_ip_label *)
71579+ acl_alloc(sizeof (struct acl_ip_label));
71580+ if (!*(i_tmp + i_num))
71581+ return ERR_PTR(-ENOMEM);
71582+
71583+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
71584+ return ERR_PTR(-EFAULT);
71585+
71586+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
71587+ return ERR_PTR(-EFAULT);
71588+
71589+ if ((*(i_tmp + i_num))->iface == NULL)
71590+ continue;
71591+
71592+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
71593+ if (err)
71594+ return ERR_PTR(err);
71595+ }
71596+
71597+ s_tmp->ips = i_tmp;
71598+
71599+insert:
71600+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
71601+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
71602+ return ERR_PTR(-ENOMEM);
71603+
71604+ return s_tmp;
71605+}
71606+
71607+static int
71608+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
71609+{
71610+ struct acl_subject_label s_pre;
71611+ struct acl_subject_label * ret;
71612+ int err;
71613+
71614+ while (userp) {
71615+ if (copy_acl_subject_label(&s_pre, userp))
71616+ return -EFAULT;
71617+
71618+ ret = do_copy_user_subj(userp, role, NULL);
71619+
71620+ err = PTR_ERR(ret);
71621+ if (IS_ERR(ret))
71622+ return err;
71623+
71624+ insert_acl_subj_label(ret, role);
71625+
71626+ userp = s_pre.prev;
71627+ }
71628+
71629+ return 0;
71630+}
71631+
71632+static int
71633+copy_user_acl(struct gr_arg *arg)
71634+{
71635+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
71636+ struct acl_subject_label *subj_list;
71637+ struct sprole_pw *sptmp;
71638+ struct gr_hash_struct *ghash;
71639+ uid_t *domainlist;
71640+ unsigned int r_num;
71641+ int err = 0;
71642+ __u16 i;
71643+ __u32 num_subjs;
71644+
71645+ /* we need a default and kernel role */
71646+ if (arg->role_db.num_roles < 2)
71647+ return -EINVAL;
71648+
71649+ /* copy special role authentication info from userspace */
71650+
71651+ polstate->num_sprole_pws = arg->num_sprole_pws;
71652+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
71653+
71654+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
71655+ return -ENOMEM;
71656+
71657+ for (i = 0; i < polstate->num_sprole_pws; i++) {
71658+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
71659+ if (!sptmp)
71660+ return -ENOMEM;
71661+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
71662+ return -EFAULT;
71663+
71664+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
71665+ if (err)
71666+ return err;
71667+
71668+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71669+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
71670+#endif
71671+
71672+ polstate->acl_special_roles[i] = sptmp;
71673+ }
71674+
71675+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
71676+
71677+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
71678+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
71679+
71680+ if (!r_tmp)
71681+ return -ENOMEM;
71682+
71683+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
71684+ return -EFAULT;
71685+
71686+ if (copy_acl_role_label(r_tmp, r_utmp2))
71687+ return -EFAULT;
71688+
71689+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
71690+ if (err)
71691+ return err;
71692+
71693+ if (!strcmp(r_tmp->rolename, "default")
71694+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
71695+ polstate->default_role = r_tmp;
71696+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
71697+ polstate->kernel_role = r_tmp;
71698+ }
71699+
71700+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
71701+ return -ENOMEM;
71702+
71703+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
71704+ return -EFAULT;
71705+
71706+ r_tmp->hash = ghash;
71707+
71708+ num_subjs = count_user_subjs(r_tmp->hash->first);
71709+
71710+ r_tmp->subj_hash_size = num_subjs;
71711+ r_tmp->subj_hash =
71712+ (struct acl_subject_label **)
71713+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
71714+
71715+ if (!r_tmp->subj_hash)
71716+ return -ENOMEM;
71717+
71718+ err = copy_user_allowedips(r_tmp);
71719+ if (err)
71720+ return err;
71721+
71722+ /* copy domain info */
71723+ if (r_tmp->domain_children != NULL) {
71724+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
71725+ if (domainlist == NULL)
71726+ return -ENOMEM;
71727+
71728+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
71729+ return -EFAULT;
71730+
71731+ r_tmp->domain_children = domainlist;
71732+ }
71733+
71734+ err = copy_user_transitions(r_tmp);
71735+ if (err)
71736+ return err;
71737+
71738+ memset(r_tmp->subj_hash, 0,
71739+ r_tmp->subj_hash_size *
71740+ sizeof (struct acl_subject_label *));
71741+
71742+ /* acquire the list of subjects, then NULL out
71743+ the list prior to parsing the subjects for this role,
71744+ as during this parsing the list is replaced with a list
71745+ of *nested* subjects for the role
71746+ */
71747+ subj_list = r_tmp->hash->first;
71748+
71749+ /* set nested subject list to null */
71750+ r_tmp->hash->first = NULL;
71751+
71752+ err = copy_user_subjs(subj_list, r_tmp);
71753+
71754+ if (err)
71755+ return err;
71756+
71757+ insert_acl_role_label(r_tmp);
71758+ }
71759+
71760+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
71761+ return -EINVAL;
71762+
71763+ return err;
71764+}
71765+
71766+static int gracl_reload_apply_policies(void *reload)
71767+{
71768+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
71769+ struct task_struct *task, *task2;
71770+ struct acl_role_label *role, *rtmp;
71771+ struct acl_subject_label *subj;
71772+ const struct cred *cred;
71773+ int role_applied;
71774+ int ret = 0;
71775+
71776+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
71777+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
71778+
71779+ /* first make sure we'll be able to apply the new policy cleanly */
71780+ do_each_thread(task2, task) {
71781+ if (task->exec_file == NULL)
71782+ continue;
71783+ role_applied = 0;
71784+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
71785+ /* preserve special roles */
71786+ FOR_EACH_ROLE_START(role)
71787+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
71788+ rtmp = task->role;
71789+ task->role = role;
71790+ role_applied = 1;
71791+ break;
71792+ }
71793+ FOR_EACH_ROLE_END(role)
71794+ }
71795+ if (!role_applied) {
71796+ cred = __task_cred(task);
71797+ rtmp = task->role;
71798+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
71799+ }
71800+ /* this handles non-nested inherited subjects, nested subjects will still
71801+ be dropped currently */
71802+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
71803+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
71804+ /* change the role back so that we've made no modifications to the policy */
71805+ task->role = rtmp;
71806+
71807+ if (subj == NULL || task->tmpacl == NULL) {
71808+ ret = -EINVAL;
71809+ goto out;
71810+ }
71811+ } while_each_thread(task2, task);
71812+
71813+ /* now actually apply the policy */
71814+
71815+ do_each_thread(task2, task) {
71816+ if (task->exec_file) {
71817+ role_applied = 0;
71818+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
71819+ /* preserve special roles */
71820+ FOR_EACH_ROLE_START(role)
71821+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
71822+ task->role = role;
71823+ role_applied = 1;
71824+ break;
71825+ }
71826+ FOR_EACH_ROLE_END(role)
71827+ }
71828+ if (!role_applied) {
71829+ cred = __task_cred(task);
71830+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
71831+ }
71832+ /* this handles non-nested inherited subjects, nested subjects will still
71833+ be dropped currently */
71834+ if (!reload_state->oldmode && task->inherited)
71835+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
71836+ else {
71837+ /* looked up and tagged to the task previously */
71838+ subj = task->tmpacl;
71839+ }
71840+ /* subj will be non-null */
71841+ __gr_apply_subject_to_task(polstate, task, subj);
71842+ if (reload_state->oldmode) {
71843+ task->acl_role_id = 0;
71844+ task->acl_sp_role = 0;
71845+ task->inherited = 0;
71846+ }
71847+ } else {
71848+ // it's a kernel process
71849+ task->role = polstate->kernel_role;
71850+ task->acl = polstate->kernel_role->root_label;
71851+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
71852+ task->acl->mode &= ~GR_PROCFIND;
71853+#endif
71854+ }
71855+ } while_each_thread(task2, task);
71856+
71857+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
71858+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
71859+
71860+out:
71861+
71862+ return ret;
71863+}
71864+
71865+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
71866+{
71867+ struct gr_reload_state new_reload_state = { };
71868+ int err;
71869+
71870+ new_reload_state.oldpolicy_ptr = polstate;
71871+ new_reload_state.oldalloc_ptr = current_alloc_state;
71872+ new_reload_state.oldmode = oldmode;
71873+
71874+ current_alloc_state = &new_reload_state.newalloc;
71875+ polstate = &new_reload_state.newpolicy;
71876+
71877+ /* everything relevant is now saved off, copy in the new policy */
71878+ if (init_variables(args, true)) {
71879+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
71880+ err = -ENOMEM;
71881+ goto error;
71882+ }
71883+
71884+ err = copy_user_acl(args);
71885+ free_init_variables();
71886+ if (err)
71887+ goto error;
71888+ /* the new policy is copied in, with the old policy available via saved_state
71889+ first go through applying roles, making sure to preserve special roles
71890+ then apply new subjects, making sure to preserve inherited and nested subjects,
71891+ though currently only inherited subjects will be preserved
71892+ */
71893+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
71894+ if (err)
71895+ goto error;
71896+
71897+ /* we've now applied the new policy, so restore the old policy state to free it */
71898+ polstate = &new_reload_state.oldpolicy;
71899+ current_alloc_state = &new_reload_state.oldalloc;
71900+ free_variables(true);
71901+
71902+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
71903+ to running_polstate/current_alloc_state inside stop_machine
71904+ */
71905+ err = 0;
71906+ goto out;
71907+error:
71908+ /* on error of loading the new policy, we'll just keep the previous
71909+ policy set around
71910+ */
71911+ free_variables(true);
71912+
71913+ /* doesn't affect runtime, but maintains consistent state */
71914+out:
71915+ polstate = new_reload_state.oldpolicy_ptr;
71916+ current_alloc_state = new_reload_state.oldalloc_ptr;
71917+
71918+ return err;
71919+}
71920+
71921+static int
71922+gracl_init(struct gr_arg *args)
71923+{
71924+ int error = 0;
71925+
71926+ memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
71927+ memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
71928+
71929+ if (init_variables(args, false)) {
71930+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
71931+ error = -ENOMEM;
71932+ goto out;
71933+ }
71934+
71935+ error = copy_user_acl(args);
71936+ free_init_variables();
71937+ if (error)
71938+ goto out;
71939+
71940+ error = gr_set_acls(0);
71941+ if (error)
71942+ goto out;
71943+
71944+ gr_enable_rbac_system();
71945+
71946+ return 0;
71947+
71948+out:
71949+ free_variables(false);
71950+ return error;
71951+}
71952+
71953+static int
71954+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
71955+ unsigned char **sum)
71956+{
71957+ struct acl_role_label *r;
71958+ struct role_allowed_ip *ipp;
71959+ struct role_transition *trans;
71960+ unsigned int i;
71961+ int found = 0;
71962+ u32 curr_ip = current->signal->curr_ip;
71963+
71964+ current->signal->saved_ip = curr_ip;
71965+
71966+ /* check transition table */
71967+
71968+ for (trans = current->role->transitions; trans; trans = trans->next) {
71969+ if (!strcmp(rolename, trans->rolename)) {
71970+ found = 1;
71971+ break;
71972+ }
71973+ }
71974+
71975+ if (!found)
71976+ return 0;
71977+
71978+ /* handle special roles that do not require authentication
71979+ and check ip */
71980+
71981+ FOR_EACH_ROLE_START(r)
71982+ if (!strcmp(rolename, r->rolename) &&
71983+ (r->roletype & GR_ROLE_SPECIAL)) {
71984+ found = 0;
71985+ if (r->allowed_ips != NULL) {
71986+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
71987+ if ((ntohl(curr_ip) & ipp->netmask) ==
71988+ (ntohl(ipp->addr) & ipp->netmask))
71989+ found = 1;
71990+ }
71991+ } else
71992+ found = 2;
71993+ if (!found)
71994+ return 0;
71995+
71996+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
71997+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
71998+ *salt = NULL;
71999+ *sum = NULL;
72000+ return 1;
72001+ }
72002+ }
72003+ FOR_EACH_ROLE_END(r)
72004+
72005+ for (i = 0; i < polstate->num_sprole_pws; i++) {
72006+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
72007+ *salt = polstate->acl_special_roles[i]->salt;
72008+ *sum = polstate->acl_special_roles[i]->sum;
72009+ return 1;
72010+ }
72011+ }
72012+
72013+ return 0;
72014+}
72015+
72016+int gr_check_secure_terminal(struct task_struct *task)
72017+{
72018+ struct task_struct *p, *p2, *p3;
72019+ struct files_struct *files;
72020+ struct fdtable *fdt;
72021+ struct file *our_file = NULL, *file;
72022+ int i;
72023+
72024+ if (task->signal->tty == NULL)
72025+ return 1;
72026+
72027+ files = get_files_struct(task);
72028+ if (files != NULL) {
72029+ rcu_read_lock();
72030+ fdt = files_fdtable(files);
72031+ for (i=0; i < fdt->max_fds; i++) {
72032+ file = fcheck_files(files, i);
72033+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
72034+ get_file(file);
72035+ our_file = file;
72036+ }
72037+ }
72038+ rcu_read_unlock();
72039+ put_files_struct(files);
72040+ }
72041+
72042+ if (our_file == NULL)
72043+ return 1;
72044+
72045+ read_lock(&tasklist_lock);
72046+ do_each_thread(p2, p) {
72047+ files = get_files_struct(p);
72048+ if (files == NULL ||
72049+ (p->signal && p->signal->tty == task->signal->tty)) {
72050+ if (files != NULL)
72051+ put_files_struct(files);
72052+ continue;
72053+ }
72054+ rcu_read_lock();
72055+ fdt = files_fdtable(files);
72056+ for (i=0; i < fdt->max_fds; i++) {
72057+ file = fcheck_files(files, i);
72058+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
72059+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
72060+ p3 = task;
72061+ while (task_pid_nr(p3) > 0) {
72062+ if (p3 == p)
72063+ break;
72064+ p3 = p3->real_parent;
72065+ }
72066+ if (p3 == p)
72067+ break;
72068+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
72069+ gr_handle_alertkill(p);
72070+ rcu_read_unlock();
72071+ put_files_struct(files);
72072+ read_unlock(&tasklist_lock);
72073+ fput(our_file);
72074+ return 0;
72075+ }
72076+ }
72077+ rcu_read_unlock();
72078+ put_files_struct(files);
72079+ } while_each_thread(p2, p);
72080+ read_unlock(&tasklist_lock);
72081+
72082+ fput(our_file);
72083+ return 1;
72084+}
72085+
72086+ssize_t
72087+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
72088+{
72089+ struct gr_arg_wrapper uwrap;
72090+ unsigned char *sprole_salt = NULL;
72091+ unsigned char *sprole_sum = NULL;
72092+ int error = 0;
72093+ int error2 = 0;
72094+ size_t req_count = 0;
72095+ unsigned char oldmode = 0;
72096+
72097+ mutex_lock(&gr_dev_mutex);
72098+
72099+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
72100+ error = -EPERM;
72101+ goto out;
72102+ }
72103+
72104+#ifdef CONFIG_COMPAT
72105+ pax_open_kernel();
72106+ if (is_compat_task()) {
72107+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
72108+ copy_gr_arg = &copy_gr_arg_compat;
72109+ copy_acl_object_label = &copy_acl_object_label_compat;
72110+ copy_acl_subject_label = &copy_acl_subject_label_compat;
72111+ copy_acl_role_label = &copy_acl_role_label_compat;
72112+ copy_acl_ip_label = &copy_acl_ip_label_compat;
72113+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
72114+ copy_role_transition = &copy_role_transition_compat;
72115+ copy_sprole_pw = &copy_sprole_pw_compat;
72116+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
72117+ copy_pointer_from_array = &copy_pointer_from_array_compat;
72118+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
72119+ } else {
72120+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
72121+ copy_gr_arg = &copy_gr_arg_normal;
72122+ copy_acl_object_label = &copy_acl_object_label_normal;
72123+ copy_acl_subject_label = &copy_acl_subject_label_normal;
72124+ copy_acl_role_label = &copy_acl_role_label_normal;
72125+ copy_acl_ip_label = &copy_acl_ip_label_normal;
72126+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
72127+ copy_role_transition = &copy_role_transition_normal;
72128+ copy_sprole_pw = &copy_sprole_pw_normal;
72129+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
72130+ copy_pointer_from_array = &copy_pointer_from_array_normal;
72131+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
72132+ }
72133+ pax_close_kernel();
72134+#endif
72135+
72136+ req_count = get_gr_arg_wrapper_size();
72137+
72138+ if (count != req_count) {
72139+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
72140+ error = -EINVAL;
72141+ goto out;
72142+ }
72143+
72144+
72145+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
72146+ gr_auth_expires = 0;
72147+ gr_auth_attempts = 0;
72148+ }
72149+
72150+ error = copy_gr_arg_wrapper(buf, &uwrap);
72151+ if (error)
72152+ goto out;
72153+
72154+ error = copy_gr_arg(uwrap.arg, &gr_usermode);
72155+ if (error)
72156+ goto out;
72157+
72158+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72159+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72160+ time_after(gr_auth_expires, get_seconds())) {
72161+ error = -EBUSY;
72162+ goto out;
72163+ }
72164+
72165+ /* if non-root trying to do anything other than use a special role,
72166+ do not attempt authentication, do not count towards authentication
72167+ locking
72168+ */
72169+
72170+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
72171+ gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72172+ gr_is_global_nonroot(current_uid())) {
72173+ error = -EPERM;
72174+ goto out;
72175+ }
72176+
72177+ /* ensure pw and special role name are null terminated */
72178+
72179+ gr_usermode.pw[GR_PW_LEN - 1] = '\0';
72180+ gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
72181+
72182+ /* Okay.
72183+ * We have our enough of the argument structure..(we have yet
72184+ * to copy_from_user the tables themselves) . Copy the tables
72185+ * only if we need them, i.e. for loading operations. */
72186+
72187+ switch (gr_usermode.mode) {
72188+ case GR_STATUS:
72189+ if (gr_acl_is_enabled()) {
72190+ error = 1;
72191+ if (!gr_check_secure_terminal(current))
72192+ error = 3;
72193+ } else
72194+ error = 2;
72195+ goto out;
72196+ case GR_SHUTDOWN:
72197+ if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72198+ stop_machine(gr_rbac_disable, NULL, NULL);
72199+ free_variables(false);
72200+ memset(&gr_usermode, 0, sizeof(gr_usermode));
72201+ memset(&gr_system_salt, 0, sizeof(gr_system_salt));
72202+ memset(&gr_system_sum, 0, sizeof(gr_system_sum));
72203+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
72204+ } else if (gr_acl_is_enabled()) {
72205+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
72206+ error = -EPERM;
72207+ } else {
72208+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
72209+ error = -EAGAIN;
72210+ }
72211+ break;
72212+ case GR_ENABLE:
72213+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
72214+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
72215+ else {
72216+ if (gr_acl_is_enabled())
72217+ error = -EAGAIN;
72218+ else
72219+ error = error2;
72220+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
72221+ }
72222+ break;
72223+ case GR_OLDRELOAD:
72224+ oldmode = 1;
72225+ case GR_RELOAD:
72226+ if (!gr_acl_is_enabled()) {
72227+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
72228+ error = -EAGAIN;
72229+ } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72230+ error2 = gracl_reload(&gr_usermode, oldmode);
72231+ if (!error2)
72232+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
72233+ else {
72234+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72235+ error = error2;
72236+ }
72237+ } else {
72238+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72239+ error = -EPERM;
72240+ }
72241+ break;
72242+ case GR_SEGVMOD:
72243+ if (unlikely(!gr_acl_is_enabled())) {
72244+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
72245+ error = -EAGAIN;
72246+ break;
72247+ }
72248+
72249+ if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72250+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
72251+ if (gr_usermode.segv_device && gr_usermode.segv_inode) {
72252+ struct acl_subject_label *segvacl;
72253+ segvacl =
72254+ lookup_acl_subj_label(gr_usermode.segv_inode,
72255+ gr_usermode.segv_device,
72256+ current->role);
72257+ if (segvacl) {
72258+ segvacl->crashes = 0;
72259+ segvacl->expires = 0;
72260+ }
72261+ } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
72262+ gr_remove_uid(gr_usermode.segv_uid);
72263+ }
72264+ } else {
72265+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
72266+ error = -EPERM;
72267+ }
72268+ break;
72269+ case GR_SPROLE:
72270+ case GR_SPROLEPAM:
72271+ if (unlikely(!gr_acl_is_enabled())) {
72272+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
72273+ error = -EAGAIN;
72274+ break;
72275+ }
72276+
72277+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
72278+ current->role->expires = 0;
72279+ current->role->auth_attempts = 0;
72280+ }
72281+
72282+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72283+ time_after(current->role->expires, get_seconds())) {
72284+ error = -EBUSY;
72285+ goto out;
72286+ }
72287+
72288+ if (lookup_special_role_auth
72289+ (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
72290+ && ((!sprole_salt && !sprole_sum)
72291+ || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
72292+ char *p = "";
72293+ assign_special_role(gr_usermode.sp_role);
72294+ read_lock(&tasklist_lock);
72295+ if (current->real_parent)
72296+ p = current->real_parent->role->rolename;
72297+ read_unlock(&tasklist_lock);
72298+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
72299+ p, acl_sp_role_value);
72300+ } else {
72301+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
72302+ error = -EPERM;
72303+ if(!(current->role->auth_attempts++))
72304+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72305+
72306+ goto out;
72307+ }
72308+ break;
72309+ case GR_UNSPROLE:
72310+ if (unlikely(!gr_acl_is_enabled())) {
72311+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
72312+ error = -EAGAIN;
72313+ break;
72314+ }
72315+
72316+ if (current->role->roletype & GR_ROLE_SPECIAL) {
72317+ char *p = "";
72318+ int i = 0;
72319+
72320+ read_lock(&tasklist_lock);
72321+ if (current->real_parent) {
72322+ p = current->real_parent->role->rolename;
72323+ i = current->real_parent->acl_role_id;
72324+ }
72325+ read_unlock(&tasklist_lock);
72326+
72327+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
72328+ gr_set_acls(1);
72329+ } else {
72330+ error = -EPERM;
72331+ goto out;
72332+ }
72333+ break;
72334+ default:
72335+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
72336+ error = -EINVAL;
72337+ break;
72338+ }
72339+
72340+ if (error != -EPERM)
72341+ goto out;
72342+
72343+ if(!(gr_auth_attempts++))
72344+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72345+
72346+ out:
72347+ mutex_unlock(&gr_dev_mutex);
72348+
72349+ if (!error)
72350+ error = req_count;
72351+
72352+ return error;
72353+}
72354+
72355+int
72356+gr_set_acls(const int type)
72357+{
72358+ struct task_struct *task, *task2;
72359+ struct acl_role_label *role = current->role;
72360+ struct acl_subject_label *subj;
72361+ __u16 acl_role_id = current->acl_role_id;
72362+ const struct cred *cred;
72363+ int ret;
72364+
72365+ rcu_read_lock();
72366+ read_lock(&tasklist_lock);
72367+ read_lock(&grsec_exec_file_lock);
72368+ do_each_thread(task2, task) {
72369+ /* check to see if we're called from the exit handler,
72370+ if so, only replace ACLs that have inherited the admin
72371+ ACL */
72372+
72373+ if (type && (task->role != role ||
72374+ task->acl_role_id != acl_role_id))
72375+ continue;
72376+
72377+ task->acl_role_id = 0;
72378+ task->acl_sp_role = 0;
72379+ task->inherited = 0;
72380+
72381+ if (task->exec_file) {
72382+ cred = __task_cred(task);
72383+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72384+ subj = __gr_get_subject_for_task(polstate, task, NULL);
72385+ if (subj == NULL) {
72386+ ret = -EINVAL;
72387+ read_unlock(&grsec_exec_file_lock);
72388+ read_unlock(&tasklist_lock);
72389+ rcu_read_unlock();
72390+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
72391+ return ret;
72392+ }
72393+ __gr_apply_subject_to_task(polstate, task, subj);
72394+ } else {
72395+ // it's a kernel process
72396+ task->role = polstate->kernel_role;
72397+ task->acl = polstate->kernel_role->root_label;
72398+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72399+ task->acl->mode &= ~GR_PROCFIND;
72400+#endif
72401+ }
72402+ } while_each_thread(task2, task);
72403+ read_unlock(&grsec_exec_file_lock);
72404+ read_unlock(&tasklist_lock);
72405+ rcu_read_unlock();
72406+
72407+ return 0;
72408+}
72409diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
72410new file mode 100644
72411index 0000000..39645c9
72412--- /dev/null
72413+++ b/grsecurity/gracl_res.c
72414@@ -0,0 +1,68 @@
72415+#include <linux/kernel.h>
72416+#include <linux/sched.h>
72417+#include <linux/gracl.h>
72418+#include <linux/grinternal.h>
72419+
72420+static const char *restab_log[] = {
72421+ [RLIMIT_CPU] = "RLIMIT_CPU",
72422+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
72423+ [RLIMIT_DATA] = "RLIMIT_DATA",
72424+ [RLIMIT_STACK] = "RLIMIT_STACK",
72425+ [RLIMIT_CORE] = "RLIMIT_CORE",
72426+ [RLIMIT_RSS] = "RLIMIT_RSS",
72427+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
72428+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
72429+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
72430+ [RLIMIT_AS] = "RLIMIT_AS",
72431+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
72432+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
72433+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
72434+ [RLIMIT_NICE] = "RLIMIT_NICE",
72435+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
72436+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
72437+ [GR_CRASH_RES] = "RLIMIT_CRASH"
72438+};
72439+
72440+void
72441+gr_log_resource(const struct task_struct *task,
72442+ const int res, const unsigned long wanted, const int gt)
72443+{
72444+ const struct cred *cred;
72445+ unsigned long rlim;
72446+
72447+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
72448+ return;
72449+
72450+ // not yet supported resource
72451+ if (unlikely(!restab_log[res]))
72452+ return;
72453+
72454+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
72455+ rlim = task_rlimit_max(task, res);
72456+ else
72457+ rlim = task_rlimit(task, res);
72458+
72459+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
72460+ return;
72461+
72462+ rcu_read_lock();
72463+ cred = __task_cred(task);
72464+
72465+ if (res == RLIMIT_NPROC &&
72466+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
72467+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
72468+ goto out_rcu_unlock;
72469+ else if (res == RLIMIT_MEMLOCK &&
72470+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
72471+ goto out_rcu_unlock;
72472+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
72473+ goto out_rcu_unlock;
72474+ rcu_read_unlock();
72475+
72476+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
72477+
72478+ return;
72479+out_rcu_unlock:
72480+ rcu_read_unlock();
72481+ return;
72482+}
72483diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
72484new file mode 100644
72485index 0000000..2040e61
72486--- /dev/null
72487+++ b/grsecurity/gracl_segv.c
72488@@ -0,0 +1,313 @@
72489+#include <linux/kernel.h>
72490+#include <linux/mm.h>
72491+#include <asm/uaccess.h>
72492+#include <asm/errno.h>
72493+#include <asm/mman.h>
72494+#include <net/sock.h>
72495+#include <linux/file.h>
72496+#include <linux/fs.h>
72497+#include <linux/net.h>
72498+#include <linux/in.h>
72499+#include <linux/slab.h>
72500+#include <linux/types.h>
72501+#include <linux/sched.h>
72502+#include <linux/timer.h>
72503+#include <linux/gracl.h>
72504+#include <linux/grsecurity.h>
72505+#include <linux/grinternal.h>
72506+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72507+#include <linux/magic.h>
72508+#include <linux/pagemap.h>
72509+#include "../fs/btrfs/async-thread.h"
72510+#include "../fs/btrfs/ctree.h"
72511+#include "../fs/btrfs/btrfs_inode.h"
72512+#endif
72513+
72514+static struct crash_uid *uid_set;
72515+static unsigned short uid_used;
72516+static DEFINE_SPINLOCK(gr_uid_lock);
72517+extern rwlock_t gr_inode_lock;
72518+extern struct acl_subject_label *
72519+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
72520+ struct acl_role_label *role);
72521+
72522+static inline dev_t __get_dev(const struct dentry *dentry)
72523+{
72524+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72525+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
72526+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
72527+ else
72528+#endif
72529+ return dentry->d_sb->s_dev;
72530+}
72531+
72532+int
72533+gr_init_uidset(void)
72534+{
72535+ uid_set =
72536+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
72537+ uid_used = 0;
72538+
72539+ return uid_set ? 1 : 0;
72540+}
72541+
72542+void
72543+gr_free_uidset(void)
72544+{
72545+ if (uid_set) {
72546+ struct crash_uid *tmpset;
72547+ spin_lock(&gr_uid_lock);
72548+ tmpset = uid_set;
72549+ uid_set = NULL;
72550+ uid_used = 0;
72551+ spin_unlock(&gr_uid_lock);
72552+ if (tmpset)
72553+ kfree(tmpset);
72554+ }
72555+
72556+ return;
72557+}
72558+
72559+int
72560+gr_find_uid(const uid_t uid)
72561+{
72562+ struct crash_uid *tmp = uid_set;
72563+ uid_t buid;
72564+ int low = 0, high = uid_used - 1, mid;
72565+
72566+ while (high >= low) {
72567+ mid = (low + high) >> 1;
72568+ buid = tmp[mid].uid;
72569+ if (buid == uid)
72570+ return mid;
72571+ if (buid > uid)
72572+ high = mid - 1;
72573+ if (buid < uid)
72574+ low = mid + 1;
72575+ }
72576+
72577+ return -1;
72578+}
72579+
72580+static __inline__ void
72581+gr_insertsort(void)
72582+{
72583+ unsigned short i, j;
72584+ struct crash_uid index;
72585+
72586+ for (i = 1; i < uid_used; i++) {
72587+ index = uid_set[i];
72588+ j = i;
72589+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
72590+ uid_set[j] = uid_set[j - 1];
72591+ j--;
72592+ }
72593+ uid_set[j] = index;
72594+ }
72595+
72596+ return;
72597+}
72598+
72599+static __inline__ void
72600+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
72601+{
72602+ int loc;
72603+ uid_t uid = GR_GLOBAL_UID(kuid);
72604+
72605+ if (uid_used == GR_UIDTABLE_MAX)
72606+ return;
72607+
72608+ loc = gr_find_uid(uid);
72609+
72610+ if (loc >= 0) {
72611+ uid_set[loc].expires = expires;
72612+ return;
72613+ }
72614+
72615+ uid_set[uid_used].uid = uid;
72616+ uid_set[uid_used].expires = expires;
72617+ uid_used++;
72618+
72619+ gr_insertsort();
72620+
72621+ return;
72622+}
72623+
72624+void
72625+gr_remove_uid(const unsigned short loc)
72626+{
72627+ unsigned short i;
72628+
72629+ for (i = loc + 1; i < uid_used; i++)
72630+ uid_set[i - 1] = uid_set[i];
72631+
72632+ uid_used--;
72633+
72634+ return;
72635+}
72636+
72637+int
72638+gr_check_crash_uid(const kuid_t kuid)
72639+{
72640+ int loc;
72641+ int ret = 0;
72642+ uid_t uid;
72643+
72644+ if (unlikely(!gr_acl_is_enabled()))
72645+ return 0;
72646+
72647+ uid = GR_GLOBAL_UID(kuid);
72648+
72649+ spin_lock(&gr_uid_lock);
72650+ loc = gr_find_uid(uid);
72651+
72652+ if (loc < 0)
72653+ goto out_unlock;
72654+
72655+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
72656+ gr_remove_uid(loc);
72657+ else
72658+ ret = 1;
72659+
72660+out_unlock:
72661+ spin_unlock(&gr_uid_lock);
72662+ return ret;
72663+}
72664+
72665+static __inline__ int
72666+proc_is_setxid(const struct cred *cred)
72667+{
72668+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
72669+ !uid_eq(cred->uid, cred->fsuid))
72670+ return 1;
72671+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
72672+ !gid_eq(cred->gid, cred->fsgid))
72673+ return 1;
72674+
72675+ return 0;
72676+}
72677+
72678+extern int gr_fake_force_sig(int sig, struct task_struct *t);
72679+
72680+void
72681+gr_handle_crash(struct task_struct *task, const int sig)
72682+{
72683+ struct acl_subject_label *curr;
72684+ struct task_struct *tsk, *tsk2;
72685+ const struct cred *cred;
72686+ const struct cred *cred2;
72687+
72688+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
72689+ return;
72690+
72691+ if (unlikely(!gr_acl_is_enabled()))
72692+ return;
72693+
72694+ curr = task->acl;
72695+
72696+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
72697+ return;
72698+
72699+ if (time_before_eq(curr->expires, get_seconds())) {
72700+ curr->expires = 0;
72701+ curr->crashes = 0;
72702+ }
72703+
72704+ curr->crashes++;
72705+
72706+ if (!curr->expires)
72707+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
72708+
72709+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
72710+ time_after(curr->expires, get_seconds())) {
72711+ rcu_read_lock();
72712+ cred = __task_cred(task);
72713+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
72714+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
72715+ spin_lock(&gr_uid_lock);
72716+ gr_insert_uid(cred->uid, curr->expires);
72717+ spin_unlock(&gr_uid_lock);
72718+ curr->expires = 0;
72719+ curr->crashes = 0;
72720+ read_lock(&tasklist_lock);
72721+ do_each_thread(tsk2, tsk) {
72722+ cred2 = __task_cred(tsk);
72723+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
72724+ gr_fake_force_sig(SIGKILL, tsk);
72725+ } while_each_thread(tsk2, tsk);
72726+ read_unlock(&tasklist_lock);
72727+ } else {
72728+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
72729+ read_lock(&tasklist_lock);
72730+ read_lock(&grsec_exec_file_lock);
72731+ do_each_thread(tsk2, tsk) {
72732+ if (likely(tsk != task)) {
72733+ // if this thread has the same subject as the one that triggered
72734+ // RES_CRASH and it's the same binary, kill it
72735+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
72736+ gr_fake_force_sig(SIGKILL, tsk);
72737+ }
72738+ } while_each_thread(tsk2, tsk);
72739+ read_unlock(&grsec_exec_file_lock);
72740+ read_unlock(&tasklist_lock);
72741+ }
72742+ rcu_read_unlock();
72743+ }
72744+
72745+ return;
72746+}
72747+
72748+int
72749+gr_check_crash_exec(const struct file *filp)
72750+{
72751+ struct acl_subject_label *curr;
72752+
72753+ if (unlikely(!gr_acl_is_enabled()))
72754+ return 0;
72755+
72756+ read_lock(&gr_inode_lock);
72757+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
72758+ __get_dev(filp->f_path.dentry),
72759+ current->role);
72760+ read_unlock(&gr_inode_lock);
72761+
72762+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
72763+ (!curr->crashes && !curr->expires))
72764+ return 0;
72765+
72766+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
72767+ time_after(curr->expires, get_seconds()))
72768+ return 1;
72769+ else if (time_before_eq(curr->expires, get_seconds())) {
72770+ curr->crashes = 0;
72771+ curr->expires = 0;
72772+ }
72773+
72774+ return 0;
72775+}
72776+
72777+void
72778+gr_handle_alertkill(struct task_struct *task)
72779+{
72780+ struct acl_subject_label *curracl;
72781+ __u32 curr_ip;
72782+ struct task_struct *p, *p2;
72783+
72784+ if (unlikely(!gr_acl_is_enabled()))
72785+ return;
72786+
72787+ curracl = task->acl;
72788+ curr_ip = task->signal->curr_ip;
72789+
72790+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
72791+ read_lock(&tasklist_lock);
72792+ do_each_thread(p2, p) {
72793+ if (p->signal->curr_ip == curr_ip)
72794+ gr_fake_force_sig(SIGKILL, p);
72795+ } while_each_thread(p2, p);
72796+ read_unlock(&tasklist_lock);
72797+ } else if (curracl->mode & GR_KILLPROC)
72798+ gr_fake_force_sig(SIGKILL, task);
72799+
72800+ return;
72801+}
72802diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
72803new file mode 100644
72804index 0000000..98011b0
72805--- /dev/null
72806+++ b/grsecurity/gracl_shm.c
72807@@ -0,0 +1,40 @@
72808+#include <linux/kernel.h>
72809+#include <linux/mm.h>
72810+#include <linux/sched.h>
72811+#include <linux/file.h>
72812+#include <linux/ipc.h>
72813+#include <linux/gracl.h>
72814+#include <linux/grsecurity.h>
72815+#include <linux/grinternal.h>
72816+
72817+int
72818+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72819+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
72820+{
72821+ struct task_struct *task;
72822+
72823+ if (!gr_acl_is_enabled())
72824+ return 1;
72825+
72826+ rcu_read_lock();
72827+ read_lock(&tasklist_lock);
72828+
72829+ task = find_task_by_vpid(shm_cprid);
72830+
72831+ if (unlikely(!task))
72832+ task = find_task_by_vpid(shm_lapid);
72833+
72834+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
72835+ (task_pid_nr(task) == shm_lapid)) &&
72836+ (task->acl->mode & GR_PROTSHM) &&
72837+ (task->acl != current->acl))) {
72838+ read_unlock(&tasklist_lock);
72839+ rcu_read_unlock();
72840+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
72841+ return 0;
72842+ }
72843+ read_unlock(&tasklist_lock);
72844+ rcu_read_unlock();
72845+
72846+ return 1;
72847+}
72848diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
72849new file mode 100644
72850index 0000000..bc0be01
72851--- /dev/null
72852+++ b/grsecurity/grsec_chdir.c
72853@@ -0,0 +1,19 @@
72854+#include <linux/kernel.h>
72855+#include <linux/sched.h>
72856+#include <linux/fs.h>
72857+#include <linux/file.h>
72858+#include <linux/grsecurity.h>
72859+#include <linux/grinternal.h>
72860+
72861+void
72862+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
72863+{
72864+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
72865+ if ((grsec_enable_chdir && grsec_enable_group &&
72866+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
72867+ !grsec_enable_group)) {
72868+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
72869+ }
72870+#endif
72871+ return;
72872+}
72873diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
72874new file mode 100644
72875index 0000000..651d6c2
72876--- /dev/null
72877+++ b/grsecurity/grsec_chroot.c
72878@@ -0,0 +1,370 @@
72879+#include <linux/kernel.h>
72880+#include <linux/module.h>
72881+#include <linux/sched.h>
72882+#include <linux/file.h>
72883+#include <linux/fs.h>
72884+#include <linux/mount.h>
72885+#include <linux/types.h>
72886+#include "../fs/mount.h"
72887+#include <linux/grsecurity.h>
72888+#include <linux/grinternal.h>
72889+
72890+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
72891+int gr_init_ran;
72892+#endif
72893+
72894+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
72895+{
72896+#ifdef CONFIG_GRKERNSEC
72897+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
72898+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
72899+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
72900+ && gr_init_ran
72901+#endif
72902+ )
72903+ task->gr_is_chrooted = 1;
72904+ else {
72905+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
72906+ if (task_pid_nr(task) == 1 && !gr_init_ran)
72907+ gr_init_ran = 1;
72908+#endif
72909+ task->gr_is_chrooted = 0;
72910+ }
72911+
72912+ task->gr_chroot_dentry = path->dentry;
72913+#endif
72914+ return;
72915+}
72916+
72917+void gr_clear_chroot_entries(struct task_struct *task)
72918+{
72919+#ifdef CONFIG_GRKERNSEC
72920+ task->gr_is_chrooted = 0;
72921+ task->gr_chroot_dentry = NULL;
72922+#endif
72923+ return;
72924+}
72925+
72926+int
72927+gr_handle_chroot_unix(const pid_t pid)
72928+{
72929+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
72930+ struct task_struct *p;
72931+
72932+ if (unlikely(!grsec_enable_chroot_unix))
72933+ return 1;
72934+
72935+ if (likely(!proc_is_chrooted(current)))
72936+ return 1;
72937+
72938+ rcu_read_lock();
72939+ read_lock(&tasklist_lock);
72940+ p = find_task_by_vpid_unrestricted(pid);
72941+ if (unlikely(p && !have_same_root(current, p))) {
72942+ read_unlock(&tasklist_lock);
72943+ rcu_read_unlock();
72944+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
72945+ return 0;
72946+ }
72947+ read_unlock(&tasklist_lock);
72948+ rcu_read_unlock();
72949+#endif
72950+ return 1;
72951+}
72952+
72953+int
72954+gr_handle_chroot_nice(void)
72955+{
72956+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
72957+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
72958+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
72959+ return -EPERM;
72960+ }
72961+#endif
72962+ return 0;
72963+}
72964+
72965+int
72966+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
72967+{
72968+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
72969+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
72970+ && proc_is_chrooted(current)) {
72971+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
72972+ return -EACCES;
72973+ }
72974+#endif
72975+ return 0;
72976+}
72977+
72978+int
72979+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
72980+{
72981+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72982+ struct task_struct *p;
72983+ int ret = 0;
72984+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
72985+ return ret;
72986+
72987+ read_lock(&tasklist_lock);
72988+ do_each_pid_task(pid, type, p) {
72989+ if (!have_same_root(current, p)) {
72990+ ret = 1;
72991+ goto out;
72992+ }
72993+ } while_each_pid_task(pid, type, p);
72994+out:
72995+ read_unlock(&tasklist_lock);
72996+ return ret;
72997+#endif
72998+ return 0;
72999+}
73000+
73001+int
73002+gr_pid_is_chrooted(struct task_struct *p)
73003+{
73004+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73005+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
73006+ return 0;
73007+
73008+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
73009+ !have_same_root(current, p)) {
73010+ return 1;
73011+ }
73012+#endif
73013+ return 0;
73014+}
73015+
73016+EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
73017+
73018+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
73019+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
73020+{
73021+ struct path path, currentroot;
73022+ int ret = 0;
73023+
73024+ path.dentry = (struct dentry *)u_dentry;
73025+ path.mnt = (struct vfsmount *)u_mnt;
73026+ get_fs_root(current->fs, &currentroot);
73027+ if (path_is_under(&path, &currentroot))
73028+ ret = 1;
73029+ path_put(&currentroot);
73030+
73031+ return ret;
73032+}
73033+#endif
73034+
73035+int
73036+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
73037+{
73038+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73039+ if (!grsec_enable_chroot_fchdir)
73040+ return 1;
73041+
73042+ if (!proc_is_chrooted(current))
73043+ return 1;
73044+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
73045+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
73046+ return 0;
73047+ }
73048+#endif
73049+ return 1;
73050+}
73051+
73052+int
73053+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73054+ const time_t shm_createtime)
73055+{
73056+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73057+ struct task_struct *p;
73058+ time_t starttime;
73059+
73060+ if (unlikely(!grsec_enable_chroot_shmat))
73061+ return 1;
73062+
73063+ if (likely(!proc_is_chrooted(current)))
73064+ return 1;
73065+
73066+ rcu_read_lock();
73067+ read_lock(&tasklist_lock);
73068+
73069+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
73070+ starttime = p->start_time.tv_sec;
73071+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
73072+ if (have_same_root(current, p)) {
73073+ goto allow;
73074+ } else {
73075+ read_unlock(&tasklist_lock);
73076+ rcu_read_unlock();
73077+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73078+ return 0;
73079+ }
73080+ }
73081+ /* creator exited, pid reuse, fall through to next check */
73082+ }
73083+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
73084+ if (unlikely(!have_same_root(current, p))) {
73085+ read_unlock(&tasklist_lock);
73086+ rcu_read_unlock();
73087+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73088+ return 0;
73089+ }
73090+ }
73091+
73092+allow:
73093+ read_unlock(&tasklist_lock);
73094+ rcu_read_unlock();
73095+#endif
73096+ return 1;
73097+}
73098+
73099+void
73100+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
73101+{
73102+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73103+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
73104+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
73105+#endif
73106+ return;
73107+}
73108+
73109+int
73110+gr_handle_chroot_mknod(const struct dentry *dentry,
73111+ const struct vfsmount *mnt, const int mode)
73112+{
73113+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73114+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
73115+ proc_is_chrooted(current)) {
73116+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
73117+ return -EPERM;
73118+ }
73119+#endif
73120+ return 0;
73121+}
73122+
73123+int
73124+gr_handle_chroot_mount(const struct dentry *dentry,
73125+ const struct vfsmount *mnt, const char *dev_name)
73126+{
73127+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73128+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
73129+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
73130+ return -EPERM;
73131+ }
73132+#endif
73133+ return 0;
73134+}
73135+
73136+int
73137+gr_handle_chroot_pivot(void)
73138+{
73139+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73140+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
73141+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
73142+ return -EPERM;
73143+ }
73144+#endif
73145+ return 0;
73146+}
73147+
73148+int
73149+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
73150+{
73151+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73152+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
73153+ !gr_is_outside_chroot(dentry, mnt)) {
73154+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
73155+ return -EPERM;
73156+ }
73157+#endif
73158+ return 0;
73159+}
73160+
73161+extern const char *captab_log[];
73162+extern int captab_log_entries;
73163+
73164+int
73165+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73166+{
73167+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73168+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73169+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73170+ if (cap_raised(chroot_caps, cap)) {
73171+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
73172+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
73173+ }
73174+ return 0;
73175+ }
73176+ }
73177+#endif
73178+ return 1;
73179+}
73180+
73181+int
73182+gr_chroot_is_capable(const int cap)
73183+{
73184+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73185+ return gr_task_chroot_is_capable(current, current_cred(), cap);
73186+#endif
73187+ return 1;
73188+}
73189+
73190+int
73191+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
73192+{
73193+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73194+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73195+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73196+ if (cap_raised(chroot_caps, cap)) {
73197+ return 0;
73198+ }
73199+ }
73200+#endif
73201+ return 1;
73202+}
73203+
73204+int
73205+gr_chroot_is_capable_nolog(const int cap)
73206+{
73207+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73208+ return gr_task_chroot_is_capable_nolog(current, cap);
73209+#endif
73210+ return 1;
73211+}
73212+
73213+int
73214+gr_handle_chroot_sysctl(const int op)
73215+{
73216+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
73217+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
73218+ proc_is_chrooted(current))
73219+ return -EACCES;
73220+#endif
73221+ return 0;
73222+}
73223+
73224+void
73225+gr_handle_chroot_chdir(const struct path *path)
73226+{
73227+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
73228+ if (grsec_enable_chroot_chdir)
73229+ set_fs_pwd(current->fs, path);
73230+#endif
73231+ return;
73232+}
73233+
73234+int
73235+gr_handle_chroot_chmod(const struct dentry *dentry,
73236+ const struct vfsmount *mnt, const int mode)
73237+{
73238+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73239+ /* allow chmod +s on directories, but not files */
73240+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
73241+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
73242+ proc_is_chrooted(current)) {
73243+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
73244+ return -EPERM;
73245+ }
73246+#endif
73247+ return 0;
73248+}
73249diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
73250new file mode 100644
73251index 0000000..4d6fce8
73252--- /dev/null
73253+++ b/grsecurity/grsec_disabled.c
73254@@ -0,0 +1,433 @@
73255+#include <linux/kernel.h>
73256+#include <linux/module.h>
73257+#include <linux/sched.h>
73258+#include <linux/file.h>
73259+#include <linux/fs.h>
73260+#include <linux/kdev_t.h>
73261+#include <linux/net.h>
73262+#include <linux/in.h>
73263+#include <linux/ip.h>
73264+#include <linux/skbuff.h>
73265+#include <linux/sysctl.h>
73266+
73267+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
73268+void
73269+pax_set_initial_flags(struct linux_binprm *bprm)
73270+{
73271+ return;
73272+}
73273+#endif
73274+
73275+#ifdef CONFIG_SYSCTL
73276+__u32
73277+gr_handle_sysctl(const struct ctl_table * table, const int op)
73278+{
73279+ return 0;
73280+}
73281+#endif
73282+
73283+#ifdef CONFIG_TASKSTATS
73284+int gr_is_taskstats_denied(int pid)
73285+{
73286+ return 0;
73287+}
73288+#endif
73289+
73290+int
73291+gr_acl_is_enabled(void)
73292+{
73293+ return 0;
73294+}
73295+
73296+void
73297+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
73298+{
73299+ return;
73300+}
73301+
73302+int
73303+gr_handle_rawio(const struct inode *inode)
73304+{
73305+ return 0;
73306+}
73307+
73308+void
73309+gr_acl_handle_psacct(struct task_struct *task, const long code)
73310+{
73311+ return;
73312+}
73313+
73314+int
73315+gr_handle_ptrace(struct task_struct *task, const long request)
73316+{
73317+ return 0;
73318+}
73319+
73320+int
73321+gr_handle_proc_ptrace(struct task_struct *task)
73322+{
73323+ return 0;
73324+}
73325+
73326+int
73327+gr_set_acls(const int type)
73328+{
73329+ return 0;
73330+}
73331+
73332+int
73333+gr_check_hidden_task(const struct task_struct *tsk)
73334+{
73335+ return 0;
73336+}
73337+
73338+int
73339+gr_check_protected_task(const struct task_struct *task)
73340+{
73341+ return 0;
73342+}
73343+
73344+int
73345+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
73346+{
73347+ return 0;
73348+}
73349+
73350+void
73351+gr_copy_label(struct task_struct *tsk)
73352+{
73353+ return;
73354+}
73355+
73356+void
73357+gr_set_pax_flags(struct task_struct *task)
73358+{
73359+ return;
73360+}
73361+
73362+int
73363+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
73364+ const int unsafe_share)
73365+{
73366+ return 0;
73367+}
73368+
73369+void
73370+gr_handle_delete(const ino_t ino, const dev_t dev)
73371+{
73372+ return;
73373+}
73374+
73375+void
73376+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
73377+{
73378+ return;
73379+}
73380+
73381+void
73382+gr_handle_crash(struct task_struct *task, const int sig)
73383+{
73384+ return;
73385+}
73386+
73387+int
73388+gr_check_crash_exec(const struct file *filp)
73389+{
73390+ return 0;
73391+}
73392+
73393+int
73394+gr_check_crash_uid(const kuid_t uid)
73395+{
73396+ return 0;
73397+}
73398+
73399+void
73400+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
73401+ struct dentry *old_dentry,
73402+ struct dentry *new_dentry,
73403+ struct vfsmount *mnt, const __u8 replace)
73404+{
73405+ return;
73406+}
73407+
73408+int
73409+gr_search_socket(const int family, const int type, const int protocol)
73410+{
73411+ return 1;
73412+}
73413+
73414+int
73415+gr_search_connectbind(const int mode, const struct socket *sock,
73416+ const struct sockaddr_in *addr)
73417+{
73418+ return 0;
73419+}
73420+
73421+void
73422+gr_handle_alertkill(struct task_struct *task)
73423+{
73424+ return;
73425+}
73426+
73427+__u32
73428+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
73429+{
73430+ return 1;
73431+}
73432+
73433+__u32
73434+gr_acl_handle_hidden_file(const struct dentry * dentry,
73435+ const struct vfsmount * mnt)
73436+{
73437+ return 1;
73438+}
73439+
73440+__u32
73441+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
73442+ int acc_mode)
73443+{
73444+ return 1;
73445+}
73446+
73447+__u32
73448+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
73449+{
73450+ return 1;
73451+}
73452+
73453+__u32
73454+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
73455+{
73456+ return 1;
73457+}
73458+
73459+int
73460+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
73461+ unsigned int *vm_flags)
73462+{
73463+ return 1;
73464+}
73465+
73466+__u32
73467+gr_acl_handle_truncate(const struct dentry * dentry,
73468+ const struct vfsmount * mnt)
73469+{
73470+ return 1;
73471+}
73472+
73473+__u32
73474+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
73475+{
73476+ return 1;
73477+}
73478+
73479+__u32
73480+gr_acl_handle_access(const struct dentry * dentry,
73481+ const struct vfsmount * mnt, const int fmode)
73482+{
73483+ return 1;
73484+}
73485+
73486+__u32
73487+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
73488+ umode_t *mode)
73489+{
73490+ return 1;
73491+}
73492+
73493+__u32
73494+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
73495+{
73496+ return 1;
73497+}
73498+
73499+__u32
73500+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
73501+{
73502+ return 1;
73503+}
73504+
73505+__u32
73506+gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
73507+{
73508+ return 1;
73509+}
73510+
73511+void
73512+grsecurity_init(void)
73513+{
73514+ return;
73515+}
73516+
73517+umode_t gr_acl_umask(void)
73518+{
73519+ return 0;
73520+}
73521+
73522+__u32
73523+gr_acl_handle_mknod(const struct dentry * new_dentry,
73524+ const struct dentry * parent_dentry,
73525+ const struct vfsmount * parent_mnt,
73526+ const int mode)
73527+{
73528+ return 1;
73529+}
73530+
73531+__u32
73532+gr_acl_handle_mkdir(const struct dentry * new_dentry,
73533+ const struct dentry * parent_dentry,
73534+ const struct vfsmount * parent_mnt)
73535+{
73536+ return 1;
73537+}
73538+
73539+__u32
73540+gr_acl_handle_symlink(const struct dentry * new_dentry,
73541+ const struct dentry * parent_dentry,
73542+ const struct vfsmount * parent_mnt, const struct filename *from)
73543+{
73544+ return 1;
73545+}
73546+
73547+__u32
73548+gr_acl_handle_link(const struct dentry * new_dentry,
73549+ const struct dentry * parent_dentry,
73550+ const struct vfsmount * parent_mnt,
73551+ const struct dentry * old_dentry,
73552+ const struct vfsmount * old_mnt, const struct filename *to)
73553+{
73554+ return 1;
73555+}
73556+
73557+int
73558+gr_acl_handle_rename(const struct dentry *new_dentry,
73559+ const struct dentry *parent_dentry,
73560+ const struct vfsmount *parent_mnt,
73561+ const struct dentry *old_dentry,
73562+ const struct inode *old_parent_inode,
73563+ const struct vfsmount *old_mnt, const struct filename *newname)
73564+{
73565+ return 0;
73566+}
73567+
73568+int
73569+gr_acl_handle_filldir(const struct file *file, const char *name,
73570+ const int namelen, const ino_t ino)
73571+{
73572+ return 1;
73573+}
73574+
73575+int
73576+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73577+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
73578+{
73579+ return 1;
73580+}
73581+
73582+int
73583+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
73584+{
73585+ return 0;
73586+}
73587+
73588+int
73589+gr_search_accept(const struct socket *sock)
73590+{
73591+ return 0;
73592+}
73593+
73594+int
73595+gr_search_listen(const struct socket *sock)
73596+{
73597+ return 0;
73598+}
73599+
73600+int
73601+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
73602+{
73603+ return 0;
73604+}
73605+
73606+__u32
73607+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
73608+{
73609+ return 1;
73610+}
73611+
73612+__u32
73613+gr_acl_handle_creat(const struct dentry * dentry,
73614+ const struct dentry * p_dentry,
73615+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
73616+ const int imode)
73617+{
73618+ return 1;
73619+}
73620+
73621+void
73622+gr_acl_handle_exit(void)
73623+{
73624+ return;
73625+}
73626+
73627+int
73628+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
73629+{
73630+ return 1;
73631+}
73632+
73633+void
73634+gr_set_role_label(const kuid_t uid, const kgid_t gid)
73635+{
73636+ return;
73637+}
73638+
73639+int
73640+gr_acl_handle_procpidmem(const struct task_struct *task)
73641+{
73642+ return 0;
73643+}
73644+
73645+int
73646+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
73647+{
73648+ return 0;
73649+}
73650+
73651+int
73652+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
73653+{
73654+ return 0;
73655+}
73656+
73657+int
73658+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
73659+{
73660+ return 0;
73661+}
73662+
73663+int
73664+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
73665+{
73666+ return 0;
73667+}
73668+
73669+int gr_acl_enable_at_secure(void)
73670+{
73671+ return 0;
73672+}
73673+
73674+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
73675+{
73676+ return dentry->d_sb->s_dev;
73677+}
73678+
73679+void gr_put_exec_file(struct task_struct *task)
73680+{
73681+ return;
73682+}
73683+
73684+#ifdef CONFIG_SECURITY
73685+EXPORT_SYMBOL_GPL(gr_check_user_change);
73686+EXPORT_SYMBOL_GPL(gr_check_group_change);
73687+#endif
73688diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
73689new file mode 100644
73690index 0000000..f35f454
73691--- /dev/null
73692+++ b/grsecurity/grsec_exec.c
73693@@ -0,0 +1,187 @@
73694+#include <linux/kernel.h>
73695+#include <linux/sched.h>
73696+#include <linux/file.h>
73697+#include <linux/binfmts.h>
73698+#include <linux/fs.h>
73699+#include <linux/types.h>
73700+#include <linux/grdefs.h>
73701+#include <linux/grsecurity.h>
73702+#include <linux/grinternal.h>
73703+#include <linux/capability.h>
73704+#include <linux/module.h>
73705+#include <linux/compat.h>
73706+
73707+#include <asm/uaccess.h>
73708+
73709+#ifdef CONFIG_GRKERNSEC_EXECLOG
73710+static char gr_exec_arg_buf[132];
73711+static DEFINE_MUTEX(gr_exec_arg_mutex);
73712+#endif
73713+
73714+struct user_arg_ptr {
73715+#ifdef CONFIG_COMPAT
73716+ bool is_compat;
73717+#endif
73718+ union {
73719+ const char __user *const __user *native;
73720+#ifdef CONFIG_COMPAT
73721+ const compat_uptr_t __user *compat;
73722+#endif
73723+ } ptr;
73724+};
73725+
73726+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
73727+
73728+void
73729+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
73730+{
73731+#ifdef CONFIG_GRKERNSEC_EXECLOG
73732+ char *grarg = gr_exec_arg_buf;
73733+ unsigned int i, x, execlen = 0;
73734+ char c;
73735+
73736+ if (!((grsec_enable_execlog && grsec_enable_group &&
73737+ in_group_p(grsec_audit_gid))
73738+ || (grsec_enable_execlog && !grsec_enable_group)))
73739+ return;
73740+
73741+ mutex_lock(&gr_exec_arg_mutex);
73742+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
73743+
73744+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
73745+ const char __user *p;
73746+ unsigned int len;
73747+
73748+ p = get_user_arg_ptr(argv, i);
73749+ if (IS_ERR(p))
73750+ goto log;
73751+
73752+ len = strnlen_user(p, 128 - execlen);
73753+ if (len > 128 - execlen)
73754+ len = 128 - execlen;
73755+ else if (len > 0)
73756+ len--;
73757+ if (copy_from_user(grarg + execlen, p, len))
73758+ goto log;
73759+
73760+ /* rewrite unprintable characters */
73761+ for (x = 0; x < len; x++) {
73762+ c = *(grarg + execlen + x);
73763+ if (c < 32 || c > 126)
73764+ *(grarg + execlen + x) = ' ';
73765+ }
73766+
73767+ execlen += len;
73768+ *(grarg + execlen) = ' ';
73769+ *(grarg + execlen + 1) = '\0';
73770+ execlen++;
73771+ }
73772+
73773+ log:
73774+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
73775+ bprm->file->f_path.mnt, grarg);
73776+ mutex_unlock(&gr_exec_arg_mutex);
73777+#endif
73778+ return;
73779+}
73780+
73781+#ifdef CONFIG_GRKERNSEC
73782+extern int gr_acl_is_capable(const int cap);
73783+extern int gr_acl_is_capable_nolog(const int cap);
73784+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
73785+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
73786+extern int gr_chroot_is_capable(const int cap);
73787+extern int gr_chroot_is_capable_nolog(const int cap);
73788+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
73789+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
73790+#endif
73791+
73792+const char *captab_log[] = {
73793+ "CAP_CHOWN",
73794+ "CAP_DAC_OVERRIDE",
73795+ "CAP_DAC_READ_SEARCH",
73796+ "CAP_FOWNER",
73797+ "CAP_FSETID",
73798+ "CAP_KILL",
73799+ "CAP_SETGID",
73800+ "CAP_SETUID",
73801+ "CAP_SETPCAP",
73802+ "CAP_LINUX_IMMUTABLE",
73803+ "CAP_NET_BIND_SERVICE",
73804+ "CAP_NET_BROADCAST",
73805+ "CAP_NET_ADMIN",
73806+ "CAP_NET_RAW",
73807+ "CAP_IPC_LOCK",
73808+ "CAP_IPC_OWNER",
73809+ "CAP_SYS_MODULE",
73810+ "CAP_SYS_RAWIO",
73811+ "CAP_SYS_CHROOT",
73812+ "CAP_SYS_PTRACE",
73813+ "CAP_SYS_PACCT",
73814+ "CAP_SYS_ADMIN",
73815+ "CAP_SYS_BOOT",
73816+ "CAP_SYS_NICE",
73817+ "CAP_SYS_RESOURCE",
73818+ "CAP_SYS_TIME",
73819+ "CAP_SYS_TTY_CONFIG",
73820+ "CAP_MKNOD",
73821+ "CAP_LEASE",
73822+ "CAP_AUDIT_WRITE",
73823+ "CAP_AUDIT_CONTROL",
73824+ "CAP_SETFCAP",
73825+ "CAP_MAC_OVERRIDE",
73826+ "CAP_MAC_ADMIN",
73827+ "CAP_SYSLOG",
73828+ "CAP_WAKE_ALARM"
73829+};
73830+
73831+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
73832+
73833+int gr_is_capable(const int cap)
73834+{
73835+#ifdef CONFIG_GRKERNSEC
73836+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
73837+ return 1;
73838+ return 0;
73839+#else
73840+ return 1;
73841+#endif
73842+}
73843+
73844+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73845+{
73846+#ifdef CONFIG_GRKERNSEC
73847+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
73848+ return 1;
73849+ return 0;
73850+#else
73851+ return 1;
73852+#endif
73853+}
73854+
73855+int gr_is_capable_nolog(const int cap)
73856+{
73857+#ifdef CONFIG_GRKERNSEC
73858+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
73859+ return 1;
73860+ return 0;
73861+#else
73862+ return 1;
73863+#endif
73864+}
73865+
73866+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
73867+{
73868+#ifdef CONFIG_GRKERNSEC
73869+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
73870+ return 1;
73871+ return 0;
73872+#else
73873+ return 1;
73874+#endif
73875+}
73876+
73877+EXPORT_SYMBOL_GPL(gr_is_capable);
73878+EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
73879+EXPORT_SYMBOL_GPL(gr_task_is_capable);
73880+EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
73881diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
73882new file mode 100644
73883index 0000000..06cc6ea
73884--- /dev/null
73885+++ b/grsecurity/grsec_fifo.c
73886@@ -0,0 +1,24 @@
73887+#include <linux/kernel.h>
73888+#include <linux/sched.h>
73889+#include <linux/fs.h>
73890+#include <linux/file.h>
73891+#include <linux/grinternal.h>
73892+
73893+int
73894+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
73895+ const struct dentry *dir, const int flag, const int acc_mode)
73896+{
73897+#ifdef CONFIG_GRKERNSEC_FIFO
73898+ const struct cred *cred = current_cred();
73899+
73900+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
73901+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
73902+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
73903+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
73904+ if (!inode_permission(dentry->d_inode, acc_mode))
73905+ 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));
73906+ return -EACCES;
73907+ }
73908+#endif
73909+ return 0;
73910+}
73911diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
73912new file mode 100644
73913index 0000000..8ca18bf
73914--- /dev/null
73915+++ b/grsecurity/grsec_fork.c
73916@@ -0,0 +1,23 @@
73917+#include <linux/kernel.h>
73918+#include <linux/sched.h>
73919+#include <linux/grsecurity.h>
73920+#include <linux/grinternal.h>
73921+#include <linux/errno.h>
73922+
73923+void
73924+gr_log_forkfail(const int retval)
73925+{
73926+#ifdef CONFIG_GRKERNSEC_FORKFAIL
73927+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
73928+ switch (retval) {
73929+ case -EAGAIN:
73930+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
73931+ break;
73932+ case -ENOMEM:
73933+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
73934+ break;
73935+ }
73936+ }
73937+#endif
73938+ return;
73939+}
73940diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
73941new file mode 100644
73942index 0000000..ae6c028
73943--- /dev/null
73944+++ b/grsecurity/grsec_init.c
73945@@ -0,0 +1,272 @@
73946+#include <linux/kernel.h>
73947+#include <linux/sched.h>
73948+#include <linux/mm.h>
73949+#include <linux/gracl.h>
73950+#include <linux/slab.h>
73951+#include <linux/vmalloc.h>
73952+#include <linux/percpu.h>
73953+#include <linux/module.h>
73954+
73955+int grsec_enable_ptrace_readexec;
73956+int grsec_enable_setxid;
73957+int grsec_enable_symlinkown;
73958+kgid_t grsec_symlinkown_gid;
73959+int grsec_enable_brute;
73960+int grsec_enable_link;
73961+int grsec_enable_dmesg;
73962+int grsec_enable_harden_ptrace;
73963+int grsec_enable_harden_ipc;
73964+int grsec_enable_fifo;
73965+int grsec_enable_execlog;
73966+int grsec_enable_signal;
73967+int grsec_enable_forkfail;
73968+int grsec_enable_audit_ptrace;
73969+int grsec_enable_time;
73970+int grsec_enable_group;
73971+kgid_t grsec_audit_gid;
73972+int grsec_enable_chdir;
73973+int grsec_enable_mount;
73974+int grsec_enable_rofs;
73975+int grsec_deny_new_usb;
73976+int grsec_enable_chroot_findtask;
73977+int grsec_enable_chroot_mount;
73978+int grsec_enable_chroot_shmat;
73979+int grsec_enable_chroot_fchdir;
73980+int grsec_enable_chroot_double;
73981+int grsec_enable_chroot_pivot;
73982+int grsec_enable_chroot_chdir;
73983+int grsec_enable_chroot_chmod;
73984+int grsec_enable_chroot_mknod;
73985+int grsec_enable_chroot_nice;
73986+int grsec_enable_chroot_execlog;
73987+int grsec_enable_chroot_caps;
73988+int grsec_enable_chroot_sysctl;
73989+int grsec_enable_chroot_unix;
73990+int grsec_enable_tpe;
73991+kgid_t grsec_tpe_gid;
73992+int grsec_enable_blackhole;
73993+#ifdef CONFIG_IPV6_MODULE
73994+EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
73995+#endif
73996+int grsec_lastack_retries;
73997+int grsec_enable_tpe_all;
73998+int grsec_enable_tpe_invert;
73999+int grsec_enable_socket_all;
74000+kgid_t grsec_socket_all_gid;
74001+int grsec_enable_socket_client;
74002+kgid_t grsec_socket_client_gid;
74003+int grsec_enable_socket_server;
74004+kgid_t grsec_socket_server_gid;
74005+int grsec_resource_logging;
74006+int grsec_disable_privio;
74007+int grsec_enable_log_rwxmaps;
74008+int grsec_lock;
74009+
74010+DEFINE_SPINLOCK(grsec_alert_lock);
74011+unsigned long grsec_alert_wtime = 0;
74012+unsigned long grsec_alert_fyet = 0;
74013+
74014+DEFINE_SPINLOCK(grsec_audit_lock);
74015+
74016+DEFINE_RWLOCK(grsec_exec_file_lock);
74017+
74018+char *gr_shared_page[4];
74019+
74020+char *gr_alert_log_fmt;
74021+char *gr_audit_log_fmt;
74022+char *gr_alert_log_buf;
74023+char *gr_audit_log_buf;
74024+
74025+void __init
74026+grsecurity_init(void)
74027+{
74028+ int j;
74029+ /* create the per-cpu shared pages */
74030+
74031+#ifdef CONFIG_X86
74032+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
74033+#endif
74034+
74035+ for (j = 0; j < 4; j++) {
74036+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
74037+ if (gr_shared_page[j] == NULL) {
74038+ panic("Unable to allocate grsecurity shared page");
74039+ return;
74040+ }
74041+ }
74042+
74043+ /* allocate log buffers */
74044+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
74045+ if (!gr_alert_log_fmt) {
74046+ panic("Unable to allocate grsecurity alert log format buffer");
74047+ return;
74048+ }
74049+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
74050+ if (!gr_audit_log_fmt) {
74051+ panic("Unable to allocate grsecurity audit log format buffer");
74052+ return;
74053+ }
74054+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74055+ if (!gr_alert_log_buf) {
74056+ panic("Unable to allocate grsecurity alert log buffer");
74057+ return;
74058+ }
74059+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74060+ if (!gr_audit_log_buf) {
74061+ panic("Unable to allocate grsecurity audit log buffer");
74062+ return;
74063+ }
74064+
74065+#ifdef CONFIG_GRKERNSEC_IO
74066+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
74067+ grsec_disable_privio = 1;
74068+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74069+ grsec_disable_privio = 1;
74070+#else
74071+ grsec_disable_privio = 0;
74072+#endif
74073+#endif
74074+
74075+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74076+ /* for backward compatibility, tpe_invert always defaults to on if
74077+ enabled in the kernel
74078+ */
74079+ grsec_enable_tpe_invert = 1;
74080+#endif
74081+
74082+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74083+#ifndef CONFIG_GRKERNSEC_SYSCTL
74084+ grsec_lock = 1;
74085+#endif
74086+
74087+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74088+ grsec_enable_log_rwxmaps = 1;
74089+#endif
74090+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74091+ grsec_enable_group = 1;
74092+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
74093+#endif
74094+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74095+ grsec_enable_ptrace_readexec = 1;
74096+#endif
74097+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74098+ grsec_enable_chdir = 1;
74099+#endif
74100+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74101+ grsec_enable_harden_ptrace = 1;
74102+#endif
74103+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74104+ grsec_enable_harden_ipc = 1;
74105+#endif
74106+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74107+ grsec_enable_mount = 1;
74108+#endif
74109+#ifdef CONFIG_GRKERNSEC_LINK
74110+ grsec_enable_link = 1;
74111+#endif
74112+#ifdef CONFIG_GRKERNSEC_BRUTE
74113+ grsec_enable_brute = 1;
74114+#endif
74115+#ifdef CONFIG_GRKERNSEC_DMESG
74116+ grsec_enable_dmesg = 1;
74117+#endif
74118+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74119+ grsec_enable_blackhole = 1;
74120+ grsec_lastack_retries = 4;
74121+#endif
74122+#ifdef CONFIG_GRKERNSEC_FIFO
74123+ grsec_enable_fifo = 1;
74124+#endif
74125+#ifdef CONFIG_GRKERNSEC_EXECLOG
74126+ grsec_enable_execlog = 1;
74127+#endif
74128+#ifdef CONFIG_GRKERNSEC_SETXID
74129+ grsec_enable_setxid = 1;
74130+#endif
74131+#ifdef CONFIG_GRKERNSEC_SIGNAL
74132+ grsec_enable_signal = 1;
74133+#endif
74134+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74135+ grsec_enable_forkfail = 1;
74136+#endif
74137+#ifdef CONFIG_GRKERNSEC_TIME
74138+ grsec_enable_time = 1;
74139+#endif
74140+#ifdef CONFIG_GRKERNSEC_RESLOG
74141+ grsec_resource_logging = 1;
74142+#endif
74143+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74144+ grsec_enable_chroot_findtask = 1;
74145+#endif
74146+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74147+ grsec_enable_chroot_unix = 1;
74148+#endif
74149+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74150+ grsec_enable_chroot_mount = 1;
74151+#endif
74152+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74153+ grsec_enable_chroot_fchdir = 1;
74154+#endif
74155+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74156+ grsec_enable_chroot_shmat = 1;
74157+#endif
74158+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74159+ grsec_enable_audit_ptrace = 1;
74160+#endif
74161+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74162+ grsec_enable_chroot_double = 1;
74163+#endif
74164+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74165+ grsec_enable_chroot_pivot = 1;
74166+#endif
74167+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74168+ grsec_enable_chroot_chdir = 1;
74169+#endif
74170+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74171+ grsec_enable_chroot_chmod = 1;
74172+#endif
74173+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74174+ grsec_enable_chroot_mknod = 1;
74175+#endif
74176+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74177+ grsec_enable_chroot_nice = 1;
74178+#endif
74179+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74180+ grsec_enable_chroot_execlog = 1;
74181+#endif
74182+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74183+ grsec_enable_chroot_caps = 1;
74184+#endif
74185+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74186+ grsec_enable_chroot_sysctl = 1;
74187+#endif
74188+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74189+ grsec_enable_symlinkown = 1;
74190+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
74191+#endif
74192+#ifdef CONFIG_GRKERNSEC_TPE
74193+ grsec_enable_tpe = 1;
74194+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
74195+#ifdef CONFIG_GRKERNSEC_TPE_ALL
74196+ grsec_enable_tpe_all = 1;
74197+#endif
74198+#endif
74199+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74200+ grsec_enable_socket_all = 1;
74201+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
74202+#endif
74203+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74204+ grsec_enable_socket_client = 1;
74205+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
74206+#endif
74207+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74208+ grsec_enable_socket_server = 1;
74209+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
74210+#endif
74211+#endif
74212+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
74213+ grsec_deny_new_usb = 1;
74214+#endif
74215+
74216+ return;
74217+}
74218diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
74219new file mode 100644
74220index 0000000..1773300
74221--- /dev/null
74222+++ b/grsecurity/grsec_ipc.c
74223@@ -0,0 +1,48 @@
74224+#include <linux/kernel.h>
74225+#include <linux/mm.h>
74226+#include <linux/sched.h>
74227+#include <linux/file.h>
74228+#include <linux/ipc.h>
74229+#include <linux/ipc_namespace.h>
74230+#include <linux/grsecurity.h>
74231+#include <linux/grinternal.h>
74232+
74233+int
74234+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
74235+{
74236+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74237+ int write;
74238+ int orig_granted_mode;
74239+ kuid_t euid;
74240+ kgid_t egid;
74241+
74242+ if (!grsec_enable_harden_ipc)
74243+ return 1;
74244+
74245+ euid = current_euid();
74246+ egid = current_egid();
74247+
74248+ write = requested_mode & 00002;
74249+ orig_granted_mode = ipcp->mode;
74250+
74251+ if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
74252+ orig_granted_mode >>= 6;
74253+ else {
74254+ /* if likely wrong permissions, lock to user */
74255+ if (orig_granted_mode & 0007)
74256+ orig_granted_mode = 0;
74257+ /* otherwise do a egid-only check */
74258+ else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
74259+ orig_granted_mode >>= 3;
74260+ /* otherwise, no access */
74261+ else
74262+ orig_granted_mode = 0;
74263+ }
74264+ if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
74265+ !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
74266+ gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
74267+ return 0;
74268+ }
74269+#endif
74270+ return 1;
74271+}
74272diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
74273new file mode 100644
74274index 0000000..5e05e20
74275--- /dev/null
74276+++ b/grsecurity/grsec_link.c
74277@@ -0,0 +1,58 @@
74278+#include <linux/kernel.h>
74279+#include <linux/sched.h>
74280+#include <linux/fs.h>
74281+#include <linux/file.h>
74282+#include <linux/grinternal.h>
74283+
74284+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
74285+{
74286+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74287+ const struct inode *link_inode = link->dentry->d_inode;
74288+
74289+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
74290+ /* ignore root-owned links, e.g. /proc/self */
74291+ gr_is_global_nonroot(link_inode->i_uid) && target &&
74292+ !uid_eq(link_inode->i_uid, target->i_uid)) {
74293+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
74294+ return 1;
74295+ }
74296+#endif
74297+ return 0;
74298+}
74299+
74300+int
74301+gr_handle_follow_link(const struct inode *parent,
74302+ const struct inode *inode,
74303+ const struct dentry *dentry, const struct vfsmount *mnt)
74304+{
74305+#ifdef CONFIG_GRKERNSEC_LINK
74306+ const struct cred *cred = current_cred();
74307+
74308+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
74309+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
74310+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
74311+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
74312+ return -EACCES;
74313+ }
74314+#endif
74315+ return 0;
74316+}
74317+
74318+int
74319+gr_handle_hardlink(const struct dentry *dentry,
74320+ const struct vfsmount *mnt,
74321+ struct inode *inode, const int mode, const struct filename *to)
74322+{
74323+#ifdef CONFIG_GRKERNSEC_LINK
74324+ const struct cred *cred = current_cred();
74325+
74326+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
74327+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
74328+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
74329+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
74330+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
74331+ return -EPERM;
74332+ }
74333+#endif
74334+ return 0;
74335+}
74336diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
74337new file mode 100644
74338index 0000000..dbe0a6b
74339--- /dev/null
74340+++ b/grsecurity/grsec_log.c
74341@@ -0,0 +1,341 @@
74342+#include <linux/kernel.h>
74343+#include <linux/sched.h>
74344+#include <linux/file.h>
74345+#include <linux/tty.h>
74346+#include <linux/fs.h>
74347+#include <linux/mm.h>
74348+#include <linux/grinternal.h>
74349+
74350+#ifdef CONFIG_TREE_PREEMPT_RCU
74351+#define DISABLE_PREEMPT() preempt_disable()
74352+#define ENABLE_PREEMPT() preempt_enable()
74353+#else
74354+#define DISABLE_PREEMPT()
74355+#define ENABLE_PREEMPT()
74356+#endif
74357+
74358+#define BEGIN_LOCKS(x) \
74359+ DISABLE_PREEMPT(); \
74360+ rcu_read_lock(); \
74361+ read_lock(&tasklist_lock); \
74362+ read_lock(&grsec_exec_file_lock); \
74363+ if (x != GR_DO_AUDIT) \
74364+ spin_lock(&grsec_alert_lock); \
74365+ else \
74366+ spin_lock(&grsec_audit_lock)
74367+
74368+#define END_LOCKS(x) \
74369+ if (x != GR_DO_AUDIT) \
74370+ spin_unlock(&grsec_alert_lock); \
74371+ else \
74372+ spin_unlock(&grsec_audit_lock); \
74373+ read_unlock(&grsec_exec_file_lock); \
74374+ read_unlock(&tasklist_lock); \
74375+ rcu_read_unlock(); \
74376+ ENABLE_PREEMPT(); \
74377+ if (x == GR_DONT_AUDIT) \
74378+ gr_handle_alertkill(current)
74379+
74380+enum {
74381+ FLOODING,
74382+ NO_FLOODING
74383+};
74384+
74385+extern char *gr_alert_log_fmt;
74386+extern char *gr_audit_log_fmt;
74387+extern char *gr_alert_log_buf;
74388+extern char *gr_audit_log_buf;
74389+
74390+static int gr_log_start(int audit)
74391+{
74392+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
74393+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
74394+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74395+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
74396+ unsigned long curr_secs = get_seconds();
74397+
74398+ if (audit == GR_DO_AUDIT)
74399+ goto set_fmt;
74400+
74401+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
74402+ grsec_alert_wtime = curr_secs;
74403+ grsec_alert_fyet = 0;
74404+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
74405+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
74406+ grsec_alert_fyet++;
74407+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
74408+ grsec_alert_wtime = curr_secs;
74409+ grsec_alert_fyet++;
74410+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
74411+ return FLOODING;
74412+ }
74413+ else return FLOODING;
74414+
74415+set_fmt:
74416+#endif
74417+ memset(buf, 0, PAGE_SIZE);
74418+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
74419+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
74420+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74421+ } else if (current->signal->curr_ip) {
74422+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
74423+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
74424+ } else if (gr_acl_is_enabled()) {
74425+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
74426+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74427+ } else {
74428+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
74429+ strcpy(buf, fmt);
74430+ }
74431+
74432+ return NO_FLOODING;
74433+}
74434+
74435+static void gr_log_middle(int audit, const char *msg, va_list ap)
74436+ __attribute__ ((format (printf, 2, 0)));
74437+
74438+static void gr_log_middle(int audit, const char *msg, va_list ap)
74439+{
74440+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74441+ unsigned int len = strlen(buf);
74442+
74443+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74444+
74445+ return;
74446+}
74447+
74448+static void gr_log_middle_varargs(int audit, const char *msg, ...)
74449+ __attribute__ ((format (printf, 2, 3)));
74450+
74451+static void gr_log_middle_varargs(int audit, const char *msg, ...)
74452+{
74453+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74454+ unsigned int len = strlen(buf);
74455+ va_list ap;
74456+
74457+ va_start(ap, msg);
74458+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74459+ va_end(ap);
74460+
74461+ return;
74462+}
74463+
74464+static void gr_log_end(int audit, int append_default)
74465+{
74466+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74467+ if (append_default) {
74468+ struct task_struct *task = current;
74469+ struct task_struct *parent = task->real_parent;
74470+ const struct cred *cred = __task_cred(task);
74471+ const struct cred *pcred = __task_cred(parent);
74472+ unsigned int len = strlen(buf);
74473+
74474+ 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));
74475+ }
74476+
74477+ printk("%s\n", buf);
74478+
74479+ return;
74480+}
74481+
74482+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
74483+{
74484+ int logtype;
74485+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
74486+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
74487+ void *voidptr = NULL;
74488+ int num1 = 0, num2 = 0;
74489+ unsigned long ulong1 = 0, ulong2 = 0;
74490+ struct dentry *dentry = NULL;
74491+ struct vfsmount *mnt = NULL;
74492+ struct file *file = NULL;
74493+ struct task_struct *task = NULL;
74494+ struct vm_area_struct *vma = NULL;
74495+ const struct cred *cred, *pcred;
74496+ va_list ap;
74497+
74498+ BEGIN_LOCKS(audit);
74499+ logtype = gr_log_start(audit);
74500+ if (logtype == FLOODING) {
74501+ END_LOCKS(audit);
74502+ return;
74503+ }
74504+ va_start(ap, argtypes);
74505+ switch (argtypes) {
74506+ case GR_TTYSNIFF:
74507+ task = va_arg(ap, struct task_struct *);
74508+ 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));
74509+ break;
74510+ case GR_SYSCTL_HIDDEN:
74511+ str1 = va_arg(ap, char *);
74512+ gr_log_middle_varargs(audit, msg, result, str1);
74513+ break;
74514+ case GR_RBAC:
74515+ dentry = va_arg(ap, struct dentry *);
74516+ mnt = va_arg(ap, struct vfsmount *);
74517+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
74518+ break;
74519+ case GR_RBAC_STR:
74520+ dentry = va_arg(ap, struct dentry *);
74521+ mnt = va_arg(ap, struct vfsmount *);
74522+ str1 = va_arg(ap, char *);
74523+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
74524+ break;
74525+ case GR_STR_RBAC:
74526+ str1 = va_arg(ap, char *);
74527+ dentry = va_arg(ap, struct dentry *);
74528+ mnt = va_arg(ap, struct vfsmount *);
74529+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
74530+ break;
74531+ case GR_RBAC_MODE2:
74532+ dentry = va_arg(ap, struct dentry *);
74533+ mnt = va_arg(ap, struct vfsmount *);
74534+ str1 = va_arg(ap, char *);
74535+ str2 = va_arg(ap, char *);
74536+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
74537+ break;
74538+ case GR_RBAC_MODE3:
74539+ dentry = va_arg(ap, struct dentry *);
74540+ mnt = va_arg(ap, struct vfsmount *);
74541+ str1 = va_arg(ap, char *);
74542+ str2 = va_arg(ap, char *);
74543+ str3 = va_arg(ap, char *);
74544+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
74545+ break;
74546+ case GR_FILENAME:
74547+ dentry = va_arg(ap, struct dentry *);
74548+ mnt = va_arg(ap, struct vfsmount *);
74549+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
74550+ break;
74551+ case GR_STR_FILENAME:
74552+ str1 = va_arg(ap, char *);
74553+ dentry = va_arg(ap, struct dentry *);
74554+ mnt = va_arg(ap, struct vfsmount *);
74555+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
74556+ break;
74557+ case GR_FILENAME_STR:
74558+ dentry = va_arg(ap, struct dentry *);
74559+ mnt = va_arg(ap, struct vfsmount *);
74560+ str1 = va_arg(ap, char *);
74561+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
74562+ break;
74563+ case GR_FILENAME_TWO_INT:
74564+ dentry = va_arg(ap, struct dentry *);
74565+ mnt = va_arg(ap, struct vfsmount *);
74566+ num1 = va_arg(ap, int);
74567+ num2 = va_arg(ap, int);
74568+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
74569+ break;
74570+ case GR_FILENAME_TWO_INT_STR:
74571+ dentry = va_arg(ap, struct dentry *);
74572+ mnt = va_arg(ap, struct vfsmount *);
74573+ num1 = va_arg(ap, int);
74574+ num2 = va_arg(ap, int);
74575+ str1 = va_arg(ap, char *);
74576+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
74577+ break;
74578+ case GR_TEXTREL:
74579+ file = va_arg(ap, struct file *);
74580+ ulong1 = va_arg(ap, unsigned long);
74581+ ulong2 = va_arg(ap, unsigned long);
74582+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
74583+ break;
74584+ case GR_PTRACE:
74585+ task = va_arg(ap, struct task_struct *);
74586+ 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));
74587+ break;
74588+ case GR_RESOURCE:
74589+ task = va_arg(ap, struct task_struct *);
74590+ cred = __task_cred(task);
74591+ pcred = __task_cred(task->real_parent);
74592+ ulong1 = va_arg(ap, unsigned long);
74593+ str1 = va_arg(ap, char *);
74594+ ulong2 = va_arg(ap, unsigned long);
74595+ 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));
74596+ break;
74597+ case GR_CAP:
74598+ task = va_arg(ap, struct task_struct *);
74599+ cred = __task_cred(task);
74600+ pcred = __task_cred(task->real_parent);
74601+ str1 = va_arg(ap, char *);
74602+ 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));
74603+ break;
74604+ case GR_SIG:
74605+ str1 = va_arg(ap, char *);
74606+ voidptr = va_arg(ap, void *);
74607+ gr_log_middle_varargs(audit, msg, str1, voidptr);
74608+ break;
74609+ case GR_SIG2:
74610+ task = va_arg(ap, struct task_struct *);
74611+ cred = __task_cred(task);
74612+ pcred = __task_cred(task->real_parent);
74613+ num1 = va_arg(ap, int);
74614+ 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));
74615+ break;
74616+ case GR_CRASH1:
74617+ task = va_arg(ap, struct task_struct *);
74618+ cred = __task_cred(task);
74619+ pcred = __task_cred(task->real_parent);
74620+ ulong1 = va_arg(ap, unsigned long);
74621+ 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);
74622+ break;
74623+ case GR_CRASH2:
74624+ task = va_arg(ap, struct task_struct *);
74625+ cred = __task_cred(task);
74626+ pcred = __task_cred(task->real_parent);
74627+ ulong1 = va_arg(ap, unsigned long);
74628+ 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);
74629+ break;
74630+ case GR_RWXMAP:
74631+ file = va_arg(ap, struct file *);
74632+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
74633+ break;
74634+ case GR_RWXMAPVMA:
74635+ vma = va_arg(ap, struct vm_area_struct *);
74636+ if (vma->vm_file)
74637+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
74638+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
74639+ str1 = "<stack>";
74640+ else if (vma->vm_start <= current->mm->brk &&
74641+ vma->vm_end >= current->mm->start_brk)
74642+ str1 = "<heap>";
74643+ else
74644+ str1 = "<anonymous mapping>";
74645+ gr_log_middle_varargs(audit, msg, str1);
74646+ break;
74647+ case GR_PSACCT:
74648+ {
74649+ unsigned int wday, cday;
74650+ __u8 whr, chr;
74651+ __u8 wmin, cmin;
74652+ __u8 wsec, csec;
74653+ char cur_tty[64] = { 0 };
74654+ char parent_tty[64] = { 0 };
74655+
74656+ task = va_arg(ap, struct task_struct *);
74657+ wday = va_arg(ap, unsigned int);
74658+ cday = va_arg(ap, unsigned int);
74659+ whr = va_arg(ap, int);
74660+ chr = va_arg(ap, int);
74661+ wmin = va_arg(ap, int);
74662+ cmin = va_arg(ap, int);
74663+ wsec = va_arg(ap, int);
74664+ csec = va_arg(ap, int);
74665+ ulong1 = va_arg(ap, unsigned long);
74666+ cred = __task_cred(task);
74667+ pcred = __task_cred(task->real_parent);
74668+
74669+ 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));
74670+ }
74671+ break;
74672+ default:
74673+ gr_log_middle(audit, msg, ap);
74674+ }
74675+ va_end(ap);
74676+ // these don't need DEFAULTSECARGS printed on the end
74677+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
74678+ gr_log_end(audit, 0);
74679+ else
74680+ gr_log_end(audit, 1);
74681+ END_LOCKS(audit);
74682+}
74683diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
74684new file mode 100644
74685index 0000000..0e39d8c
74686--- /dev/null
74687+++ b/grsecurity/grsec_mem.c
74688@@ -0,0 +1,48 @@
74689+#include <linux/kernel.h>
74690+#include <linux/sched.h>
74691+#include <linux/mm.h>
74692+#include <linux/mman.h>
74693+#include <linux/module.h>
74694+#include <linux/grinternal.h>
74695+
74696+void gr_handle_msr_write(void)
74697+{
74698+ gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
74699+ return;
74700+}
74701+EXPORT_SYMBOL_GPL(gr_handle_msr_write);
74702+
74703+void
74704+gr_handle_ioperm(void)
74705+{
74706+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
74707+ return;
74708+}
74709+
74710+void
74711+gr_handle_iopl(void)
74712+{
74713+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
74714+ return;
74715+}
74716+
74717+void
74718+gr_handle_mem_readwrite(u64 from, u64 to)
74719+{
74720+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
74721+ return;
74722+}
74723+
74724+void
74725+gr_handle_vm86(void)
74726+{
74727+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
74728+ return;
74729+}
74730+
74731+void
74732+gr_log_badprocpid(const char *entry)
74733+{
74734+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
74735+ return;
74736+}
74737diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
74738new file mode 100644
74739index 0000000..cd9e124
74740--- /dev/null
74741+++ b/grsecurity/grsec_mount.c
74742@@ -0,0 +1,65 @@
74743+#include <linux/kernel.h>
74744+#include <linux/sched.h>
74745+#include <linux/mount.h>
74746+#include <linux/major.h>
74747+#include <linux/grsecurity.h>
74748+#include <linux/grinternal.h>
74749+
74750+void
74751+gr_log_remount(const char *devname, const int retval)
74752+{
74753+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74754+ if (grsec_enable_mount && (retval >= 0))
74755+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
74756+#endif
74757+ return;
74758+}
74759+
74760+void
74761+gr_log_unmount(const char *devname, const int retval)
74762+{
74763+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74764+ if (grsec_enable_mount && (retval >= 0))
74765+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
74766+#endif
74767+ return;
74768+}
74769+
74770+void
74771+gr_log_mount(const char *from, const char *to, const int retval)
74772+{
74773+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74774+ if (grsec_enable_mount && (retval >= 0))
74775+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
74776+#endif
74777+ return;
74778+}
74779+
74780+int
74781+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
74782+{
74783+#ifdef CONFIG_GRKERNSEC_ROFS
74784+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
74785+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
74786+ return -EPERM;
74787+ } else
74788+ return 0;
74789+#endif
74790+ return 0;
74791+}
74792+
74793+int
74794+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
74795+{
74796+#ifdef CONFIG_GRKERNSEC_ROFS
74797+ struct inode *inode = dentry->d_inode;
74798+
74799+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
74800+ inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
74801+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
74802+ return -EPERM;
74803+ } else
74804+ return 0;
74805+#endif
74806+ return 0;
74807+}
74808diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
74809new file mode 100644
74810index 0000000..6ee9d50
74811--- /dev/null
74812+++ b/grsecurity/grsec_pax.c
74813@@ -0,0 +1,45 @@
74814+#include <linux/kernel.h>
74815+#include <linux/sched.h>
74816+#include <linux/mm.h>
74817+#include <linux/file.h>
74818+#include <linux/grinternal.h>
74819+#include <linux/grsecurity.h>
74820+
74821+void
74822+gr_log_textrel(struct vm_area_struct * vma)
74823+{
74824+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74825+ if (grsec_enable_log_rwxmaps)
74826+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
74827+#endif
74828+ return;
74829+}
74830+
74831+void gr_log_ptgnustack(struct file *file)
74832+{
74833+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74834+ if (grsec_enable_log_rwxmaps)
74835+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
74836+#endif
74837+ return;
74838+}
74839+
74840+void
74841+gr_log_rwxmmap(struct file *file)
74842+{
74843+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74844+ if (grsec_enable_log_rwxmaps)
74845+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
74846+#endif
74847+ return;
74848+}
74849+
74850+void
74851+gr_log_rwxmprotect(struct vm_area_struct *vma)
74852+{
74853+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74854+ if (grsec_enable_log_rwxmaps)
74855+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
74856+#endif
74857+ return;
74858+}
74859diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
74860new file mode 100644
74861index 0000000..f7f29aa
74862--- /dev/null
74863+++ b/grsecurity/grsec_ptrace.c
74864@@ -0,0 +1,30 @@
74865+#include <linux/kernel.h>
74866+#include <linux/sched.h>
74867+#include <linux/grinternal.h>
74868+#include <linux/security.h>
74869+
74870+void
74871+gr_audit_ptrace(struct task_struct *task)
74872+{
74873+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74874+ if (grsec_enable_audit_ptrace)
74875+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
74876+#endif
74877+ return;
74878+}
74879+
74880+int
74881+gr_ptrace_readexec(struct file *file, int unsafe_flags)
74882+{
74883+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74884+ const struct dentry *dentry = file->f_path.dentry;
74885+ const struct vfsmount *mnt = file->f_path.mnt;
74886+
74887+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
74888+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
74889+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
74890+ return -EACCES;
74891+ }
74892+#endif
74893+ return 0;
74894+}
74895diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
74896new file mode 100644
74897index 0000000..3860c7e
74898--- /dev/null
74899+++ b/grsecurity/grsec_sig.c
74900@@ -0,0 +1,236 @@
74901+#include <linux/kernel.h>
74902+#include <linux/sched.h>
74903+#include <linux/fs.h>
74904+#include <linux/delay.h>
74905+#include <linux/grsecurity.h>
74906+#include <linux/grinternal.h>
74907+#include <linux/hardirq.h>
74908+
74909+char *signames[] = {
74910+ [SIGSEGV] = "Segmentation fault",
74911+ [SIGILL] = "Illegal instruction",
74912+ [SIGABRT] = "Abort",
74913+ [SIGBUS] = "Invalid alignment/Bus error"
74914+};
74915+
74916+void
74917+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
74918+{
74919+#ifdef CONFIG_GRKERNSEC_SIGNAL
74920+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
74921+ (sig == SIGABRT) || (sig == SIGBUS))) {
74922+ if (task_pid_nr(t) == task_pid_nr(current)) {
74923+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
74924+ } else {
74925+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
74926+ }
74927+ }
74928+#endif
74929+ return;
74930+}
74931+
74932+int
74933+gr_handle_signal(const struct task_struct *p, const int sig)
74934+{
74935+#ifdef CONFIG_GRKERNSEC
74936+ /* ignore the 0 signal for protected task checks */
74937+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
74938+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
74939+ return -EPERM;
74940+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
74941+ return -EPERM;
74942+ }
74943+#endif
74944+ return 0;
74945+}
74946+
74947+#ifdef CONFIG_GRKERNSEC
74948+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
74949+
74950+int gr_fake_force_sig(int sig, struct task_struct *t)
74951+{
74952+ unsigned long int flags;
74953+ int ret, blocked, ignored;
74954+ struct k_sigaction *action;
74955+
74956+ spin_lock_irqsave(&t->sighand->siglock, flags);
74957+ action = &t->sighand->action[sig-1];
74958+ ignored = action->sa.sa_handler == SIG_IGN;
74959+ blocked = sigismember(&t->blocked, sig);
74960+ if (blocked || ignored) {
74961+ action->sa.sa_handler = SIG_DFL;
74962+ if (blocked) {
74963+ sigdelset(&t->blocked, sig);
74964+ recalc_sigpending_and_wake(t);
74965+ }
74966+ }
74967+ if (action->sa.sa_handler == SIG_DFL)
74968+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
74969+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
74970+
74971+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
74972+
74973+ return ret;
74974+}
74975+#endif
74976+
74977+#define GR_USER_BAN_TIME (15 * 60)
74978+#define GR_DAEMON_BRUTE_TIME (30 * 60)
74979+
74980+void gr_handle_brute_attach(int dumpable)
74981+{
74982+#ifdef CONFIG_GRKERNSEC_BRUTE
74983+ struct task_struct *p = current;
74984+ kuid_t uid = GLOBAL_ROOT_UID;
74985+ int daemon = 0;
74986+
74987+ if (!grsec_enable_brute)
74988+ return;
74989+
74990+ rcu_read_lock();
74991+ read_lock(&tasklist_lock);
74992+ read_lock(&grsec_exec_file_lock);
74993+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
74994+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
74995+ p->real_parent->brute = 1;
74996+ daemon = 1;
74997+ } else {
74998+ const struct cred *cred = __task_cred(p), *cred2;
74999+ struct task_struct *tsk, *tsk2;
75000+
75001+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
75002+ struct user_struct *user;
75003+
75004+ uid = cred->uid;
75005+
75006+ /* this is put upon execution past expiration */
75007+ user = find_user(uid);
75008+ if (user == NULL)
75009+ goto unlock;
75010+ user->suid_banned = 1;
75011+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
75012+ if (user->suid_ban_expires == ~0UL)
75013+ user->suid_ban_expires--;
75014+
75015+ /* only kill other threads of the same binary, from the same user */
75016+ do_each_thread(tsk2, tsk) {
75017+ cred2 = __task_cred(tsk);
75018+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
75019+ gr_fake_force_sig(SIGKILL, tsk);
75020+ } while_each_thread(tsk2, tsk);
75021+ }
75022+ }
75023+unlock:
75024+ read_unlock(&grsec_exec_file_lock);
75025+ read_unlock(&tasklist_lock);
75026+ rcu_read_unlock();
75027+
75028+ if (gr_is_global_nonroot(uid))
75029+ 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);
75030+ else if (daemon)
75031+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
75032+
75033+#endif
75034+ return;
75035+}
75036+
75037+void gr_handle_brute_check(void)
75038+{
75039+#ifdef CONFIG_GRKERNSEC_BRUTE
75040+ struct task_struct *p = current;
75041+
75042+ if (unlikely(p->brute)) {
75043+ if (!grsec_enable_brute)
75044+ p->brute = 0;
75045+ else if (time_before(get_seconds(), p->brute_expires))
75046+ msleep(30 * 1000);
75047+ }
75048+#endif
75049+ return;
75050+}
75051+
75052+void gr_handle_kernel_exploit(void)
75053+{
75054+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75055+ const struct cred *cred;
75056+ struct task_struct *tsk, *tsk2;
75057+ struct user_struct *user;
75058+ kuid_t uid;
75059+
75060+ if (in_irq() || in_serving_softirq() || in_nmi())
75061+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
75062+
75063+ uid = current_uid();
75064+
75065+ if (gr_is_global_root(uid))
75066+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
75067+ else {
75068+ /* kill all the processes of this user, hold a reference
75069+ to their creds struct, and prevent them from creating
75070+ another process until system reset
75071+ */
75072+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
75073+ GR_GLOBAL_UID(uid));
75074+ /* we intentionally leak this ref */
75075+ user = get_uid(current->cred->user);
75076+ if (user)
75077+ user->kernel_banned = 1;
75078+
75079+ /* kill all processes of this user */
75080+ read_lock(&tasklist_lock);
75081+ do_each_thread(tsk2, tsk) {
75082+ cred = __task_cred(tsk);
75083+ if (uid_eq(cred->uid, uid))
75084+ gr_fake_force_sig(SIGKILL, tsk);
75085+ } while_each_thread(tsk2, tsk);
75086+ read_unlock(&tasklist_lock);
75087+ }
75088+#endif
75089+}
75090+
75091+#ifdef CONFIG_GRKERNSEC_BRUTE
75092+static bool suid_ban_expired(struct user_struct *user)
75093+{
75094+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
75095+ user->suid_banned = 0;
75096+ user->suid_ban_expires = 0;
75097+ free_uid(user);
75098+ return true;
75099+ }
75100+
75101+ return false;
75102+}
75103+#endif
75104+
75105+int gr_process_kernel_exec_ban(void)
75106+{
75107+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75108+ if (unlikely(current->cred->user->kernel_banned))
75109+ return -EPERM;
75110+#endif
75111+ return 0;
75112+}
75113+
75114+int gr_process_kernel_setuid_ban(struct user_struct *user)
75115+{
75116+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75117+ if (unlikely(user->kernel_banned))
75118+ gr_fake_force_sig(SIGKILL, current);
75119+#endif
75120+ return 0;
75121+}
75122+
75123+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
75124+{
75125+#ifdef CONFIG_GRKERNSEC_BRUTE
75126+ struct user_struct *user = current->cred->user;
75127+ if (unlikely(user->suid_banned)) {
75128+ if (suid_ban_expired(user))
75129+ return 0;
75130+ /* disallow execution of suid binaries only */
75131+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
75132+ return -EPERM;
75133+ }
75134+#endif
75135+ return 0;
75136+}
75137diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
75138new file mode 100644
75139index 0000000..c0aef3a
75140--- /dev/null
75141+++ b/grsecurity/grsec_sock.c
75142@@ -0,0 +1,244 @@
75143+#include <linux/kernel.h>
75144+#include <linux/module.h>
75145+#include <linux/sched.h>
75146+#include <linux/file.h>
75147+#include <linux/net.h>
75148+#include <linux/in.h>
75149+#include <linux/ip.h>
75150+#include <net/sock.h>
75151+#include <net/inet_sock.h>
75152+#include <linux/grsecurity.h>
75153+#include <linux/grinternal.h>
75154+#include <linux/gracl.h>
75155+
75156+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
75157+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
75158+
75159+EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
75160+EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
75161+
75162+#ifdef CONFIG_UNIX_MODULE
75163+EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
75164+EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
75165+EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
75166+EXPORT_SYMBOL_GPL(gr_handle_create);
75167+#endif
75168+
75169+#ifdef CONFIG_GRKERNSEC
75170+#define gr_conn_table_size 32749
75171+struct conn_table_entry {
75172+ struct conn_table_entry *next;
75173+ struct signal_struct *sig;
75174+};
75175+
75176+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
75177+DEFINE_SPINLOCK(gr_conn_table_lock);
75178+
75179+extern const char * gr_socktype_to_name(unsigned char type);
75180+extern const char * gr_proto_to_name(unsigned char proto);
75181+extern const char * gr_sockfamily_to_name(unsigned char family);
75182+
75183+static __inline__ int
75184+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
75185+{
75186+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
75187+}
75188+
75189+static __inline__ int
75190+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
75191+ __u16 sport, __u16 dport)
75192+{
75193+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
75194+ sig->gr_sport == sport && sig->gr_dport == dport))
75195+ return 1;
75196+ else
75197+ return 0;
75198+}
75199+
75200+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
75201+{
75202+ struct conn_table_entry **match;
75203+ unsigned int index;
75204+
75205+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75206+ sig->gr_sport, sig->gr_dport,
75207+ gr_conn_table_size);
75208+
75209+ newent->sig = sig;
75210+
75211+ match = &gr_conn_table[index];
75212+ newent->next = *match;
75213+ *match = newent;
75214+
75215+ return;
75216+}
75217+
75218+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
75219+{
75220+ struct conn_table_entry *match, *last = NULL;
75221+ unsigned int index;
75222+
75223+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75224+ sig->gr_sport, sig->gr_dport,
75225+ gr_conn_table_size);
75226+
75227+ match = gr_conn_table[index];
75228+ while (match && !conn_match(match->sig,
75229+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
75230+ sig->gr_dport)) {
75231+ last = match;
75232+ match = match->next;
75233+ }
75234+
75235+ if (match) {
75236+ if (last)
75237+ last->next = match->next;
75238+ else
75239+ gr_conn_table[index] = NULL;
75240+ kfree(match);
75241+ }
75242+
75243+ return;
75244+}
75245+
75246+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
75247+ __u16 sport, __u16 dport)
75248+{
75249+ struct conn_table_entry *match;
75250+ unsigned int index;
75251+
75252+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
75253+
75254+ match = gr_conn_table[index];
75255+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
75256+ match = match->next;
75257+
75258+ if (match)
75259+ return match->sig;
75260+ else
75261+ return NULL;
75262+}
75263+
75264+#endif
75265+
75266+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
75267+{
75268+#ifdef CONFIG_GRKERNSEC
75269+ struct signal_struct *sig = task->signal;
75270+ struct conn_table_entry *newent;
75271+
75272+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
75273+ if (newent == NULL)
75274+ return;
75275+ /* no bh lock needed since we are called with bh disabled */
75276+ spin_lock(&gr_conn_table_lock);
75277+ gr_del_task_from_ip_table_nolock(sig);
75278+ sig->gr_saddr = inet->inet_rcv_saddr;
75279+ sig->gr_daddr = inet->inet_daddr;
75280+ sig->gr_sport = inet->inet_sport;
75281+ sig->gr_dport = inet->inet_dport;
75282+ gr_add_to_task_ip_table_nolock(sig, newent);
75283+ spin_unlock(&gr_conn_table_lock);
75284+#endif
75285+ return;
75286+}
75287+
75288+void gr_del_task_from_ip_table(struct task_struct *task)
75289+{
75290+#ifdef CONFIG_GRKERNSEC
75291+ spin_lock_bh(&gr_conn_table_lock);
75292+ gr_del_task_from_ip_table_nolock(task->signal);
75293+ spin_unlock_bh(&gr_conn_table_lock);
75294+#endif
75295+ return;
75296+}
75297+
75298+void
75299+gr_attach_curr_ip(const struct sock *sk)
75300+{
75301+#ifdef CONFIG_GRKERNSEC
75302+ struct signal_struct *p, *set;
75303+ const struct inet_sock *inet = inet_sk(sk);
75304+
75305+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
75306+ return;
75307+
75308+ set = current->signal;
75309+
75310+ spin_lock_bh(&gr_conn_table_lock);
75311+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
75312+ inet->inet_dport, inet->inet_sport);
75313+ if (unlikely(p != NULL)) {
75314+ set->curr_ip = p->curr_ip;
75315+ set->used_accept = 1;
75316+ gr_del_task_from_ip_table_nolock(p);
75317+ spin_unlock_bh(&gr_conn_table_lock);
75318+ return;
75319+ }
75320+ spin_unlock_bh(&gr_conn_table_lock);
75321+
75322+ set->curr_ip = inet->inet_daddr;
75323+ set->used_accept = 1;
75324+#endif
75325+ return;
75326+}
75327+
75328+int
75329+gr_handle_sock_all(const int family, const int type, const int protocol)
75330+{
75331+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75332+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
75333+ (family != AF_UNIX)) {
75334+ if (family == AF_INET)
75335+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
75336+ else
75337+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
75338+ return -EACCES;
75339+ }
75340+#endif
75341+ return 0;
75342+}
75343+
75344+int
75345+gr_handle_sock_server(const struct sockaddr *sck)
75346+{
75347+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75348+ if (grsec_enable_socket_server &&
75349+ in_group_p(grsec_socket_server_gid) &&
75350+ sck && (sck->sa_family != AF_UNIX) &&
75351+ (sck->sa_family != AF_LOCAL)) {
75352+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75353+ return -EACCES;
75354+ }
75355+#endif
75356+ return 0;
75357+}
75358+
75359+int
75360+gr_handle_sock_server_other(const struct sock *sck)
75361+{
75362+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75363+ if (grsec_enable_socket_server &&
75364+ in_group_p(grsec_socket_server_gid) &&
75365+ sck && (sck->sk_family != AF_UNIX) &&
75366+ (sck->sk_family != AF_LOCAL)) {
75367+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75368+ return -EACCES;
75369+ }
75370+#endif
75371+ return 0;
75372+}
75373+
75374+int
75375+gr_handle_sock_client(const struct sockaddr *sck)
75376+{
75377+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75378+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
75379+ sck && (sck->sa_family != AF_UNIX) &&
75380+ (sck->sa_family != AF_LOCAL)) {
75381+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
75382+ return -EACCES;
75383+ }
75384+#endif
75385+ return 0;
75386+}
75387diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
75388new file mode 100644
75389index 0000000..8159888
75390--- /dev/null
75391+++ b/grsecurity/grsec_sysctl.c
75392@@ -0,0 +1,479 @@
75393+#include <linux/kernel.h>
75394+#include <linux/sched.h>
75395+#include <linux/sysctl.h>
75396+#include <linux/grsecurity.h>
75397+#include <linux/grinternal.h>
75398+
75399+int
75400+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
75401+{
75402+#ifdef CONFIG_GRKERNSEC_SYSCTL
75403+ if (dirname == NULL || name == NULL)
75404+ return 0;
75405+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
75406+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
75407+ return -EACCES;
75408+ }
75409+#endif
75410+ return 0;
75411+}
75412+
75413+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
75414+static int __maybe_unused __read_only one = 1;
75415+#endif
75416+
75417+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
75418+ defined(CONFIG_GRKERNSEC_DENYUSB)
75419+struct ctl_table grsecurity_table[] = {
75420+#ifdef CONFIG_GRKERNSEC_SYSCTL
75421+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
75422+#ifdef CONFIG_GRKERNSEC_IO
75423+ {
75424+ .procname = "disable_priv_io",
75425+ .data = &grsec_disable_privio,
75426+ .maxlen = sizeof(int),
75427+ .mode = 0600,
75428+ .proc_handler = &proc_dointvec,
75429+ },
75430+#endif
75431+#endif
75432+#ifdef CONFIG_GRKERNSEC_LINK
75433+ {
75434+ .procname = "linking_restrictions",
75435+ .data = &grsec_enable_link,
75436+ .maxlen = sizeof(int),
75437+ .mode = 0600,
75438+ .proc_handler = &proc_dointvec,
75439+ },
75440+#endif
75441+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75442+ {
75443+ .procname = "enforce_symlinksifowner",
75444+ .data = &grsec_enable_symlinkown,
75445+ .maxlen = sizeof(int),
75446+ .mode = 0600,
75447+ .proc_handler = &proc_dointvec,
75448+ },
75449+ {
75450+ .procname = "symlinkown_gid",
75451+ .data = &grsec_symlinkown_gid,
75452+ .maxlen = sizeof(int),
75453+ .mode = 0600,
75454+ .proc_handler = &proc_dointvec,
75455+ },
75456+#endif
75457+#ifdef CONFIG_GRKERNSEC_BRUTE
75458+ {
75459+ .procname = "deter_bruteforce",
75460+ .data = &grsec_enable_brute,
75461+ .maxlen = sizeof(int),
75462+ .mode = 0600,
75463+ .proc_handler = &proc_dointvec,
75464+ },
75465+#endif
75466+#ifdef CONFIG_GRKERNSEC_FIFO
75467+ {
75468+ .procname = "fifo_restrictions",
75469+ .data = &grsec_enable_fifo,
75470+ .maxlen = sizeof(int),
75471+ .mode = 0600,
75472+ .proc_handler = &proc_dointvec,
75473+ },
75474+#endif
75475+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75476+ {
75477+ .procname = "ptrace_readexec",
75478+ .data = &grsec_enable_ptrace_readexec,
75479+ .maxlen = sizeof(int),
75480+ .mode = 0600,
75481+ .proc_handler = &proc_dointvec,
75482+ },
75483+#endif
75484+#ifdef CONFIG_GRKERNSEC_SETXID
75485+ {
75486+ .procname = "consistent_setxid",
75487+ .data = &grsec_enable_setxid,
75488+ .maxlen = sizeof(int),
75489+ .mode = 0600,
75490+ .proc_handler = &proc_dointvec,
75491+ },
75492+#endif
75493+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75494+ {
75495+ .procname = "ip_blackhole",
75496+ .data = &grsec_enable_blackhole,
75497+ .maxlen = sizeof(int),
75498+ .mode = 0600,
75499+ .proc_handler = &proc_dointvec,
75500+ },
75501+ {
75502+ .procname = "lastack_retries",
75503+ .data = &grsec_lastack_retries,
75504+ .maxlen = sizeof(int),
75505+ .mode = 0600,
75506+ .proc_handler = &proc_dointvec,
75507+ },
75508+#endif
75509+#ifdef CONFIG_GRKERNSEC_EXECLOG
75510+ {
75511+ .procname = "exec_logging",
75512+ .data = &grsec_enable_execlog,
75513+ .maxlen = sizeof(int),
75514+ .mode = 0600,
75515+ .proc_handler = &proc_dointvec,
75516+ },
75517+#endif
75518+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75519+ {
75520+ .procname = "rwxmap_logging",
75521+ .data = &grsec_enable_log_rwxmaps,
75522+ .maxlen = sizeof(int),
75523+ .mode = 0600,
75524+ .proc_handler = &proc_dointvec,
75525+ },
75526+#endif
75527+#ifdef CONFIG_GRKERNSEC_SIGNAL
75528+ {
75529+ .procname = "signal_logging",
75530+ .data = &grsec_enable_signal,
75531+ .maxlen = sizeof(int),
75532+ .mode = 0600,
75533+ .proc_handler = &proc_dointvec,
75534+ },
75535+#endif
75536+#ifdef CONFIG_GRKERNSEC_FORKFAIL
75537+ {
75538+ .procname = "forkfail_logging",
75539+ .data = &grsec_enable_forkfail,
75540+ .maxlen = sizeof(int),
75541+ .mode = 0600,
75542+ .proc_handler = &proc_dointvec,
75543+ },
75544+#endif
75545+#ifdef CONFIG_GRKERNSEC_TIME
75546+ {
75547+ .procname = "timechange_logging",
75548+ .data = &grsec_enable_time,
75549+ .maxlen = sizeof(int),
75550+ .mode = 0600,
75551+ .proc_handler = &proc_dointvec,
75552+ },
75553+#endif
75554+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
75555+ {
75556+ .procname = "chroot_deny_shmat",
75557+ .data = &grsec_enable_chroot_shmat,
75558+ .maxlen = sizeof(int),
75559+ .mode = 0600,
75560+ .proc_handler = &proc_dointvec,
75561+ },
75562+#endif
75563+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
75564+ {
75565+ .procname = "chroot_deny_unix",
75566+ .data = &grsec_enable_chroot_unix,
75567+ .maxlen = sizeof(int),
75568+ .mode = 0600,
75569+ .proc_handler = &proc_dointvec,
75570+ },
75571+#endif
75572+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
75573+ {
75574+ .procname = "chroot_deny_mount",
75575+ .data = &grsec_enable_chroot_mount,
75576+ .maxlen = sizeof(int),
75577+ .mode = 0600,
75578+ .proc_handler = &proc_dointvec,
75579+ },
75580+#endif
75581+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
75582+ {
75583+ .procname = "chroot_deny_fchdir",
75584+ .data = &grsec_enable_chroot_fchdir,
75585+ .maxlen = sizeof(int),
75586+ .mode = 0600,
75587+ .proc_handler = &proc_dointvec,
75588+ },
75589+#endif
75590+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
75591+ {
75592+ .procname = "chroot_deny_chroot",
75593+ .data = &grsec_enable_chroot_double,
75594+ .maxlen = sizeof(int),
75595+ .mode = 0600,
75596+ .proc_handler = &proc_dointvec,
75597+ },
75598+#endif
75599+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
75600+ {
75601+ .procname = "chroot_deny_pivot",
75602+ .data = &grsec_enable_chroot_pivot,
75603+ .maxlen = sizeof(int),
75604+ .mode = 0600,
75605+ .proc_handler = &proc_dointvec,
75606+ },
75607+#endif
75608+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
75609+ {
75610+ .procname = "chroot_enforce_chdir",
75611+ .data = &grsec_enable_chroot_chdir,
75612+ .maxlen = sizeof(int),
75613+ .mode = 0600,
75614+ .proc_handler = &proc_dointvec,
75615+ },
75616+#endif
75617+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
75618+ {
75619+ .procname = "chroot_deny_chmod",
75620+ .data = &grsec_enable_chroot_chmod,
75621+ .maxlen = sizeof(int),
75622+ .mode = 0600,
75623+ .proc_handler = &proc_dointvec,
75624+ },
75625+#endif
75626+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
75627+ {
75628+ .procname = "chroot_deny_mknod",
75629+ .data = &grsec_enable_chroot_mknod,
75630+ .maxlen = sizeof(int),
75631+ .mode = 0600,
75632+ .proc_handler = &proc_dointvec,
75633+ },
75634+#endif
75635+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
75636+ {
75637+ .procname = "chroot_restrict_nice",
75638+ .data = &grsec_enable_chroot_nice,
75639+ .maxlen = sizeof(int),
75640+ .mode = 0600,
75641+ .proc_handler = &proc_dointvec,
75642+ },
75643+#endif
75644+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
75645+ {
75646+ .procname = "chroot_execlog",
75647+ .data = &grsec_enable_chroot_execlog,
75648+ .maxlen = sizeof(int),
75649+ .mode = 0600,
75650+ .proc_handler = &proc_dointvec,
75651+ },
75652+#endif
75653+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
75654+ {
75655+ .procname = "chroot_caps",
75656+ .data = &grsec_enable_chroot_caps,
75657+ .maxlen = sizeof(int),
75658+ .mode = 0600,
75659+ .proc_handler = &proc_dointvec,
75660+ },
75661+#endif
75662+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
75663+ {
75664+ .procname = "chroot_deny_sysctl",
75665+ .data = &grsec_enable_chroot_sysctl,
75666+ .maxlen = sizeof(int),
75667+ .mode = 0600,
75668+ .proc_handler = &proc_dointvec,
75669+ },
75670+#endif
75671+#ifdef CONFIG_GRKERNSEC_TPE
75672+ {
75673+ .procname = "tpe",
75674+ .data = &grsec_enable_tpe,
75675+ .maxlen = sizeof(int),
75676+ .mode = 0600,
75677+ .proc_handler = &proc_dointvec,
75678+ },
75679+ {
75680+ .procname = "tpe_gid",
75681+ .data = &grsec_tpe_gid,
75682+ .maxlen = sizeof(int),
75683+ .mode = 0600,
75684+ .proc_handler = &proc_dointvec,
75685+ },
75686+#endif
75687+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
75688+ {
75689+ .procname = "tpe_invert",
75690+ .data = &grsec_enable_tpe_invert,
75691+ .maxlen = sizeof(int),
75692+ .mode = 0600,
75693+ .proc_handler = &proc_dointvec,
75694+ },
75695+#endif
75696+#ifdef CONFIG_GRKERNSEC_TPE_ALL
75697+ {
75698+ .procname = "tpe_restrict_all",
75699+ .data = &grsec_enable_tpe_all,
75700+ .maxlen = sizeof(int),
75701+ .mode = 0600,
75702+ .proc_handler = &proc_dointvec,
75703+ },
75704+#endif
75705+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75706+ {
75707+ .procname = "socket_all",
75708+ .data = &grsec_enable_socket_all,
75709+ .maxlen = sizeof(int),
75710+ .mode = 0600,
75711+ .proc_handler = &proc_dointvec,
75712+ },
75713+ {
75714+ .procname = "socket_all_gid",
75715+ .data = &grsec_socket_all_gid,
75716+ .maxlen = sizeof(int),
75717+ .mode = 0600,
75718+ .proc_handler = &proc_dointvec,
75719+ },
75720+#endif
75721+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75722+ {
75723+ .procname = "socket_client",
75724+ .data = &grsec_enable_socket_client,
75725+ .maxlen = sizeof(int),
75726+ .mode = 0600,
75727+ .proc_handler = &proc_dointvec,
75728+ },
75729+ {
75730+ .procname = "socket_client_gid",
75731+ .data = &grsec_socket_client_gid,
75732+ .maxlen = sizeof(int),
75733+ .mode = 0600,
75734+ .proc_handler = &proc_dointvec,
75735+ },
75736+#endif
75737+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75738+ {
75739+ .procname = "socket_server",
75740+ .data = &grsec_enable_socket_server,
75741+ .maxlen = sizeof(int),
75742+ .mode = 0600,
75743+ .proc_handler = &proc_dointvec,
75744+ },
75745+ {
75746+ .procname = "socket_server_gid",
75747+ .data = &grsec_socket_server_gid,
75748+ .maxlen = sizeof(int),
75749+ .mode = 0600,
75750+ .proc_handler = &proc_dointvec,
75751+ },
75752+#endif
75753+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
75754+ {
75755+ .procname = "audit_group",
75756+ .data = &grsec_enable_group,
75757+ .maxlen = sizeof(int),
75758+ .mode = 0600,
75759+ .proc_handler = &proc_dointvec,
75760+ },
75761+ {
75762+ .procname = "audit_gid",
75763+ .data = &grsec_audit_gid,
75764+ .maxlen = sizeof(int),
75765+ .mode = 0600,
75766+ .proc_handler = &proc_dointvec,
75767+ },
75768+#endif
75769+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
75770+ {
75771+ .procname = "audit_chdir",
75772+ .data = &grsec_enable_chdir,
75773+ .maxlen = sizeof(int),
75774+ .mode = 0600,
75775+ .proc_handler = &proc_dointvec,
75776+ },
75777+#endif
75778+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75779+ {
75780+ .procname = "audit_mount",
75781+ .data = &grsec_enable_mount,
75782+ .maxlen = sizeof(int),
75783+ .mode = 0600,
75784+ .proc_handler = &proc_dointvec,
75785+ },
75786+#endif
75787+#ifdef CONFIG_GRKERNSEC_DMESG
75788+ {
75789+ .procname = "dmesg",
75790+ .data = &grsec_enable_dmesg,
75791+ .maxlen = sizeof(int),
75792+ .mode = 0600,
75793+ .proc_handler = &proc_dointvec,
75794+ },
75795+#endif
75796+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
75797+ {
75798+ .procname = "chroot_findtask",
75799+ .data = &grsec_enable_chroot_findtask,
75800+ .maxlen = sizeof(int),
75801+ .mode = 0600,
75802+ .proc_handler = &proc_dointvec,
75803+ },
75804+#endif
75805+#ifdef CONFIG_GRKERNSEC_RESLOG
75806+ {
75807+ .procname = "resource_logging",
75808+ .data = &grsec_resource_logging,
75809+ .maxlen = sizeof(int),
75810+ .mode = 0600,
75811+ .proc_handler = &proc_dointvec,
75812+ },
75813+#endif
75814+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75815+ {
75816+ .procname = "audit_ptrace",
75817+ .data = &grsec_enable_audit_ptrace,
75818+ .maxlen = sizeof(int),
75819+ .mode = 0600,
75820+ .proc_handler = &proc_dointvec,
75821+ },
75822+#endif
75823+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
75824+ {
75825+ .procname = "harden_ptrace",
75826+ .data = &grsec_enable_harden_ptrace,
75827+ .maxlen = sizeof(int),
75828+ .mode = 0600,
75829+ .proc_handler = &proc_dointvec,
75830+ },
75831+#endif
75832+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
75833+ {
75834+ .procname = "harden_ipc",
75835+ .data = &grsec_enable_harden_ipc,
75836+ .maxlen = sizeof(int),
75837+ .mode = 0600,
75838+ .proc_handler = &proc_dointvec,
75839+ },
75840+#endif
75841+ {
75842+ .procname = "grsec_lock",
75843+ .data = &grsec_lock,
75844+ .maxlen = sizeof(int),
75845+ .mode = 0600,
75846+ .proc_handler = &proc_dointvec,
75847+ },
75848+#endif
75849+#ifdef CONFIG_GRKERNSEC_ROFS
75850+ {
75851+ .procname = "romount_protect",
75852+ .data = &grsec_enable_rofs,
75853+ .maxlen = sizeof(int),
75854+ .mode = 0600,
75855+ .proc_handler = &proc_dointvec_minmax,
75856+ .extra1 = &one,
75857+ .extra2 = &one,
75858+ },
75859+#endif
75860+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
75861+ {
75862+ .procname = "deny_new_usb",
75863+ .data = &grsec_deny_new_usb,
75864+ .maxlen = sizeof(int),
75865+ .mode = 0600,
75866+ .proc_handler = &proc_dointvec,
75867+ },
75868+#endif
75869+ { }
75870+};
75871+#endif
75872diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
75873new file mode 100644
75874index 0000000..61b514e
75875--- /dev/null
75876+++ b/grsecurity/grsec_time.c
75877@@ -0,0 +1,16 @@
75878+#include <linux/kernel.h>
75879+#include <linux/sched.h>
75880+#include <linux/grinternal.h>
75881+#include <linux/module.h>
75882+
75883+void
75884+gr_log_timechange(void)
75885+{
75886+#ifdef CONFIG_GRKERNSEC_TIME
75887+ if (grsec_enable_time)
75888+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
75889+#endif
75890+ return;
75891+}
75892+
75893+EXPORT_SYMBOL_GPL(gr_log_timechange);
75894diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
75895new file mode 100644
75896index 0000000..ee57dcf
75897--- /dev/null
75898+++ b/grsecurity/grsec_tpe.c
75899@@ -0,0 +1,73 @@
75900+#include <linux/kernel.h>
75901+#include <linux/sched.h>
75902+#include <linux/file.h>
75903+#include <linux/fs.h>
75904+#include <linux/grinternal.h>
75905+
75906+extern int gr_acl_tpe_check(void);
75907+
75908+int
75909+gr_tpe_allow(const struct file *file)
75910+{
75911+#ifdef CONFIG_GRKERNSEC
75912+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
75913+ const struct cred *cred = current_cred();
75914+ char *msg = NULL;
75915+ char *msg2 = NULL;
75916+
75917+ // never restrict root
75918+ if (gr_is_global_root(cred->uid))
75919+ return 1;
75920+
75921+ if (grsec_enable_tpe) {
75922+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
75923+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
75924+ msg = "not being in trusted group";
75925+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
75926+ msg = "being in untrusted group";
75927+#else
75928+ if (in_group_p(grsec_tpe_gid))
75929+ msg = "being in untrusted group";
75930+#endif
75931+ }
75932+ if (!msg && gr_acl_tpe_check())
75933+ msg = "being in untrusted role";
75934+
75935+ // not in any affected group/role
75936+ if (!msg)
75937+ goto next_check;
75938+
75939+ if (gr_is_global_nonroot(inode->i_uid))
75940+ msg2 = "file in non-root-owned directory";
75941+ else if (inode->i_mode & S_IWOTH)
75942+ msg2 = "file in world-writable directory";
75943+ else if (inode->i_mode & S_IWGRP)
75944+ msg2 = "file in group-writable directory";
75945+
75946+ if (msg && msg2) {
75947+ char fullmsg[70] = {0};
75948+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
75949+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
75950+ return 0;
75951+ }
75952+ msg = NULL;
75953+next_check:
75954+#ifdef CONFIG_GRKERNSEC_TPE_ALL
75955+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
75956+ return 1;
75957+
75958+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
75959+ msg = "directory not owned by user";
75960+ else if (inode->i_mode & S_IWOTH)
75961+ msg = "file in world-writable directory";
75962+ else if (inode->i_mode & S_IWGRP)
75963+ msg = "file in group-writable directory";
75964+
75965+ if (msg) {
75966+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
75967+ return 0;
75968+ }
75969+#endif
75970+#endif
75971+ return 1;
75972+}
75973diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
75974new file mode 100644
75975index 0000000..ae02d8e
75976--- /dev/null
75977+++ b/grsecurity/grsec_usb.c
75978@@ -0,0 +1,15 @@
75979+#include <linux/kernel.h>
75980+#include <linux/grinternal.h>
75981+#include <linux/module.h>
75982+
75983+int gr_handle_new_usb(void)
75984+{
75985+#ifdef CONFIG_GRKERNSEC_DENYUSB
75986+ if (grsec_deny_new_usb) {
75987+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
75988+ return 1;
75989+ }
75990+#endif
75991+ return 0;
75992+}
75993+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
75994diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
75995new file mode 100644
75996index 0000000..9f7b1ac
75997--- /dev/null
75998+++ b/grsecurity/grsum.c
75999@@ -0,0 +1,61 @@
76000+#include <linux/err.h>
76001+#include <linux/kernel.h>
76002+#include <linux/sched.h>
76003+#include <linux/mm.h>
76004+#include <linux/scatterlist.h>
76005+#include <linux/crypto.h>
76006+#include <linux/gracl.h>
76007+
76008+
76009+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
76010+#error "crypto and sha256 must be built into the kernel"
76011+#endif
76012+
76013+int
76014+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
76015+{
76016+ char *p;
76017+ struct crypto_hash *tfm;
76018+ struct hash_desc desc;
76019+ struct scatterlist sg;
76020+ unsigned char temp_sum[GR_SHA_LEN];
76021+ volatile int retval = 0;
76022+ volatile int dummy = 0;
76023+ unsigned int i;
76024+
76025+ sg_init_table(&sg, 1);
76026+
76027+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
76028+ if (IS_ERR(tfm)) {
76029+ /* should never happen, since sha256 should be built in */
76030+ return 1;
76031+ }
76032+
76033+ desc.tfm = tfm;
76034+ desc.flags = 0;
76035+
76036+ crypto_hash_init(&desc);
76037+
76038+ p = salt;
76039+ sg_set_buf(&sg, p, GR_SALT_LEN);
76040+ crypto_hash_update(&desc, &sg, sg.length);
76041+
76042+ p = entry->pw;
76043+ sg_set_buf(&sg, p, strlen(p));
76044+
76045+ crypto_hash_update(&desc, &sg, sg.length);
76046+
76047+ crypto_hash_final(&desc, temp_sum);
76048+
76049+ memset(entry->pw, 0, GR_PW_LEN);
76050+
76051+ for (i = 0; i < GR_SHA_LEN; i++)
76052+ if (sum[i] != temp_sum[i])
76053+ retval = 1;
76054+ else
76055+ dummy = 1; // waste a cycle
76056+
76057+ crypto_free_hash(tfm);
76058+
76059+ return retval;
76060+}
76061diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
76062index 77ff547..181834f 100644
76063--- a/include/asm-generic/4level-fixup.h
76064+++ b/include/asm-generic/4level-fixup.h
76065@@ -13,8 +13,10 @@
76066 #define pmd_alloc(mm, pud, address) \
76067 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
76068 NULL: pmd_offset(pud, address))
76069+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
76070
76071 #define pud_alloc(mm, pgd, address) (pgd)
76072+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
76073 #define pud_offset(pgd, start) (pgd)
76074 #define pud_none(pud) 0
76075 #define pud_bad(pud) 0
76076diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
76077index b7babf0..97f4c4f 100644
76078--- a/include/asm-generic/atomic-long.h
76079+++ b/include/asm-generic/atomic-long.h
76080@@ -22,6 +22,12 @@
76081
76082 typedef atomic64_t atomic_long_t;
76083
76084+#ifdef CONFIG_PAX_REFCOUNT
76085+typedef atomic64_unchecked_t atomic_long_unchecked_t;
76086+#else
76087+typedef atomic64_t atomic_long_unchecked_t;
76088+#endif
76089+
76090 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
76091
76092 static inline long atomic_long_read(atomic_long_t *l)
76093@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76094 return (long)atomic64_read(v);
76095 }
76096
76097+#ifdef CONFIG_PAX_REFCOUNT
76098+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76099+{
76100+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76101+
76102+ return (long)atomic64_read_unchecked(v);
76103+}
76104+#endif
76105+
76106 static inline void atomic_long_set(atomic_long_t *l, long i)
76107 {
76108 atomic64_t *v = (atomic64_t *)l;
76109@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76110 atomic64_set(v, i);
76111 }
76112
76113+#ifdef CONFIG_PAX_REFCOUNT
76114+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76115+{
76116+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76117+
76118+ atomic64_set_unchecked(v, i);
76119+}
76120+#endif
76121+
76122 static inline void atomic_long_inc(atomic_long_t *l)
76123 {
76124 atomic64_t *v = (atomic64_t *)l;
76125@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76126 atomic64_inc(v);
76127 }
76128
76129+#ifdef CONFIG_PAX_REFCOUNT
76130+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76131+{
76132+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76133+
76134+ atomic64_inc_unchecked(v);
76135+}
76136+#endif
76137+
76138 static inline void atomic_long_dec(atomic_long_t *l)
76139 {
76140 atomic64_t *v = (atomic64_t *)l;
76141@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76142 atomic64_dec(v);
76143 }
76144
76145+#ifdef CONFIG_PAX_REFCOUNT
76146+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76147+{
76148+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76149+
76150+ atomic64_dec_unchecked(v);
76151+}
76152+#endif
76153+
76154 static inline void atomic_long_add(long i, atomic_long_t *l)
76155 {
76156 atomic64_t *v = (atomic64_t *)l;
76157@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76158 atomic64_add(i, v);
76159 }
76160
76161+#ifdef CONFIG_PAX_REFCOUNT
76162+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76163+{
76164+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76165+
76166+ atomic64_add_unchecked(i, v);
76167+}
76168+#endif
76169+
76170 static inline void atomic_long_sub(long i, atomic_long_t *l)
76171 {
76172 atomic64_t *v = (atomic64_t *)l;
76173@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76174 atomic64_sub(i, v);
76175 }
76176
76177+#ifdef CONFIG_PAX_REFCOUNT
76178+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76179+{
76180+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76181+
76182+ atomic64_sub_unchecked(i, v);
76183+}
76184+#endif
76185+
76186 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76187 {
76188 atomic64_t *v = (atomic64_t *)l;
76189@@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
76190 return atomic64_add_negative(i, v);
76191 }
76192
76193-static inline long atomic_long_add_return(long i, atomic_long_t *l)
76194+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
76195 {
76196 atomic64_t *v = (atomic64_t *)l;
76197
76198 return (long)atomic64_add_return(i, v);
76199 }
76200
76201+#ifdef CONFIG_PAX_REFCOUNT
76202+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76203+{
76204+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76205+
76206+ return (long)atomic64_add_return_unchecked(i, v);
76207+}
76208+#endif
76209+
76210 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76211 {
76212 atomic64_t *v = (atomic64_t *)l;
76213@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76214 return (long)atomic64_inc_return(v);
76215 }
76216
76217+#ifdef CONFIG_PAX_REFCOUNT
76218+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76219+{
76220+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76221+
76222+ return (long)atomic64_inc_return_unchecked(v);
76223+}
76224+#endif
76225+
76226 static inline long atomic_long_dec_return(atomic_long_t *l)
76227 {
76228 atomic64_t *v = (atomic64_t *)l;
76229@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76230
76231 typedef atomic_t atomic_long_t;
76232
76233+#ifdef CONFIG_PAX_REFCOUNT
76234+typedef atomic_unchecked_t atomic_long_unchecked_t;
76235+#else
76236+typedef atomic_t atomic_long_unchecked_t;
76237+#endif
76238+
76239 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
76240 static inline long atomic_long_read(atomic_long_t *l)
76241 {
76242@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76243 return (long)atomic_read(v);
76244 }
76245
76246+#ifdef CONFIG_PAX_REFCOUNT
76247+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76248+{
76249+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76250+
76251+ return (long)atomic_read_unchecked(v);
76252+}
76253+#endif
76254+
76255 static inline void atomic_long_set(atomic_long_t *l, long i)
76256 {
76257 atomic_t *v = (atomic_t *)l;
76258@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76259 atomic_set(v, i);
76260 }
76261
76262+#ifdef CONFIG_PAX_REFCOUNT
76263+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76264+{
76265+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76266+
76267+ atomic_set_unchecked(v, i);
76268+}
76269+#endif
76270+
76271 static inline void atomic_long_inc(atomic_long_t *l)
76272 {
76273 atomic_t *v = (atomic_t *)l;
76274@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76275 atomic_inc(v);
76276 }
76277
76278+#ifdef CONFIG_PAX_REFCOUNT
76279+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76280+{
76281+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76282+
76283+ atomic_inc_unchecked(v);
76284+}
76285+#endif
76286+
76287 static inline void atomic_long_dec(atomic_long_t *l)
76288 {
76289 atomic_t *v = (atomic_t *)l;
76290@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76291 atomic_dec(v);
76292 }
76293
76294+#ifdef CONFIG_PAX_REFCOUNT
76295+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76296+{
76297+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76298+
76299+ atomic_dec_unchecked(v);
76300+}
76301+#endif
76302+
76303 static inline void atomic_long_add(long i, atomic_long_t *l)
76304 {
76305 atomic_t *v = (atomic_t *)l;
76306@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76307 atomic_add(i, v);
76308 }
76309
76310+#ifdef CONFIG_PAX_REFCOUNT
76311+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76312+{
76313+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76314+
76315+ atomic_add_unchecked(i, v);
76316+}
76317+#endif
76318+
76319 static inline void atomic_long_sub(long i, atomic_long_t *l)
76320 {
76321 atomic_t *v = (atomic_t *)l;
76322@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76323 atomic_sub(i, v);
76324 }
76325
76326+#ifdef CONFIG_PAX_REFCOUNT
76327+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76328+{
76329+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76330+
76331+ atomic_sub_unchecked(i, v);
76332+}
76333+#endif
76334+
76335 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76336 {
76337 atomic_t *v = (atomic_t *)l;
76338@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
76339 return (long)atomic_add_return(i, v);
76340 }
76341
76342+#ifdef CONFIG_PAX_REFCOUNT
76343+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76344+{
76345+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76346+
76347+ return (long)atomic_add_return_unchecked(i, v);
76348+}
76349+
76350+#endif
76351+
76352 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76353 {
76354 atomic_t *v = (atomic_t *)l;
76355@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76356 return (long)atomic_inc_return(v);
76357 }
76358
76359+#ifdef CONFIG_PAX_REFCOUNT
76360+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76361+{
76362+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76363+
76364+ return (long)atomic_inc_return_unchecked(v);
76365+}
76366+#endif
76367+
76368 static inline long atomic_long_dec_return(atomic_long_t *l)
76369 {
76370 atomic_t *v = (atomic_t *)l;
76371@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76372
76373 #endif /* BITS_PER_LONG == 64 */
76374
76375+#ifdef CONFIG_PAX_REFCOUNT
76376+static inline void pax_refcount_needs_these_functions(void)
76377+{
76378+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
76379+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
76380+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
76381+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
76382+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
76383+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
76384+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
76385+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
76386+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
76387+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
76388+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
76389+#ifdef CONFIG_X86
76390+ atomic_clear_mask_unchecked(0, NULL);
76391+ atomic_set_mask_unchecked(0, NULL);
76392+#endif
76393+
76394+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
76395+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
76396+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
76397+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
76398+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
76399+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
76400+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
76401+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
76402+}
76403+#else
76404+#define atomic_read_unchecked(v) atomic_read(v)
76405+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
76406+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
76407+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
76408+#define atomic_inc_unchecked(v) atomic_inc(v)
76409+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
76410+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
76411+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
76412+#define atomic_dec_unchecked(v) atomic_dec(v)
76413+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
76414+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
76415+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
76416+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
76417+
76418+#define atomic_long_read_unchecked(v) atomic_long_read(v)
76419+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
76420+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
76421+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
76422+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
76423+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
76424+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
76425+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
76426+#endif
76427+
76428 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
76429diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
76430index 33bd2de..f31bff97 100644
76431--- a/include/asm-generic/atomic.h
76432+++ b/include/asm-generic/atomic.h
76433@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
76434 * Atomically clears the bits set in @mask from @v
76435 */
76436 #ifndef atomic_clear_mask
76437-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
76438+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
76439 {
76440 unsigned long flags;
76441
76442diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
76443index b18ce4f..2ee2843 100644
76444--- a/include/asm-generic/atomic64.h
76445+++ b/include/asm-generic/atomic64.h
76446@@ -16,6 +16,8 @@ typedef struct {
76447 long long counter;
76448 } atomic64_t;
76449
76450+typedef atomic64_t atomic64_unchecked_t;
76451+
76452 #define ATOMIC64_INIT(i) { (i) }
76453
76454 extern long long atomic64_read(const atomic64_t *v);
76455@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
76456 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
76457 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
76458
76459+#define atomic64_read_unchecked(v) atomic64_read(v)
76460+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
76461+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
76462+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
76463+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
76464+#define atomic64_inc_unchecked(v) atomic64_inc(v)
76465+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
76466+#define atomic64_dec_unchecked(v) atomic64_dec(v)
76467+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
76468+
76469 #endif /* _ASM_GENERIC_ATOMIC64_H */
76470diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
76471index a60a7cc..0fe12f2 100644
76472--- a/include/asm-generic/bitops/__fls.h
76473+++ b/include/asm-generic/bitops/__fls.h
76474@@ -9,7 +9,7 @@
76475 *
76476 * Undefined if no set bit exists, so code should check against 0 first.
76477 */
76478-static __always_inline unsigned long __fls(unsigned long word)
76479+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
76480 {
76481 int num = BITS_PER_LONG - 1;
76482
76483diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
76484index 0576d1f..dad6c71 100644
76485--- a/include/asm-generic/bitops/fls.h
76486+++ b/include/asm-generic/bitops/fls.h
76487@@ -9,7 +9,7 @@
76488 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
76489 */
76490
76491-static __always_inline int fls(int x)
76492+static __always_inline int __intentional_overflow(-1) fls(int x)
76493 {
76494 int r = 32;
76495
76496diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
76497index b097cf8..3d40e14 100644
76498--- a/include/asm-generic/bitops/fls64.h
76499+++ b/include/asm-generic/bitops/fls64.h
76500@@ -15,7 +15,7 @@
76501 * at position 64.
76502 */
76503 #if BITS_PER_LONG == 32
76504-static __always_inline int fls64(__u64 x)
76505+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76506 {
76507 __u32 h = x >> 32;
76508 if (h)
76509@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
76510 return fls(x);
76511 }
76512 #elif BITS_PER_LONG == 64
76513-static __always_inline int fls64(__u64 x)
76514+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76515 {
76516 if (x == 0)
76517 return 0;
76518diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
76519index 1bfcfe5..e04c5c9 100644
76520--- a/include/asm-generic/cache.h
76521+++ b/include/asm-generic/cache.h
76522@@ -6,7 +6,7 @@
76523 * cache lines need to provide their own cache.h.
76524 */
76525
76526-#define L1_CACHE_SHIFT 5
76527-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
76528+#define L1_CACHE_SHIFT 5UL
76529+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
76530
76531 #endif /* __ASM_GENERIC_CACHE_H */
76532diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
76533index 0d68a1e..b74a761 100644
76534--- a/include/asm-generic/emergency-restart.h
76535+++ b/include/asm-generic/emergency-restart.h
76536@@ -1,7 +1,7 @@
76537 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
76538 #define _ASM_GENERIC_EMERGENCY_RESTART_H
76539
76540-static inline void machine_emergency_restart(void)
76541+static inline __noreturn void machine_emergency_restart(void)
76542 {
76543 machine_restart(NULL);
76544 }
76545diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
76546index 90f99c7..00ce236 100644
76547--- a/include/asm-generic/kmap_types.h
76548+++ b/include/asm-generic/kmap_types.h
76549@@ -2,9 +2,9 @@
76550 #define _ASM_GENERIC_KMAP_TYPES_H
76551
76552 #ifdef __WITH_KM_FENCE
76553-# define KM_TYPE_NR 41
76554+# define KM_TYPE_NR 42
76555 #else
76556-# define KM_TYPE_NR 20
76557+# define KM_TYPE_NR 21
76558 #endif
76559
76560 #endif
76561diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
76562index 9ceb03b..62b0b8f 100644
76563--- a/include/asm-generic/local.h
76564+++ b/include/asm-generic/local.h
76565@@ -23,24 +23,37 @@ typedef struct
76566 atomic_long_t a;
76567 } local_t;
76568
76569+typedef struct {
76570+ atomic_long_unchecked_t a;
76571+} local_unchecked_t;
76572+
76573 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
76574
76575 #define local_read(l) atomic_long_read(&(l)->a)
76576+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
76577 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
76578+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
76579 #define local_inc(l) atomic_long_inc(&(l)->a)
76580+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
76581 #define local_dec(l) atomic_long_dec(&(l)->a)
76582+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
76583 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
76584+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
76585 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
76586+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
76587
76588 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
76589 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
76590 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
76591 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
76592 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
76593+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
76594 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
76595 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
76596+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
76597
76598 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
76599+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
76600 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
76601 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
76602 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
76603diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
76604index 725612b..9cc513a 100644
76605--- a/include/asm-generic/pgtable-nopmd.h
76606+++ b/include/asm-generic/pgtable-nopmd.h
76607@@ -1,14 +1,19 @@
76608 #ifndef _PGTABLE_NOPMD_H
76609 #define _PGTABLE_NOPMD_H
76610
76611-#ifndef __ASSEMBLY__
76612-
76613 #include <asm-generic/pgtable-nopud.h>
76614
76615-struct mm_struct;
76616-
76617 #define __PAGETABLE_PMD_FOLDED
76618
76619+#define PMD_SHIFT PUD_SHIFT
76620+#define PTRS_PER_PMD 1
76621+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
76622+#define PMD_MASK (~(PMD_SIZE-1))
76623+
76624+#ifndef __ASSEMBLY__
76625+
76626+struct mm_struct;
76627+
76628 /*
76629 * Having the pmd type consist of a pud gets the size right, and allows
76630 * us to conceptually access the pud entry that this pmd is folded into
76631@@ -16,11 +21,6 @@ struct mm_struct;
76632 */
76633 typedef struct { pud_t pud; } pmd_t;
76634
76635-#define PMD_SHIFT PUD_SHIFT
76636-#define PTRS_PER_PMD 1
76637-#define PMD_SIZE (1UL << PMD_SHIFT)
76638-#define PMD_MASK (~(PMD_SIZE-1))
76639-
76640 /*
76641 * The "pud_xxx()" functions here are trivial for a folded two-level
76642 * setup: the pmd is never bad, and a pmd always exists (as it's folded
76643diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
76644index 810431d..0ec4804f 100644
76645--- a/include/asm-generic/pgtable-nopud.h
76646+++ b/include/asm-generic/pgtable-nopud.h
76647@@ -1,10 +1,15 @@
76648 #ifndef _PGTABLE_NOPUD_H
76649 #define _PGTABLE_NOPUD_H
76650
76651-#ifndef __ASSEMBLY__
76652-
76653 #define __PAGETABLE_PUD_FOLDED
76654
76655+#define PUD_SHIFT PGDIR_SHIFT
76656+#define PTRS_PER_PUD 1
76657+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
76658+#define PUD_MASK (~(PUD_SIZE-1))
76659+
76660+#ifndef __ASSEMBLY__
76661+
76662 /*
76663 * Having the pud type consist of a pgd gets the size right, and allows
76664 * us to conceptually access the pgd entry that this pud is folded into
76665@@ -12,11 +17,6 @@
76666 */
76667 typedef struct { pgd_t pgd; } pud_t;
76668
76669-#define PUD_SHIFT PGDIR_SHIFT
76670-#define PTRS_PER_PUD 1
76671-#define PUD_SIZE (1UL << PUD_SHIFT)
76672-#define PUD_MASK (~(PUD_SIZE-1))
76673-
76674 /*
76675 * The "pgd_xxx()" functions here are trivial for a folded two-level
76676 * setup: the pud is never bad, and a pud always exists (as it's folded
76677@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
76678 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
76679
76680 #define pgd_populate(mm, pgd, pud) do { } while (0)
76681+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
76682 /*
76683 * (puds are folded into pgds so this doesn't get actually called,
76684 * but the define is needed for a generic inline function.)
76685diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
76686index 8e4f41d..c5e9afd 100644
76687--- a/include/asm-generic/pgtable.h
76688+++ b/include/asm-generic/pgtable.h
76689@@ -748,6 +748,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
76690 }
76691 #endif /* CONFIG_NUMA_BALANCING */
76692
76693+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
76694+#ifdef CONFIG_PAX_KERNEXEC
76695+#error KERNEXEC requires pax_open_kernel
76696+#else
76697+static inline unsigned long pax_open_kernel(void) { return 0; }
76698+#endif
76699+#endif
76700+
76701+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
76702+#ifdef CONFIG_PAX_KERNEXEC
76703+#error KERNEXEC requires pax_close_kernel
76704+#else
76705+static inline unsigned long pax_close_kernel(void) { return 0; }
76706+#endif
76707+#endif
76708+
76709 #endif /* CONFIG_MMU */
76710
76711 #endif /* !__ASSEMBLY__ */
76712diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
76713index dc1269c..48a4f51 100644
76714--- a/include/asm-generic/uaccess.h
76715+++ b/include/asm-generic/uaccess.h
76716@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
76717 return __clear_user(to, n);
76718 }
76719
76720+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
76721+#ifdef CONFIG_PAX_MEMORY_UDEREF
76722+#error UDEREF requires pax_open_userland
76723+#else
76724+static inline unsigned long pax_open_userland(void) { return 0; }
76725+#endif
76726+#endif
76727+
76728+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
76729+#ifdef CONFIG_PAX_MEMORY_UDEREF
76730+#error UDEREF requires pax_close_userland
76731+#else
76732+static inline unsigned long pax_close_userland(void) { return 0; }
76733+#endif
76734+#endif
76735+
76736 #endif /* __ASM_GENERIC_UACCESS_H */
76737diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
76738index bc2121f..2f41f9a 100644
76739--- a/include/asm-generic/vmlinux.lds.h
76740+++ b/include/asm-generic/vmlinux.lds.h
76741@@ -232,6 +232,7 @@
76742 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
76743 VMLINUX_SYMBOL(__start_rodata) = .; \
76744 *(.rodata) *(.rodata.*) \
76745+ *(.data..read_only) \
76746 *(__vermagic) /* Kernel version magic */ \
76747 . = ALIGN(8); \
76748 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
76749@@ -716,17 +717,18 @@
76750 * section in the linker script will go there too. @phdr should have
76751 * a leading colon.
76752 *
76753- * Note that this macros defines __per_cpu_load as an absolute symbol.
76754+ * Note that this macros defines per_cpu_load as an absolute symbol.
76755 * If there is no need to put the percpu section at a predetermined
76756 * address, use PERCPU_SECTION.
76757 */
76758 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
76759- VMLINUX_SYMBOL(__per_cpu_load) = .; \
76760- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
76761+ per_cpu_load = .; \
76762+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
76763 - LOAD_OFFSET) { \
76764+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
76765 PERCPU_INPUT(cacheline) \
76766 } phdr \
76767- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
76768+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
76769
76770 /**
76771 * PERCPU_SECTION - define output section for percpu area, simple version
76772diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
76773index e73c19e..5b89e00 100644
76774--- a/include/crypto/algapi.h
76775+++ b/include/crypto/algapi.h
76776@@ -34,7 +34,7 @@ struct crypto_type {
76777 unsigned int maskclear;
76778 unsigned int maskset;
76779 unsigned int tfmsize;
76780-};
76781+} __do_const;
76782
76783 struct crypto_instance {
76784 struct crypto_alg alg;
76785diff --git a/include/drm/drmP.h b/include/drm/drmP.h
76786index 1d4a920..da65658 100644
76787--- a/include/drm/drmP.h
76788+++ b/include/drm/drmP.h
76789@@ -66,6 +66,7 @@
76790 #include <linux/workqueue.h>
76791 #include <linux/poll.h>
76792 #include <asm/pgalloc.h>
76793+#include <asm/local.h>
76794 #include <drm/drm.h>
76795 #include <drm/drm_sarea.h>
76796 #include <drm/drm_vma_manager.h>
76797@@ -278,10 +279,12 @@ do { \
76798 * \param cmd command.
76799 * \param arg argument.
76800 */
76801-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
76802+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
76803+ struct drm_file *file_priv);
76804+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
76805 struct drm_file *file_priv);
76806
76807-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
76808+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
76809 unsigned long arg);
76810
76811 #define DRM_IOCTL_NR(n) _IOC_NR(n)
76812@@ -297,10 +300,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
76813 struct drm_ioctl_desc {
76814 unsigned int cmd;
76815 int flags;
76816- drm_ioctl_t *func;
76817+ drm_ioctl_t func;
76818 unsigned int cmd_drv;
76819 const char *name;
76820-};
76821+} __do_const;
76822
76823 /**
76824 * Creates a driver or general drm_ioctl_desc array entry for the given
76825@@ -1013,7 +1016,8 @@ struct drm_info_list {
76826 int (*show)(struct seq_file*, void*); /** show callback */
76827 u32 driver_features; /**< Required driver features for this entry */
76828 void *data;
76829-};
76830+} __do_const;
76831+typedef struct drm_info_list __no_const drm_info_list_no_const;
76832
76833 /**
76834 * debugfs node structure. This structure represents a debugfs file.
76835@@ -1097,7 +1101,7 @@ struct drm_device {
76836
76837 /** \name Usage Counters */
76838 /*@{ */
76839- int open_count; /**< Outstanding files open */
76840+ local_t open_count; /**< Outstanding files open */
76841 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
76842 atomic_t vma_count; /**< Outstanding vma areas open */
76843 int buf_use; /**< Buffers in use -- cannot alloc */
76844diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
76845index ef6ad3a..be34b16 100644
76846--- a/include/drm/drm_crtc_helper.h
76847+++ b/include/drm/drm_crtc_helper.h
76848@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
76849 struct drm_connector *connector);
76850 /* disable encoder when not in use - more explicit than dpms off */
76851 void (*disable)(struct drm_encoder *encoder);
76852-};
76853+} __no_const;
76854
76855 /**
76856 * drm_connector_helper_funcs - helper operations for connectors
76857diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
76858index 940ece4..8cb727f 100644
76859--- a/include/drm/i915_pciids.h
76860+++ b/include/drm/i915_pciids.h
76861@@ -37,7 +37,7 @@
76862 */
76863 #define INTEL_VGA_DEVICE(id, info) { \
76864 0x8086, id, \
76865- ~0, ~0, \
76866+ PCI_ANY_ID, PCI_ANY_ID, \
76867 0x030000, 0xff0000, \
76868 (unsigned long) info }
76869
76870diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
76871index 72dcbe8..8db58d7 100644
76872--- a/include/drm/ttm/ttm_memory.h
76873+++ b/include/drm/ttm/ttm_memory.h
76874@@ -48,7 +48,7 @@
76875
76876 struct ttm_mem_shrink {
76877 int (*do_shrink) (struct ttm_mem_shrink *);
76878-};
76879+} __no_const;
76880
76881 /**
76882 * struct ttm_mem_global - Global memory accounting structure.
76883diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
76884index d1f61bf..2239439 100644
76885--- a/include/drm/ttm/ttm_page_alloc.h
76886+++ b/include/drm/ttm/ttm_page_alloc.h
76887@@ -78,6 +78,7 @@ void ttm_dma_page_alloc_fini(void);
76888 */
76889 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
76890
76891+struct device;
76892 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
76893 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
76894
76895diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
76896index 4b840e8..155d235 100644
76897--- a/include/keys/asymmetric-subtype.h
76898+++ b/include/keys/asymmetric-subtype.h
76899@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
76900 /* Verify the signature on a key of this subtype (optional) */
76901 int (*verify_signature)(const struct key *key,
76902 const struct public_key_signature *sig);
76903-};
76904+} __do_const;
76905
76906 /**
76907 * asymmetric_key_subtype - Get the subtype from an asymmetric key
76908diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
76909index c1da539..1dcec55 100644
76910--- a/include/linux/atmdev.h
76911+++ b/include/linux/atmdev.h
76912@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
76913 #endif
76914
76915 struct k_atm_aal_stats {
76916-#define __HANDLE_ITEM(i) atomic_t i
76917+#define __HANDLE_ITEM(i) atomic_unchecked_t i
76918 __AAL_STAT_ITEMS
76919 #undef __HANDLE_ITEM
76920 };
76921@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
76922 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
76923 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
76924 struct module *owner;
76925-};
76926+} __do_const ;
76927
76928 struct atmphy_ops {
76929 int (*start)(struct atm_dev *dev);
76930diff --git a/include/linux/audit.h b/include/linux/audit.h
76931index bf1ef22..2a55e1b 100644
76932--- a/include/linux/audit.h
76933+++ b/include/linux/audit.h
76934@@ -195,7 +195,7 @@ static inline void audit_ptrace(struct task_struct *t)
76935 extern unsigned int audit_serial(void);
76936 extern int auditsc_get_stamp(struct audit_context *ctx,
76937 struct timespec *t, unsigned int *serial);
76938-extern int audit_set_loginuid(kuid_t loginuid);
76939+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
76940
76941 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
76942 {
76943diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
76944index fd8bf32..49a5f5c 100644
76945--- a/include/linux/binfmts.h
76946+++ b/include/linux/binfmts.h
76947@@ -45,7 +45,7 @@ struct linux_binprm {
76948 unsigned interp_data;
76949 unsigned long loader, exec;
76950 char tcomm[TASK_COMM_LEN];
76951-};
76952+} __randomize_layout;
76953
76954 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
76955 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
76956@@ -74,8 +74,10 @@ struct linux_binfmt {
76957 int (*load_binary)(struct linux_binprm *);
76958 int (*load_shlib)(struct file *);
76959 int (*core_dump)(struct coredump_params *cprm);
76960+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
76961+ void (*handle_mmap)(struct file *);
76962 unsigned long min_coredump; /* minimal dump size */
76963-};
76964+} __do_const __randomize_layout;
76965
76966 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
76967
76968diff --git a/include/linux/bitops.h b/include/linux/bitops.h
76969index be5fd38..d71192a 100644
76970--- a/include/linux/bitops.h
76971+++ b/include/linux/bitops.h
76972@@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
76973 * @word: value to rotate
76974 * @shift: bits to roll
76975 */
76976-static inline __u32 rol32(__u32 word, unsigned int shift)
76977+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
76978 {
76979 return (word << shift) | (word >> (32 - shift));
76980 }
76981@@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
76982 * @word: value to rotate
76983 * @shift: bits to roll
76984 */
76985-static inline __u32 ror32(__u32 word, unsigned int shift)
76986+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
76987 {
76988 return (word >> shift) | (word << (32 - shift));
76989 }
76990@@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
76991 return (__s32)(value << shift) >> shift;
76992 }
76993
76994-static inline unsigned fls_long(unsigned long l)
76995+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
76996 {
76997 if (sizeof(l) == 4)
76998 return fls(l);
76999diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
77000index 1b135d4..59fc876 100644
77001--- a/include/linux/blkdev.h
77002+++ b/include/linux/blkdev.h
77003@@ -1578,7 +1578,7 @@ struct block_device_operations {
77004 /* this callback is with swap_lock and sometimes page table lock held */
77005 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
77006 struct module *owner;
77007-};
77008+} __do_const;
77009
77010 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
77011 unsigned long);
77012diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
77013index afc1343..9735539 100644
77014--- a/include/linux/blktrace_api.h
77015+++ b/include/linux/blktrace_api.h
77016@@ -25,7 +25,7 @@ struct blk_trace {
77017 struct dentry *dropped_file;
77018 struct dentry *msg_file;
77019 struct list_head running_list;
77020- atomic_t dropped;
77021+ atomic_unchecked_t dropped;
77022 };
77023
77024 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
77025diff --git a/include/linux/cache.h b/include/linux/cache.h
77026index 4c57065..40346da 100644
77027--- a/include/linux/cache.h
77028+++ b/include/linux/cache.h
77029@@ -16,6 +16,14 @@
77030 #define __read_mostly
77031 #endif
77032
77033+#ifndef __read_only
77034+#ifdef CONFIG_PAX_KERNEXEC
77035+#error KERNEXEC requires __read_only
77036+#else
77037+#define __read_only __read_mostly
77038+#endif
77039+#endif
77040+
77041 #ifndef ____cacheline_aligned
77042 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
77043 #endif
77044diff --git a/include/linux/capability.h b/include/linux/capability.h
77045index a6ee1f9..e1ca49d 100644
77046--- a/include/linux/capability.h
77047+++ b/include/linux/capability.h
77048@@ -212,8 +212,13 @@ extern bool capable(int cap);
77049 extern bool ns_capable(struct user_namespace *ns, int cap);
77050 extern bool inode_capable(const struct inode *inode, int cap);
77051 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
77052+extern bool capable_nolog(int cap);
77053+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
77054+extern bool inode_capable_nolog(const struct inode *inode, int cap);
77055
77056 /* audit system wants to get cap info from files as well */
77057 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
77058
77059+extern int is_privileged_binary(const struct dentry *dentry);
77060+
77061 #endif /* !_LINUX_CAPABILITY_H */
77062diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
77063index 8609d57..86e4d79 100644
77064--- a/include/linux/cdrom.h
77065+++ b/include/linux/cdrom.h
77066@@ -87,7 +87,6 @@ struct cdrom_device_ops {
77067
77068 /* driver specifications */
77069 const int capability; /* capability flags */
77070- int n_minors; /* number of active minor devices */
77071 /* handle uniform packets for scsi type devices (scsi,atapi) */
77072 int (*generic_packet) (struct cdrom_device_info *,
77073 struct packet_command *);
77074diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
77075index 4ce9056..86caac6 100644
77076--- a/include/linux/cleancache.h
77077+++ b/include/linux/cleancache.h
77078@@ -31,7 +31,7 @@ struct cleancache_ops {
77079 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
77080 void (*invalidate_inode)(int, struct cleancache_filekey);
77081 void (*invalidate_fs)(int);
77082-};
77083+} __no_const;
77084
77085 extern struct cleancache_ops *
77086 cleancache_register_ops(struct cleancache_ops *ops);
77087diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
77088index 7e59253..d6e4cae 100644
77089--- a/include/linux/clk-provider.h
77090+++ b/include/linux/clk-provider.h
77091@@ -141,6 +141,7 @@ struct clk_ops {
77092 unsigned long);
77093 void (*init)(struct clk_hw *hw);
77094 };
77095+typedef struct clk_ops __no_const clk_ops_no_const;
77096
77097 /**
77098 * struct clk_init_data - holds init data that's common to all clocks and is
77099diff --git a/include/linux/compat.h b/include/linux/compat.h
77100index 19f6003..90b64f4 100644
77101--- a/include/linux/compat.h
77102+++ b/include/linux/compat.h
77103@@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
77104 compat_size_t __user *len_ptr);
77105
77106 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
77107-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
77108+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
77109 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
77110 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
77111 compat_ssize_t msgsz, int msgflg);
77112@@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
77113 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
77114 compat_ulong_t addr, compat_ulong_t data);
77115 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77116- compat_long_t addr, compat_long_t data);
77117+ compat_ulong_t addr, compat_ulong_t data);
77118
77119 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
77120 /*
77121diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
77122index 2507fd2..55203f8 100644
77123--- a/include/linux/compiler-gcc4.h
77124+++ b/include/linux/compiler-gcc4.h
77125@@ -39,9 +39,34 @@
77126 # define __compiletime_warning(message) __attribute__((warning(message)))
77127 # define __compiletime_error(message) __attribute__((error(message)))
77128 #endif /* __CHECKER__ */
77129+
77130+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
77131+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
77132+#define __bos0(ptr) __bos((ptr), 0)
77133+#define __bos1(ptr) __bos((ptr), 1)
77134 #endif /* GCC_VERSION >= 40300 */
77135
77136 #if GCC_VERSION >= 40500
77137+
77138+#ifdef RANDSTRUCT_PLUGIN
77139+#define __randomize_layout __attribute__((randomize_layout))
77140+#define __no_randomize_layout __attribute__((no_randomize_layout))
77141+#endif
77142+
77143+#ifdef CONSTIFY_PLUGIN
77144+#define __no_const __attribute__((no_const))
77145+#define __do_const __attribute__((do_const))
77146+#endif
77147+
77148+#ifdef SIZE_OVERFLOW_PLUGIN
77149+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
77150+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
77151+#endif
77152+
77153+#ifdef LATENT_ENTROPY_PLUGIN
77154+#define __latent_entropy __attribute__((latent_entropy))
77155+#endif
77156+
77157 /*
77158 * Mark a position in code as unreachable. This can be used to
77159 * suppress control flow warnings after asm blocks that transfer
77160diff --git a/include/linux/compiler.h b/include/linux/compiler.h
77161index 92669cd..cc564c0 100644
77162--- a/include/linux/compiler.h
77163+++ b/include/linux/compiler.h
77164@@ -5,11 +5,14 @@
77165
77166 #ifdef __CHECKER__
77167 # define __user __attribute__((noderef, address_space(1)))
77168+# define __force_user __force __user
77169 # define __kernel __attribute__((address_space(0)))
77170+# define __force_kernel __force __kernel
77171 # define __safe __attribute__((safe))
77172 # define __force __attribute__((force))
77173 # define __nocast __attribute__((nocast))
77174 # define __iomem __attribute__((noderef, address_space(2)))
77175+# define __force_iomem __force __iomem
77176 # define __must_hold(x) __attribute__((context(x,1,1)))
77177 # define __acquires(x) __attribute__((context(x,0,1)))
77178 # define __releases(x) __attribute__((context(x,1,0)))
77179@@ -17,20 +20,37 @@
77180 # define __release(x) __context__(x,-1)
77181 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
77182 # define __percpu __attribute__((noderef, address_space(3)))
77183+# define __force_percpu __force __percpu
77184 #ifdef CONFIG_SPARSE_RCU_POINTER
77185 # define __rcu __attribute__((noderef, address_space(4)))
77186+# define __force_rcu __force __rcu
77187 #else
77188 # define __rcu
77189+# define __force_rcu
77190 #endif
77191 extern void __chk_user_ptr(const volatile void __user *);
77192 extern void __chk_io_ptr(const volatile void __iomem *);
77193 #else
77194-# define __user
77195-# define __kernel
77196+# ifdef CHECKER_PLUGIN
77197+//# define __user
77198+//# define __force_user
77199+//# define __kernel
77200+//# define __force_kernel
77201+# else
77202+# ifdef STRUCTLEAK_PLUGIN
77203+# define __user __attribute__((user))
77204+# else
77205+# define __user
77206+# endif
77207+# define __force_user
77208+# define __kernel
77209+# define __force_kernel
77210+# endif
77211 # define __safe
77212 # define __force
77213 # define __nocast
77214 # define __iomem
77215+# define __force_iomem
77216 # define __chk_user_ptr(x) (void)0
77217 # define __chk_io_ptr(x) (void)0
77218 # define __builtin_warning(x, y...) (1)
77219@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
77220 # define __release(x) (void)0
77221 # define __cond_lock(x,c) (c)
77222 # define __percpu
77223+# define __force_percpu
77224 # define __rcu
77225+# define __force_rcu
77226 #endif
77227
77228 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
77229@@ -275,6 +297,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77230 # define __attribute_const__ /* unimplemented */
77231 #endif
77232
77233+#ifndef __randomize_layout
77234+# define __randomize_layout
77235+#endif
77236+
77237+#ifndef __no_randomize_layout
77238+# define __no_randomize_layout
77239+#endif
77240+
77241+#ifndef __no_const
77242+# define __no_const
77243+#endif
77244+
77245+#ifndef __do_const
77246+# define __do_const
77247+#endif
77248+
77249+#ifndef __size_overflow
77250+# define __size_overflow(...)
77251+#endif
77252+
77253+#ifndef __intentional_overflow
77254+# define __intentional_overflow(...)
77255+#endif
77256+
77257+#ifndef __latent_entropy
77258+# define __latent_entropy
77259+#endif
77260+
77261 /*
77262 * Tell gcc if a function is cold. The compiler will assume any path
77263 * directly leading to the call is unlikely.
77264@@ -284,6 +334,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77265 #define __cold
77266 #endif
77267
77268+#ifndef __alloc_size
77269+#define __alloc_size(...)
77270+#endif
77271+
77272+#ifndef __bos
77273+#define __bos(ptr, arg)
77274+#endif
77275+
77276+#ifndef __bos0
77277+#define __bos0(ptr)
77278+#endif
77279+
77280+#ifndef __bos1
77281+#define __bos1(ptr)
77282+#endif
77283+
77284 /* Simple shorthand for a section definition */
77285 #ifndef __section
77286 # define __section(S) __attribute__ ((__section__(#S)))
77287@@ -349,7 +415,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77288 * use is to mediate communication between process-level code and irq/NMI
77289 * handlers, all running on the same CPU.
77290 */
77291-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
77292+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
77293+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
77294
77295 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
77296 #ifdef CONFIG_KPROBES
77297diff --git a/include/linux/completion.h b/include/linux/completion.h
77298index 5d5aaae..0ea9b84 100644
77299--- a/include/linux/completion.h
77300+++ b/include/linux/completion.h
77301@@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
77302
77303 extern void wait_for_completion(struct completion *);
77304 extern void wait_for_completion_io(struct completion *);
77305-extern int wait_for_completion_interruptible(struct completion *x);
77306-extern int wait_for_completion_killable(struct completion *x);
77307+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
77308+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
77309 extern unsigned long wait_for_completion_timeout(struct completion *x,
77310- unsigned long timeout);
77311+ unsigned long timeout) __intentional_overflow(-1);
77312 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
77313- unsigned long timeout);
77314+ unsigned long timeout) __intentional_overflow(-1);
77315 extern long wait_for_completion_interruptible_timeout(
77316- struct completion *x, unsigned long timeout);
77317+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77318 extern long wait_for_completion_killable_timeout(
77319- struct completion *x, unsigned long timeout);
77320+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77321 extern bool try_wait_for_completion(struct completion *x);
77322 extern bool completion_done(struct completion *x);
77323
77324diff --git a/include/linux/configfs.h b/include/linux/configfs.h
77325index 34025df..d94bbbc 100644
77326--- a/include/linux/configfs.h
77327+++ b/include/linux/configfs.h
77328@@ -125,7 +125,7 @@ struct configfs_attribute {
77329 const char *ca_name;
77330 struct module *ca_owner;
77331 umode_t ca_mode;
77332-};
77333+} __do_const;
77334
77335 /*
77336 * Users often need to create attribute structures for their configurable
77337diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
77338index dc196bb..c55a50f 100644
77339--- a/include/linux/cpufreq.h
77340+++ b/include/linux/cpufreq.h
77341@@ -189,6 +189,7 @@ struct global_attr {
77342 ssize_t (*store)(struct kobject *a, struct attribute *b,
77343 const char *c, size_t count);
77344 };
77345+typedef struct global_attr __no_const global_attr_no_const;
77346
77347 #define define_one_global_ro(_name) \
77348 static struct global_attr _name = \
77349@@ -225,7 +226,7 @@ struct cpufreq_driver {
77350 int (*suspend) (struct cpufreq_policy *policy);
77351 int (*resume) (struct cpufreq_policy *policy);
77352 struct freq_attr **attr;
77353-};
77354+} __do_const;
77355
77356 /* flags */
77357 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
77358diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
77359index 50fcbb0..9d2dbd9 100644
77360--- a/include/linux/cpuidle.h
77361+++ b/include/linux/cpuidle.h
77362@@ -50,7 +50,8 @@ struct cpuidle_state {
77363 int index);
77364
77365 int (*enter_dead) (struct cpuidle_device *dev, int index);
77366-};
77367+} __do_const;
77368+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
77369
77370 /* Idle State Flags */
77371 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
77372@@ -192,7 +193,7 @@ struct cpuidle_governor {
77373 void (*reflect) (struct cpuidle_device *dev, int index);
77374
77375 struct module *owner;
77376-};
77377+} __do_const;
77378
77379 #ifdef CONFIG_CPU_IDLE
77380 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
77381diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
77382index d08e4d2..95fad61 100644
77383--- a/include/linux/cpumask.h
77384+++ b/include/linux/cpumask.h
77385@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77386 }
77387
77388 /* Valid inputs for n are -1 and 0. */
77389-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77390+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77391 {
77392 return n+1;
77393 }
77394
77395-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77396+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77397 {
77398 return n+1;
77399 }
77400
77401-static inline unsigned int cpumask_next_and(int n,
77402+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
77403 const struct cpumask *srcp,
77404 const struct cpumask *andp)
77405 {
77406@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77407 *
77408 * Returns >= nr_cpu_ids if no further cpus set.
77409 */
77410-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77411+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77412 {
77413 /* -1 is a legal arg here. */
77414 if (n != -1)
77415@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77416 *
77417 * Returns >= nr_cpu_ids if no further cpus unset.
77418 */
77419-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77420+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77421 {
77422 /* -1 is a legal arg here. */
77423 if (n != -1)
77424@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77425 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
77426 }
77427
77428-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
77429+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
77430 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
77431
77432 /**
77433diff --git a/include/linux/cred.h b/include/linux/cred.h
77434index 04421e8..117e17a 100644
77435--- a/include/linux/cred.h
77436+++ b/include/linux/cred.h
77437@@ -35,7 +35,7 @@ struct group_info {
77438 int nblocks;
77439 kgid_t small_block[NGROUPS_SMALL];
77440 kgid_t *blocks[0];
77441-};
77442+} __randomize_layout;
77443
77444 /**
77445 * get_group_info - Get a reference to a group info structure
77446@@ -136,7 +136,7 @@ struct cred {
77447 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
77448 struct group_info *group_info; /* supplementary groups for euid/fsgid */
77449 struct rcu_head rcu; /* RCU deletion hook */
77450-};
77451+} __randomize_layout;
77452
77453 extern void __put_cred(struct cred *);
77454 extern void exit_creds(struct task_struct *);
77455@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
77456 static inline void validate_process_creds(void)
77457 {
77458 }
77459+static inline void validate_task_creds(struct task_struct *task)
77460+{
77461+}
77462 #endif
77463
77464 /**
77465diff --git a/include/linux/crypto.h b/include/linux/crypto.h
77466index b92eadf..b4ecdc1 100644
77467--- a/include/linux/crypto.h
77468+++ b/include/linux/crypto.h
77469@@ -373,7 +373,7 @@ struct cipher_tfm {
77470 const u8 *key, unsigned int keylen);
77471 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77472 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77473-};
77474+} __no_const;
77475
77476 struct hash_tfm {
77477 int (*init)(struct hash_desc *desc);
77478@@ -394,13 +394,13 @@ struct compress_tfm {
77479 int (*cot_decompress)(struct crypto_tfm *tfm,
77480 const u8 *src, unsigned int slen,
77481 u8 *dst, unsigned int *dlen);
77482-};
77483+} __no_const;
77484
77485 struct rng_tfm {
77486 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
77487 unsigned int dlen);
77488 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
77489-};
77490+} __no_const;
77491
77492 #define crt_ablkcipher crt_u.ablkcipher
77493 #define crt_aead crt_u.aead
77494diff --git a/include/linux/ctype.h b/include/linux/ctype.h
77495index 653589e..4ef254a 100644
77496--- a/include/linux/ctype.h
77497+++ b/include/linux/ctype.h
77498@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
77499 * Fast implementation of tolower() for internal usage. Do not use in your
77500 * code.
77501 */
77502-static inline char _tolower(const char c)
77503+static inline unsigned char _tolower(const unsigned char c)
77504 {
77505 return c | 0x20;
77506 }
77507diff --git a/include/linux/dcache.h b/include/linux/dcache.h
77508index bf72e9a..4ca7927 100644
77509--- a/include/linux/dcache.h
77510+++ b/include/linux/dcache.h
77511@@ -133,7 +133,7 @@ struct dentry {
77512 } d_u;
77513 struct list_head d_subdirs; /* our children */
77514 struct hlist_node d_alias; /* inode alias list */
77515-};
77516+} __randomize_layout;
77517
77518 /*
77519 * dentry->d_lock spinlock nesting subclasses:
77520diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
77521index 7925bf0..d5143d2 100644
77522--- a/include/linux/decompress/mm.h
77523+++ b/include/linux/decompress/mm.h
77524@@ -77,7 +77,7 @@ static void free(void *where)
77525 * warnings when not needed (indeed large_malloc / large_free are not
77526 * needed by inflate */
77527
77528-#define malloc(a) kmalloc(a, GFP_KERNEL)
77529+#define malloc(a) kmalloc((a), GFP_KERNEL)
77530 #define free(a) kfree(a)
77531
77532 #define large_malloc(a) vmalloc(a)
77533diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
77534index d48dc00..211ee54 100644
77535--- a/include/linux/devfreq.h
77536+++ b/include/linux/devfreq.h
77537@@ -114,7 +114,7 @@ struct devfreq_governor {
77538 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
77539 int (*event_handler)(struct devfreq *devfreq,
77540 unsigned int event, void *data);
77541-};
77542+} __do_const;
77543
77544 /**
77545 * struct devfreq - Device devfreq structure
77546diff --git a/include/linux/device.h b/include/linux/device.h
77547index 952b010..d5b7691 100644
77548--- a/include/linux/device.h
77549+++ b/include/linux/device.h
77550@@ -310,7 +310,7 @@ struct subsys_interface {
77551 struct list_head node;
77552 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
77553 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
77554-};
77555+} __do_const;
77556
77557 int subsys_interface_register(struct subsys_interface *sif);
77558 void subsys_interface_unregister(struct subsys_interface *sif);
77559@@ -506,7 +506,7 @@ struct device_type {
77560 void (*release)(struct device *dev);
77561
77562 const struct dev_pm_ops *pm;
77563-};
77564+} __do_const;
77565
77566 /* interface for exporting device attributes */
77567 struct device_attribute {
77568@@ -516,11 +516,12 @@ struct device_attribute {
77569 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
77570 const char *buf, size_t count);
77571 };
77572+typedef struct device_attribute __no_const device_attribute_no_const;
77573
77574 struct dev_ext_attribute {
77575 struct device_attribute attr;
77576 void *var;
77577-};
77578+} __do_const;
77579
77580 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
77581 char *buf);
77582diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
77583index fd4aee2..1f28db9 100644
77584--- a/include/linux/dma-mapping.h
77585+++ b/include/linux/dma-mapping.h
77586@@ -54,7 +54,7 @@ struct dma_map_ops {
77587 u64 (*get_required_mask)(struct device *dev);
77588 #endif
77589 int is_phys;
77590-};
77591+} __do_const;
77592
77593 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
77594
77595diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
77596index 41cf0c3..f3b771c 100644
77597--- a/include/linux/dmaengine.h
77598+++ b/include/linux/dmaengine.h
77599@@ -1114,9 +1114,9 @@ struct dma_pinned_list {
77600 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
77601 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
77602
77603-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
77604+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
77605 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
77606-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
77607+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
77608 struct dma_pinned_list *pinned_list, struct page *page,
77609 unsigned int offset, size_t len);
77610
77611diff --git a/include/linux/efi.h b/include/linux/efi.h
77612index 11ce678..7b8c69c 100644
77613--- a/include/linux/efi.h
77614+++ b/include/linux/efi.h
77615@@ -764,6 +764,7 @@ struct efivar_operations {
77616 efi_set_variable_t *set_variable;
77617 efi_query_variable_store_t *query_variable_store;
77618 };
77619+typedef struct efivar_operations __no_const efivar_operations_no_const;
77620
77621 struct efivars {
77622 /*
77623diff --git a/include/linux/elf.h b/include/linux/elf.h
77624index 67a5fa7..b817372 100644
77625--- a/include/linux/elf.h
77626+++ b/include/linux/elf.h
77627@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
77628 #define elf_note elf32_note
77629 #define elf_addr_t Elf32_Off
77630 #define Elf_Half Elf32_Half
77631+#define elf_dyn Elf32_Dyn
77632
77633 #else
77634
77635@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
77636 #define elf_note elf64_note
77637 #define elf_addr_t Elf64_Off
77638 #define Elf_Half Elf64_Half
77639+#define elf_dyn Elf64_Dyn
77640
77641 #endif
77642
77643diff --git a/include/linux/err.h b/include/linux/err.h
77644index 15f92e0..e825a8e 100644
77645--- a/include/linux/err.h
77646+++ b/include/linux/err.h
77647@@ -19,12 +19,12 @@
77648
77649 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
77650
77651-static inline void * __must_check ERR_PTR(long error)
77652+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
77653 {
77654 return (void *) error;
77655 }
77656
77657-static inline long __must_check PTR_ERR(__force const void *ptr)
77658+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
77659 {
77660 return (long) ptr;
77661 }
77662diff --git a/include/linux/extcon.h b/include/linux/extcon.h
77663index 21c59af..6057a03 100644
77664--- a/include/linux/extcon.h
77665+++ b/include/linux/extcon.h
77666@@ -135,7 +135,7 @@ struct extcon_dev {
77667 /* /sys/class/extcon/.../mutually_exclusive/... */
77668 struct attribute_group attr_g_muex;
77669 struct attribute **attrs_muex;
77670- struct device_attribute *d_attrs_muex;
77671+ device_attribute_no_const *d_attrs_muex;
77672 };
77673
77674 /**
77675diff --git a/include/linux/fb.h b/include/linux/fb.h
77676index 70c4836..ff3daec 100644
77677--- a/include/linux/fb.h
77678+++ b/include/linux/fb.h
77679@@ -304,7 +304,7 @@ struct fb_ops {
77680 /* called at KDB enter and leave time to prepare the console */
77681 int (*fb_debug_enter)(struct fb_info *info);
77682 int (*fb_debug_leave)(struct fb_info *info);
77683-};
77684+} __do_const;
77685
77686 #ifdef CONFIG_FB_TILEBLITTING
77687 #define FB_TILE_CURSOR_NONE 0
77688diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
77689index 085197b..0fa6f0b 100644
77690--- a/include/linux/fdtable.h
77691+++ b/include/linux/fdtable.h
77692@@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
77693 void put_files_struct(struct files_struct *fs);
77694 void reset_files_struct(struct files_struct *);
77695 int unshare_files(struct files_struct **);
77696-struct files_struct *dup_fd(struct files_struct *, int *);
77697+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
77698 void do_close_on_exec(struct files_struct *);
77699 int iterate_fd(struct files_struct *, unsigned,
77700 int (*)(const void *, struct file *, unsigned),
77701diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
77702index 8293262..2b3b8bd 100644
77703--- a/include/linux/frontswap.h
77704+++ b/include/linux/frontswap.h
77705@@ -11,7 +11,7 @@ struct frontswap_ops {
77706 int (*load)(unsigned, pgoff_t, struct page *);
77707 void (*invalidate_page)(unsigned, pgoff_t);
77708 void (*invalidate_area)(unsigned);
77709-};
77710+} __no_const;
77711
77712 extern bool frontswap_enabled;
77713 extern struct frontswap_ops *
77714diff --git a/include/linux/fs.h b/include/linux/fs.h
77715index 121f11f..0f2a863 100644
77716--- a/include/linux/fs.h
77717+++ b/include/linux/fs.h
77718@@ -423,7 +423,7 @@ struct address_space {
77719 spinlock_t private_lock; /* for use by the address_space */
77720 struct list_head private_list; /* ditto */
77721 void *private_data; /* ditto */
77722-} __attribute__((aligned(sizeof(long))));
77723+} __attribute__((aligned(sizeof(long)))) __randomize_layout;
77724 /*
77725 * On most architectures that alignment is already the case; but
77726 * must be enforced here for CRIS, to let the least significant bit
77727@@ -466,7 +466,7 @@ struct block_device {
77728 int bd_fsfreeze_count;
77729 /* Mutex for freeze */
77730 struct mutex bd_fsfreeze_mutex;
77731-};
77732+} __randomize_layout;
77733
77734 /*
77735 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
77736@@ -610,7 +610,7 @@ struct inode {
77737 atomic_t i_readcount; /* struct files open RO */
77738 #endif
77739 void *i_private; /* fs or device private pointer */
77740-};
77741+} __randomize_layout;
77742
77743 static inline int inode_unhashed(struct inode *inode)
77744 {
77745@@ -808,7 +808,7 @@ struct file {
77746 #ifdef CONFIG_DEBUG_WRITECOUNT
77747 unsigned long f_mnt_write_state;
77748 #endif
77749-};
77750+} __randomize_layout;
77751
77752 struct file_handle {
77753 __u32 handle_bytes;
77754@@ -978,7 +978,7 @@ struct file_lock {
77755 int state; /* state of grant or error if -ve */
77756 } afs;
77757 } fl_u;
77758-};
77759+} __randomize_layout;
77760
77761 /* The following constant reflects the upper bound of the file/locking space */
77762 #ifndef OFFSET_MAX
77763@@ -1325,7 +1325,7 @@ struct super_block {
77764 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
77765 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
77766 struct rcu_head rcu;
77767-};
77768+} __randomize_layout;
77769
77770 extern struct timespec current_fs_time(struct super_block *sb);
77771
77772@@ -1547,7 +1547,8 @@ struct file_operations {
77773 long (*fallocate)(struct file *file, int mode, loff_t offset,
77774 loff_t len);
77775 int (*show_fdinfo)(struct seq_file *m, struct file *f);
77776-};
77777+} __do_const __randomize_layout;
77778+typedef struct file_operations __no_const file_operations_no_const;
77779
77780 struct inode_operations {
77781 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
77782@@ -2808,4 +2809,14 @@ static inline bool dir_relax(struct inode *inode)
77783 return !IS_DEADDIR(inode);
77784 }
77785
77786+static inline bool is_sidechannel_device(const struct inode *inode)
77787+{
77788+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
77789+ umode_t mode = inode->i_mode;
77790+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
77791+#else
77792+ return false;
77793+#endif
77794+}
77795+
77796 #endif /* _LINUX_FS_H */
77797diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
77798index 0efc3e6..fd23610 100644
77799--- a/include/linux/fs_struct.h
77800+++ b/include/linux/fs_struct.h
77801@@ -6,13 +6,13 @@
77802 #include <linux/seqlock.h>
77803
77804 struct fs_struct {
77805- int users;
77806+ atomic_t users;
77807 spinlock_t lock;
77808 seqcount_t seq;
77809 int umask;
77810 int in_exec;
77811 struct path root, pwd;
77812-};
77813+} __randomize_layout;
77814
77815 extern struct kmem_cache *fs_cachep;
77816
77817diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
77818index 7714849..a4a5c7a 100644
77819--- a/include/linux/fscache-cache.h
77820+++ b/include/linux/fscache-cache.h
77821@@ -113,7 +113,7 @@ struct fscache_operation {
77822 fscache_operation_release_t release;
77823 };
77824
77825-extern atomic_t fscache_op_debug_id;
77826+extern atomic_unchecked_t fscache_op_debug_id;
77827 extern void fscache_op_work_func(struct work_struct *work);
77828
77829 extern void fscache_enqueue_operation(struct fscache_operation *);
77830@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
77831 INIT_WORK(&op->work, fscache_op_work_func);
77832 atomic_set(&op->usage, 1);
77833 op->state = FSCACHE_OP_ST_INITIALISED;
77834- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
77835+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
77836 op->processor = processor;
77837 op->release = release;
77838 INIT_LIST_HEAD(&op->pend_link);
77839diff --git a/include/linux/fscache.h b/include/linux/fscache.h
77840index 115bb81..e7b812b 100644
77841--- a/include/linux/fscache.h
77842+++ b/include/linux/fscache.h
77843@@ -152,7 +152,7 @@ struct fscache_cookie_def {
77844 * - this is mandatory for any object that may have data
77845 */
77846 void (*now_uncached)(void *cookie_netfs_data);
77847-};
77848+} __do_const;
77849
77850 /*
77851 * fscache cached network filesystem type
77852diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
77853index 1c804b0..1432c2b 100644
77854--- a/include/linux/fsnotify.h
77855+++ b/include/linux/fsnotify.h
77856@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
77857 struct inode *inode = file_inode(file);
77858 __u32 mask = FS_ACCESS;
77859
77860+ if (is_sidechannel_device(inode))
77861+ return;
77862+
77863 if (S_ISDIR(inode->i_mode))
77864 mask |= FS_ISDIR;
77865
77866@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
77867 struct inode *inode = file_inode(file);
77868 __u32 mask = FS_MODIFY;
77869
77870+ if (is_sidechannel_device(inode))
77871+ return;
77872+
77873 if (S_ISDIR(inode->i_mode))
77874 mask |= FS_ISDIR;
77875
77876@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
77877 */
77878 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
77879 {
77880- return kstrdup(name, GFP_KERNEL);
77881+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
77882 }
77883
77884 /*
77885diff --git a/include/linux/genhd.h b/include/linux/genhd.h
77886index 9f3c275..8bdff5d 100644
77887--- a/include/linux/genhd.h
77888+++ b/include/linux/genhd.h
77889@@ -194,7 +194,7 @@ struct gendisk {
77890 struct kobject *slave_dir;
77891
77892 struct timer_rand_state *random;
77893- atomic_t sync_io; /* RAID */
77894+ atomic_unchecked_t sync_io; /* RAID */
77895 struct disk_events *ev;
77896 #ifdef CONFIG_BLK_DEV_INTEGRITY
77897 struct blk_integrity *integrity;
77898@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
77899 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
77900
77901 /* drivers/char/random.c */
77902-extern void add_disk_randomness(struct gendisk *disk);
77903+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
77904 extern void rand_initialize_disk(struct gendisk *disk);
77905
77906 static inline sector_t get_start_sect(struct block_device *bdev)
77907diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
77908index c0894dd..2fbf10c 100644
77909--- a/include/linux/genl_magic_func.h
77910+++ b/include/linux/genl_magic_func.h
77911@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
77912 },
77913
77914 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
77915-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
77916+static struct genl_ops ZZZ_genl_ops[] = {
77917 #include GENL_MAGIC_INCLUDE_FILE
77918 };
77919
77920diff --git a/include/linux/gfp.h b/include/linux/gfp.h
77921index 9b4dd49..61fd41d 100644
77922--- a/include/linux/gfp.h
77923+++ b/include/linux/gfp.h
77924@@ -35,6 +35,13 @@ struct vm_area_struct;
77925 #define ___GFP_NO_KSWAPD 0x400000u
77926 #define ___GFP_OTHER_NODE 0x800000u
77927 #define ___GFP_WRITE 0x1000000u
77928+
77929+#ifdef CONFIG_PAX_USERCOPY_SLABS
77930+#define ___GFP_USERCOPY 0x2000000u
77931+#else
77932+#define ___GFP_USERCOPY 0
77933+#endif
77934+
77935 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
77936
77937 /*
77938@@ -92,6 +99,7 @@ struct vm_area_struct;
77939 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
77940 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
77941 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
77942+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
77943
77944 /*
77945 * This may seem redundant, but it's a way of annotating false positives vs.
77946@@ -99,7 +107,7 @@ struct vm_area_struct;
77947 */
77948 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
77949
77950-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
77951+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
77952 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
77953
77954 /* This equals 0, but use constants in case they ever change */
77955@@ -153,6 +161,8 @@ struct vm_area_struct;
77956 /* 4GB DMA on some platforms */
77957 #define GFP_DMA32 __GFP_DMA32
77958
77959+#define GFP_USERCOPY __GFP_USERCOPY
77960+
77961 /* Convert GFP flags to their corresponding migrate type */
77962 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
77963 {
77964diff --git a/include/linux/gracl.h b/include/linux/gracl.h
77965new file mode 100644
77966index 0000000..edb2cb6
77967--- /dev/null
77968+++ b/include/linux/gracl.h
77969@@ -0,0 +1,340 @@
77970+#ifndef GR_ACL_H
77971+#define GR_ACL_H
77972+
77973+#include <linux/grdefs.h>
77974+#include <linux/resource.h>
77975+#include <linux/capability.h>
77976+#include <linux/dcache.h>
77977+#include <asm/resource.h>
77978+
77979+/* Major status information */
77980+
77981+#define GR_VERSION "grsecurity 3.0"
77982+#define GRSECURITY_VERSION 0x3000
77983+
77984+enum {
77985+ GR_SHUTDOWN = 0,
77986+ GR_ENABLE = 1,
77987+ GR_SPROLE = 2,
77988+ GR_OLDRELOAD = 3,
77989+ GR_SEGVMOD = 4,
77990+ GR_STATUS = 5,
77991+ GR_UNSPROLE = 6,
77992+ GR_PASSSET = 7,
77993+ GR_SPROLEPAM = 8,
77994+ GR_RELOAD = 9,
77995+};
77996+
77997+/* Password setup definitions
77998+ * kernel/grhash.c */
77999+enum {
78000+ GR_PW_LEN = 128,
78001+ GR_SALT_LEN = 16,
78002+ GR_SHA_LEN = 32,
78003+};
78004+
78005+enum {
78006+ GR_SPROLE_LEN = 64,
78007+};
78008+
78009+enum {
78010+ GR_NO_GLOB = 0,
78011+ GR_REG_GLOB,
78012+ GR_CREATE_GLOB
78013+};
78014+
78015+#define GR_NLIMITS 32
78016+
78017+/* Begin Data Structures */
78018+
78019+struct sprole_pw {
78020+ unsigned char *rolename;
78021+ unsigned char salt[GR_SALT_LEN];
78022+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
78023+};
78024+
78025+struct name_entry {
78026+ __u32 key;
78027+ ino_t inode;
78028+ dev_t device;
78029+ char *name;
78030+ __u16 len;
78031+ __u8 deleted;
78032+ struct name_entry *prev;
78033+ struct name_entry *next;
78034+};
78035+
78036+struct inodev_entry {
78037+ struct name_entry *nentry;
78038+ struct inodev_entry *prev;
78039+ struct inodev_entry *next;
78040+};
78041+
78042+struct acl_role_db {
78043+ struct acl_role_label **r_hash;
78044+ __u32 r_size;
78045+};
78046+
78047+struct inodev_db {
78048+ struct inodev_entry **i_hash;
78049+ __u32 i_size;
78050+};
78051+
78052+struct name_db {
78053+ struct name_entry **n_hash;
78054+ __u32 n_size;
78055+};
78056+
78057+struct crash_uid {
78058+ uid_t uid;
78059+ unsigned long expires;
78060+};
78061+
78062+struct gr_hash_struct {
78063+ void **table;
78064+ void **nametable;
78065+ void *first;
78066+ __u32 table_size;
78067+ __u32 used_size;
78068+ int type;
78069+};
78070+
78071+/* Userspace Grsecurity ACL data structures */
78072+
78073+struct acl_subject_label {
78074+ char *filename;
78075+ ino_t inode;
78076+ dev_t device;
78077+ __u32 mode;
78078+ kernel_cap_t cap_mask;
78079+ kernel_cap_t cap_lower;
78080+ kernel_cap_t cap_invert_audit;
78081+
78082+ struct rlimit res[GR_NLIMITS];
78083+ __u32 resmask;
78084+
78085+ __u8 user_trans_type;
78086+ __u8 group_trans_type;
78087+ uid_t *user_transitions;
78088+ gid_t *group_transitions;
78089+ __u16 user_trans_num;
78090+ __u16 group_trans_num;
78091+
78092+ __u32 sock_families[2];
78093+ __u32 ip_proto[8];
78094+ __u32 ip_type;
78095+ struct acl_ip_label **ips;
78096+ __u32 ip_num;
78097+ __u32 inaddr_any_override;
78098+
78099+ __u32 crashes;
78100+ unsigned long expires;
78101+
78102+ struct acl_subject_label *parent_subject;
78103+ struct gr_hash_struct *hash;
78104+ struct acl_subject_label *prev;
78105+ struct acl_subject_label *next;
78106+
78107+ struct acl_object_label **obj_hash;
78108+ __u32 obj_hash_size;
78109+ __u16 pax_flags;
78110+};
78111+
78112+struct role_allowed_ip {
78113+ __u32 addr;
78114+ __u32 netmask;
78115+
78116+ struct role_allowed_ip *prev;
78117+ struct role_allowed_ip *next;
78118+};
78119+
78120+struct role_transition {
78121+ char *rolename;
78122+
78123+ struct role_transition *prev;
78124+ struct role_transition *next;
78125+};
78126+
78127+struct acl_role_label {
78128+ char *rolename;
78129+ uid_t uidgid;
78130+ __u16 roletype;
78131+
78132+ __u16 auth_attempts;
78133+ unsigned long expires;
78134+
78135+ struct acl_subject_label *root_label;
78136+ struct gr_hash_struct *hash;
78137+
78138+ struct acl_role_label *prev;
78139+ struct acl_role_label *next;
78140+
78141+ struct role_transition *transitions;
78142+ struct role_allowed_ip *allowed_ips;
78143+ uid_t *domain_children;
78144+ __u16 domain_child_num;
78145+
78146+ umode_t umask;
78147+
78148+ struct acl_subject_label **subj_hash;
78149+ __u32 subj_hash_size;
78150+};
78151+
78152+struct user_acl_role_db {
78153+ struct acl_role_label **r_table;
78154+ __u32 num_pointers; /* Number of allocations to track */
78155+ __u32 num_roles; /* Number of roles */
78156+ __u32 num_domain_children; /* Number of domain children */
78157+ __u32 num_subjects; /* Number of subjects */
78158+ __u32 num_objects; /* Number of objects */
78159+};
78160+
78161+struct acl_object_label {
78162+ char *filename;
78163+ ino_t inode;
78164+ dev_t device;
78165+ __u32 mode;
78166+
78167+ struct acl_subject_label *nested;
78168+ struct acl_object_label *globbed;
78169+
78170+ /* next two structures not used */
78171+
78172+ struct acl_object_label *prev;
78173+ struct acl_object_label *next;
78174+};
78175+
78176+struct acl_ip_label {
78177+ char *iface;
78178+ __u32 addr;
78179+ __u32 netmask;
78180+ __u16 low, high;
78181+ __u8 mode;
78182+ __u32 type;
78183+ __u32 proto[8];
78184+
78185+ /* next two structures not used */
78186+
78187+ struct acl_ip_label *prev;
78188+ struct acl_ip_label *next;
78189+};
78190+
78191+struct gr_arg {
78192+ struct user_acl_role_db role_db;
78193+ unsigned char pw[GR_PW_LEN];
78194+ unsigned char salt[GR_SALT_LEN];
78195+ unsigned char sum[GR_SHA_LEN];
78196+ unsigned char sp_role[GR_SPROLE_LEN];
78197+ struct sprole_pw *sprole_pws;
78198+ dev_t segv_device;
78199+ ino_t segv_inode;
78200+ uid_t segv_uid;
78201+ __u16 num_sprole_pws;
78202+ __u16 mode;
78203+};
78204+
78205+struct gr_arg_wrapper {
78206+ struct gr_arg *arg;
78207+ __u32 version;
78208+ __u32 size;
78209+};
78210+
78211+struct subject_map {
78212+ struct acl_subject_label *user;
78213+ struct acl_subject_label *kernel;
78214+ struct subject_map *prev;
78215+ struct subject_map *next;
78216+};
78217+
78218+struct acl_subj_map_db {
78219+ struct subject_map **s_hash;
78220+ __u32 s_size;
78221+};
78222+
78223+struct gr_policy_state {
78224+ struct sprole_pw **acl_special_roles;
78225+ __u16 num_sprole_pws;
78226+ struct acl_role_label *kernel_role;
78227+ struct acl_role_label *role_list;
78228+ struct acl_role_label *default_role;
78229+ struct acl_role_db acl_role_set;
78230+ struct acl_subj_map_db subj_map_set;
78231+ struct name_db name_set;
78232+ struct inodev_db inodev_set;
78233+};
78234+
78235+struct gr_alloc_state {
78236+ unsigned long alloc_stack_next;
78237+ unsigned long alloc_stack_size;
78238+ void **alloc_stack;
78239+};
78240+
78241+struct gr_reload_state {
78242+ struct gr_policy_state oldpolicy;
78243+ struct gr_alloc_state oldalloc;
78244+ struct gr_policy_state newpolicy;
78245+ struct gr_alloc_state newalloc;
78246+ struct gr_policy_state *oldpolicy_ptr;
78247+ struct gr_alloc_state *oldalloc_ptr;
78248+ unsigned char oldmode;
78249+};
78250+
78251+/* End Data Structures Section */
78252+
78253+/* Hash functions generated by empirical testing by Brad Spengler
78254+ Makes good use of the low bits of the inode. Generally 0-1 times
78255+ in loop for successful match. 0-3 for unsuccessful match.
78256+ Shift/add algorithm with modulus of table size and an XOR*/
78257+
78258+static __inline__ unsigned int
78259+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
78260+{
78261+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
78262+}
78263+
78264+ static __inline__ unsigned int
78265+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
78266+{
78267+ return ((const unsigned long)userp % sz);
78268+}
78269+
78270+static __inline__ unsigned int
78271+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
78272+{
78273+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
78274+}
78275+
78276+static __inline__ unsigned int
78277+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
78278+{
78279+ return full_name_hash((const unsigned char *)name, len) % sz;
78280+}
78281+
78282+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
78283+ subj = NULL; \
78284+ iter = 0; \
78285+ while (iter < role->subj_hash_size) { \
78286+ if (subj == NULL) \
78287+ subj = role->subj_hash[iter]; \
78288+ if (subj == NULL) { \
78289+ iter++; \
78290+ continue; \
78291+ }
78292+
78293+#define FOR_EACH_SUBJECT_END(subj,iter) \
78294+ subj = subj->next; \
78295+ if (subj == NULL) \
78296+ iter++; \
78297+ }
78298+
78299+
78300+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
78301+ subj = role->hash->first; \
78302+ while (subj != NULL) {
78303+
78304+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
78305+ subj = subj->next; \
78306+ }
78307+
78308+#endif
78309+
78310diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
78311new file mode 100644
78312index 0000000..33ebd1f
78313--- /dev/null
78314+++ b/include/linux/gracl_compat.h
78315@@ -0,0 +1,156 @@
78316+#ifndef GR_ACL_COMPAT_H
78317+#define GR_ACL_COMPAT_H
78318+
78319+#include <linux/resource.h>
78320+#include <asm/resource.h>
78321+
78322+struct sprole_pw_compat {
78323+ compat_uptr_t rolename;
78324+ unsigned char salt[GR_SALT_LEN];
78325+ unsigned char sum[GR_SHA_LEN];
78326+};
78327+
78328+struct gr_hash_struct_compat {
78329+ compat_uptr_t table;
78330+ compat_uptr_t nametable;
78331+ compat_uptr_t first;
78332+ __u32 table_size;
78333+ __u32 used_size;
78334+ int type;
78335+};
78336+
78337+struct acl_subject_label_compat {
78338+ compat_uptr_t filename;
78339+ compat_ino_t inode;
78340+ __u32 device;
78341+ __u32 mode;
78342+ kernel_cap_t cap_mask;
78343+ kernel_cap_t cap_lower;
78344+ kernel_cap_t cap_invert_audit;
78345+
78346+ struct compat_rlimit res[GR_NLIMITS];
78347+ __u32 resmask;
78348+
78349+ __u8 user_trans_type;
78350+ __u8 group_trans_type;
78351+ compat_uptr_t user_transitions;
78352+ compat_uptr_t group_transitions;
78353+ __u16 user_trans_num;
78354+ __u16 group_trans_num;
78355+
78356+ __u32 sock_families[2];
78357+ __u32 ip_proto[8];
78358+ __u32 ip_type;
78359+ compat_uptr_t ips;
78360+ __u32 ip_num;
78361+ __u32 inaddr_any_override;
78362+
78363+ __u32 crashes;
78364+ compat_ulong_t expires;
78365+
78366+ compat_uptr_t parent_subject;
78367+ compat_uptr_t hash;
78368+ compat_uptr_t prev;
78369+ compat_uptr_t next;
78370+
78371+ compat_uptr_t obj_hash;
78372+ __u32 obj_hash_size;
78373+ __u16 pax_flags;
78374+};
78375+
78376+struct role_allowed_ip_compat {
78377+ __u32 addr;
78378+ __u32 netmask;
78379+
78380+ compat_uptr_t prev;
78381+ compat_uptr_t next;
78382+};
78383+
78384+struct role_transition_compat {
78385+ compat_uptr_t rolename;
78386+
78387+ compat_uptr_t prev;
78388+ compat_uptr_t next;
78389+};
78390+
78391+struct acl_role_label_compat {
78392+ compat_uptr_t rolename;
78393+ uid_t uidgid;
78394+ __u16 roletype;
78395+
78396+ __u16 auth_attempts;
78397+ compat_ulong_t expires;
78398+
78399+ compat_uptr_t root_label;
78400+ compat_uptr_t hash;
78401+
78402+ compat_uptr_t prev;
78403+ compat_uptr_t next;
78404+
78405+ compat_uptr_t transitions;
78406+ compat_uptr_t allowed_ips;
78407+ compat_uptr_t domain_children;
78408+ __u16 domain_child_num;
78409+
78410+ umode_t umask;
78411+
78412+ compat_uptr_t subj_hash;
78413+ __u32 subj_hash_size;
78414+};
78415+
78416+struct user_acl_role_db_compat {
78417+ compat_uptr_t r_table;
78418+ __u32 num_pointers;
78419+ __u32 num_roles;
78420+ __u32 num_domain_children;
78421+ __u32 num_subjects;
78422+ __u32 num_objects;
78423+};
78424+
78425+struct acl_object_label_compat {
78426+ compat_uptr_t filename;
78427+ compat_ino_t inode;
78428+ __u32 device;
78429+ __u32 mode;
78430+
78431+ compat_uptr_t nested;
78432+ compat_uptr_t globbed;
78433+
78434+ compat_uptr_t prev;
78435+ compat_uptr_t next;
78436+};
78437+
78438+struct acl_ip_label_compat {
78439+ compat_uptr_t iface;
78440+ __u32 addr;
78441+ __u32 netmask;
78442+ __u16 low, high;
78443+ __u8 mode;
78444+ __u32 type;
78445+ __u32 proto[8];
78446+
78447+ compat_uptr_t prev;
78448+ compat_uptr_t next;
78449+};
78450+
78451+struct gr_arg_compat {
78452+ struct user_acl_role_db_compat role_db;
78453+ unsigned char pw[GR_PW_LEN];
78454+ unsigned char salt[GR_SALT_LEN];
78455+ unsigned char sum[GR_SHA_LEN];
78456+ unsigned char sp_role[GR_SPROLE_LEN];
78457+ compat_uptr_t sprole_pws;
78458+ __u32 segv_device;
78459+ compat_ino_t segv_inode;
78460+ uid_t segv_uid;
78461+ __u16 num_sprole_pws;
78462+ __u16 mode;
78463+};
78464+
78465+struct gr_arg_wrapper_compat {
78466+ compat_uptr_t arg;
78467+ __u32 version;
78468+ __u32 size;
78469+};
78470+
78471+#endif
78472diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
78473new file mode 100644
78474index 0000000..323ecf2
78475--- /dev/null
78476+++ b/include/linux/gralloc.h
78477@@ -0,0 +1,9 @@
78478+#ifndef __GRALLOC_H
78479+#define __GRALLOC_H
78480+
78481+void acl_free_all(void);
78482+int acl_alloc_stack_init(unsigned long size);
78483+void *acl_alloc(unsigned long len);
78484+void *acl_alloc_num(unsigned long num, unsigned long len);
78485+
78486+#endif
78487diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
78488new file mode 100644
78489index 0000000..be66033
78490--- /dev/null
78491+++ b/include/linux/grdefs.h
78492@@ -0,0 +1,140 @@
78493+#ifndef GRDEFS_H
78494+#define GRDEFS_H
78495+
78496+/* Begin grsecurity status declarations */
78497+
78498+enum {
78499+ GR_READY = 0x01,
78500+ GR_STATUS_INIT = 0x00 // disabled state
78501+};
78502+
78503+/* Begin ACL declarations */
78504+
78505+/* Role flags */
78506+
78507+enum {
78508+ GR_ROLE_USER = 0x0001,
78509+ GR_ROLE_GROUP = 0x0002,
78510+ GR_ROLE_DEFAULT = 0x0004,
78511+ GR_ROLE_SPECIAL = 0x0008,
78512+ GR_ROLE_AUTH = 0x0010,
78513+ GR_ROLE_NOPW = 0x0020,
78514+ GR_ROLE_GOD = 0x0040,
78515+ GR_ROLE_LEARN = 0x0080,
78516+ GR_ROLE_TPE = 0x0100,
78517+ GR_ROLE_DOMAIN = 0x0200,
78518+ GR_ROLE_PAM = 0x0400,
78519+ GR_ROLE_PERSIST = 0x0800
78520+};
78521+
78522+/* ACL Subject and Object mode flags */
78523+enum {
78524+ GR_DELETED = 0x80000000
78525+};
78526+
78527+/* ACL Object-only mode flags */
78528+enum {
78529+ GR_READ = 0x00000001,
78530+ GR_APPEND = 0x00000002,
78531+ GR_WRITE = 0x00000004,
78532+ GR_EXEC = 0x00000008,
78533+ GR_FIND = 0x00000010,
78534+ GR_INHERIT = 0x00000020,
78535+ GR_SETID = 0x00000040,
78536+ GR_CREATE = 0x00000080,
78537+ GR_DELETE = 0x00000100,
78538+ GR_LINK = 0x00000200,
78539+ GR_AUDIT_READ = 0x00000400,
78540+ GR_AUDIT_APPEND = 0x00000800,
78541+ GR_AUDIT_WRITE = 0x00001000,
78542+ GR_AUDIT_EXEC = 0x00002000,
78543+ GR_AUDIT_FIND = 0x00004000,
78544+ GR_AUDIT_INHERIT= 0x00008000,
78545+ GR_AUDIT_SETID = 0x00010000,
78546+ GR_AUDIT_CREATE = 0x00020000,
78547+ GR_AUDIT_DELETE = 0x00040000,
78548+ GR_AUDIT_LINK = 0x00080000,
78549+ GR_PTRACERD = 0x00100000,
78550+ GR_NOPTRACE = 0x00200000,
78551+ GR_SUPPRESS = 0x00400000,
78552+ GR_NOLEARN = 0x00800000,
78553+ GR_INIT_TRANSFER= 0x01000000
78554+};
78555+
78556+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
78557+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
78558+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
78559+
78560+/* ACL subject-only mode flags */
78561+enum {
78562+ GR_KILL = 0x00000001,
78563+ GR_VIEW = 0x00000002,
78564+ GR_PROTECTED = 0x00000004,
78565+ GR_LEARN = 0x00000008,
78566+ GR_OVERRIDE = 0x00000010,
78567+ /* just a placeholder, this mode is only used in userspace */
78568+ GR_DUMMY = 0x00000020,
78569+ GR_PROTSHM = 0x00000040,
78570+ GR_KILLPROC = 0x00000080,
78571+ GR_KILLIPPROC = 0x00000100,
78572+ /* just a placeholder, this mode is only used in userspace */
78573+ GR_NOTROJAN = 0x00000200,
78574+ GR_PROTPROCFD = 0x00000400,
78575+ GR_PROCACCT = 0x00000800,
78576+ GR_RELAXPTRACE = 0x00001000,
78577+ //GR_NESTED = 0x00002000,
78578+ GR_INHERITLEARN = 0x00004000,
78579+ GR_PROCFIND = 0x00008000,
78580+ GR_POVERRIDE = 0x00010000,
78581+ GR_KERNELAUTH = 0x00020000,
78582+ GR_ATSECURE = 0x00040000,
78583+ GR_SHMEXEC = 0x00080000
78584+};
78585+
78586+enum {
78587+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
78588+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
78589+ GR_PAX_ENABLE_MPROTECT = 0x0004,
78590+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
78591+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
78592+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
78593+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
78594+ GR_PAX_DISABLE_MPROTECT = 0x0400,
78595+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
78596+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
78597+};
78598+
78599+enum {
78600+ GR_ID_USER = 0x01,
78601+ GR_ID_GROUP = 0x02,
78602+};
78603+
78604+enum {
78605+ GR_ID_ALLOW = 0x01,
78606+ GR_ID_DENY = 0x02,
78607+};
78608+
78609+#define GR_CRASH_RES 31
78610+#define GR_UIDTABLE_MAX 500
78611+
78612+/* begin resource learning section */
78613+enum {
78614+ GR_RLIM_CPU_BUMP = 60,
78615+ GR_RLIM_FSIZE_BUMP = 50000,
78616+ GR_RLIM_DATA_BUMP = 10000,
78617+ GR_RLIM_STACK_BUMP = 1000,
78618+ GR_RLIM_CORE_BUMP = 10000,
78619+ GR_RLIM_RSS_BUMP = 500000,
78620+ GR_RLIM_NPROC_BUMP = 1,
78621+ GR_RLIM_NOFILE_BUMP = 5,
78622+ GR_RLIM_MEMLOCK_BUMP = 50000,
78623+ GR_RLIM_AS_BUMP = 500000,
78624+ GR_RLIM_LOCKS_BUMP = 2,
78625+ GR_RLIM_SIGPENDING_BUMP = 5,
78626+ GR_RLIM_MSGQUEUE_BUMP = 10000,
78627+ GR_RLIM_NICE_BUMP = 1,
78628+ GR_RLIM_RTPRIO_BUMP = 1,
78629+ GR_RLIM_RTTIME_BUMP = 1000000
78630+};
78631+
78632+#endif
78633diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
78634new file mode 100644
78635index 0000000..d25522e
78636--- /dev/null
78637+++ b/include/linux/grinternal.h
78638@@ -0,0 +1,229 @@
78639+#ifndef __GRINTERNAL_H
78640+#define __GRINTERNAL_H
78641+
78642+#ifdef CONFIG_GRKERNSEC
78643+
78644+#include <linux/fs.h>
78645+#include <linux/mnt_namespace.h>
78646+#include <linux/nsproxy.h>
78647+#include <linux/gracl.h>
78648+#include <linux/grdefs.h>
78649+#include <linux/grmsg.h>
78650+
78651+void gr_add_learn_entry(const char *fmt, ...)
78652+ __attribute__ ((format (printf, 1, 2)));
78653+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
78654+ const struct vfsmount *mnt);
78655+__u32 gr_check_create(const struct dentry *new_dentry,
78656+ const struct dentry *parent,
78657+ const struct vfsmount *mnt, const __u32 mode);
78658+int gr_check_protected_task(const struct task_struct *task);
78659+__u32 to_gr_audit(const __u32 reqmode);
78660+int gr_set_acls(const int type);
78661+int gr_acl_is_enabled(void);
78662+char gr_roletype_to_char(void);
78663+
78664+void gr_handle_alertkill(struct task_struct *task);
78665+char *gr_to_filename(const struct dentry *dentry,
78666+ const struct vfsmount *mnt);
78667+char *gr_to_filename1(const struct dentry *dentry,
78668+ const struct vfsmount *mnt);
78669+char *gr_to_filename2(const struct dentry *dentry,
78670+ const struct vfsmount *mnt);
78671+char *gr_to_filename3(const struct dentry *dentry,
78672+ const struct vfsmount *mnt);
78673+
78674+extern int grsec_enable_ptrace_readexec;
78675+extern int grsec_enable_harden_ptrace;
78676+extern int grsec_enable_link;
78677+extern int grsec_enable_fifo;
78678+extern int grsec_enable_execve;
78679+extern int grsec_enable_shm;
78680+extern int grsec_enable_execlog;
78681+extern int grsec_enable_signal;
78682+extern int grsec_enable_audit_ptrace;
78683+extern int grsec_enable_forkfail;
78684+extern int grsec_enable_time;
78685+extern int grsec_enable_rofs;
78686+extern int grsec_deny_new_usb;
78687+extern int grsec_enable_chroot_shmat;
78688+extern int grsec_enable_chroot_mount;
78689+extern int grsec_enable_chroot_double;
78690+extern int grsec_enable_chroot_pivot;
78691+extern int grsec_enable_chroot_chdir;
78692+extern int grsec_enable_chroot_chmod;
78693+extern int grsec_enable_chroot_mknod;
78694+extern int grsec_enable_chroot_fchdir;
78695+extern int grsec_enable_chroot_nice;
78696+extern int grsec_enable_chroot_execlog;
78697+extern int grsec_enable_chroot_caps;
78698+extern int grsec_enable_chroot_sysctl;
78699+extern int grsec_enable_chroot_unix;
78700+extern int grsec_enable_symlinkown;
78701+extern kgid_t grsec_symlinkown_gid;
78702+extern int grsec_enable_tpe;
78703+extern kgid_t grsec_tpe_gid;
78704+extern int grsec_enable_tpe_all;
78705+extern int grsec_enable_tpe_invert;
78706+extern int grsec_enable_socket_all;
78707+extern kgid_t grsec_socket_all_gid;
78708+extern int grsec_enable_socket_client;
78709+extern kgid_t grsec_socket_client_gid;
78710+extern int grsec_enable_socket_server;
78711+extern kgid_t grsec_socket_server_gid;
78712+extern kgid_t grsec_audit_gid;
78713+extern int grsec_enable_group;
78714+extern int grsec_enable_log_rwxmaps;
78715+extern int grsec_enable_mount;
78716+extern int grsec_enable_chdir;
78717+extern int grsec_resource_logging;
78718+extern int grsec_enable_blackhole;
78719+extern int grsec_lastack_retries;
78720+extern int grsec_enable_brute;
78721+extern int grsec_enable_harden_ipc;
78722+extern int grsec_lock;
78723+
78724+extern spinlock_t grsec_alert_lock;
78725+extern unsigned long grsec_alert_wtime;
78726+extern unsigned long grsec_alert_fyet;
78727+
78728+extern spinlock_t grsec_audit_lock;
78729+
78730+extern rwlock_t grsec_exec_file_lock;
78731+
78732+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
78733+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
78734+ (tsk)->exec_file->f_path.mnt) : "/")
78735+
78736+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
78737+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
78738+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
78739+
78740+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
78741+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
78742+ (tsk)->exec_file->f_path.mnt) : "/")
78743+
78744+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
78745+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
78746+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
78747+
78748+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
78749+
78750+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
78751+
78752+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
78753+{
78754+ if (file1 && file2) {
78755+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
78756+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
78757+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
78758+ return true;
78759+ }
78760+
78761+ return false;
78762+}
78763+
78764+#define GR_CHROOT_CAPS {{ \
78765+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
78766+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
78767+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
78768+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
78769+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
78770+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
78771+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
78772+
78773+#define security_learn(normal_msg,args...) \
78774+({ \
78775+ read_lock(&grsec_exec_file_lock); \
78776+ gr_add_learn_entry(normal_msg "\n", ## args); \
78777+ read_unlock(&grsec_exec_file_lock); \
78778+})
78779+
78780+enum {
78781+ GR_DO_AUDIT,
78782+ GR_DONT_AUDIT,
78783+ /* used for non-audit messages that we shouldn't kill the task on */
78784+ GR_DONT_AUDIT_GOOD
78785+};
78786+
78787+enum {
78788+ GR_TTYSNIFF,
78789+ GR_RBAC,
78790+ GR_RBAC_STR,
78791+ GR_STR_RBAC,
78792+ GR_RBAC_MODE2,
78793+ GR_RBAC_MODE3,
78794+ GR_FILENAME,
78795+ GR_SYSCTL_HIDDEN,
78796+ GR_NOARGS,
78797+ GR_ONE_INT,
78798+ GR_ONE_INT_TWO_STR,
78799+ GR_ONE_STR,
78800+ GR_STR_INT,
78801+ GR_TWO_STR_INT,
78802+ GR_TWO_INT,
78803+ GR_TWO_U64,
78804+ GR_THREE_INT,
78805+ GR_FIVE_INT_TWO_STR,
78806+ GR_TWO_STR,
78807+ GR_THREE_STR,
78808+ GR_FOUR_STR,
78809+ GR_STR_FILENAME,
78810+ GR_FILENAME_STR,
78811+ GR_FILENAME_TWO_INT,
78812+ GR_FILENAME_TWO_INT_STR,
78813+ GR_TEXTREL,
78814+ GR_PTRACE,
78815+ GR_RESOURCE,
78816+ GR_CAP,
78817+ GR_SIG,
78818+ GR_SIG2,
78819+ GR_CRASH1,
78820+ GR_CRASH2,
78821+ GR_PSACCT,
78822+ GR_RWXMAP,
78823+ GR_RWXMAPVMA
78824+};
78825+
78826+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
78827+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
78828+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
78829+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
78830+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
78831+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
78832+#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)
78833+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
78834+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
78835+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
78836+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
78837+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
78838+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
78839+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
78840+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
78841+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
78842+#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)
78843+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
78844+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
78845+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
78846+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
78847+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
78848+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
78849+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
78850+#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)
78851+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
78852+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
78853+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
78854+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
78855+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
78856+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
78857+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
78858+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
78859+#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)
78860+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
78861+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
78862+
78863+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
78864+
78865+#endif
78866+
78867+#endif
78868diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
78869new file mode 100644
78870index 0000000..ba93581
78871--- /dev/null
78872+++ b/include/linux/grmsg.h
78873@@ -0,0 +1,116 @@
78874+#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"
78875+#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"
78876+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
78877+#define GR_STOPMOD_MSG "denied modification of module state by "
78878+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
78879+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
78880+#define GR_IOPERM_MSG "denied use of ioperm() by "
78881+#define GR_IOPL_MSG "denied use of iopl() by "
78882+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
78883+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
78884+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
78885+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
78886+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
78887+#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"
78888+#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"
78889+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
78890+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
78891+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
78892+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
78893+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
78894+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
78895+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
78896+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
78897+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
78898+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
78899+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
78900+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
78901+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
78902+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
78903+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
78904+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
78905+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
78906+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
78907+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
78908+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
78909+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
78910+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
78911+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
78912+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
78913+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
78914+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
78915+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
78916+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
78917+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
78918+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
78919+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
78920+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
78921+#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
78922+#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
78923+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
78924+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
78925+#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"
78926+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
78927+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
78928+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
78929+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
78930+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
78931+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
78932+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
78933+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
78934+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
78935+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
78936+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
78937+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
78938+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
78939+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
78940+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
78941+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
78942+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
78943+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
78944+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
78945+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
78946+#define GR_FAILFORK_MSG "failed fork with errno %s by "
78947+#define GR_NICE_CHROOT_MSG "denied priority change by "
78948+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
78949+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
78950+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
78951+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
78952+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
78953+#define GR_TIME_MSG "time set by "
78954+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
78955+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
78956+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
78957+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
78958+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
78959+#define GR_BIND_MSG "denied bind() by "
78960+#define GR_CONNECT_MSG "denied connect() by "
78961+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
78962+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
78963+#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"
78964+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
78965+#define GR_CAP_ACL_MSG "use of %s denied for "
78966+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
78967+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
78968+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
78969+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
78970+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
78971+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
78972+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
78973+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
78974+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
78975+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
78976+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
78977+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
78978+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
78979+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
78980+#define GR_VM86_MSG "denied use of vm86 by "
78981+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
78982+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
78983+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
78984+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
78985+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
78986+#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 "
78987+#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 "
78988+#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
78989+#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
78990diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
78991new file mode 100644
78992index 0000000..8108301
78993--- /dev/null
78994+++ b/include/linux/grsecurity.h
78995@@ -0,0 +1,246 @@
78996+#ifndef GR_SECURITY_H
78997+#define GR_SECURITY_H
78998+#include <linux/fs.h>
78999+#include <linux/fs_struct.h>
79000+#include <linux/binfmts.h>
79001+#include <linux/gracl.h>
79002+
79003+/* notify of brain-dead configs */
79004+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79005+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
79006+#endif
79007+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
79008+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
79009+#endif
79010+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
79011+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
79012+#endif
79013+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
79014+#error "CONFIG_PAX enabled, but no PaX options are enabled."
79015+#endif
79016+
79017+int gr_handle_new_usb(void);
79018+
79019+void gr_handle_brute_attach(int dumpable);
79020+void gr_handle_brute_check(void);
79021+void gr_handle_kernel_exploit(void);
79022+
79023+char gr_roletype_to_char(void);
79024+
79025+int gr_acl_enable_at_secure(void);
79026+
79027+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
79028+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
79029+
79030+void gr_del_task_from_ip_table(struct task_struct *p);
79031+
79032+int gr_pid_is_chrooted(struct task_struct *p);
79033+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
79034+int gr_handle_chroot_nice(void);
79035+int gr_handle_chroot_sysctl(const int op);
79036+int gr_handle_chroot_setpriority(struct task_struct *p,
79037+ const int niceval);
79038+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
79039+int gr_handle_chroot_chroot(const struct dentry *dentry,
79040+ const struct vfsmount *mnt);
79041+void gr_handle_chroot_chdir(const struct path *path);
79042+int gr_handle_chroot_chmod(const struct dentry *dentry,
79043+ const struct vfsmount *mnt, const int mode);
79044+int gr_handle_chroot_mknod(const struct dentry *dentry,
79045+ const struct vfsmount *mnt, const int mode);
79046+int gr_handle_chroot_mount(const struct dentry *dentry,
79047+ const struct vfsmount *mnt,
79048+ const char *dev_name);
79049+int gr_handle_chroot_pivot(void);
79050+int gr_handle_chroot_unix(const pid_t pid);
79051+
79052+int gr_handle_rawio(const struct inode *inode);
79053+
79054+void gr_handle_ioperm(void);
79055+void gr_handle_iopl(void);
79056+void gr_handle_msr_write(void);
79057+
79058+umode_t gr_acl_umask(void);
79059+
79060+int gr_tpe_allow(const struct file *file);
79061+
79062+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
79063+void gr_clear_chroot_entries(struct task_struct *task);
79064+
79065+void gr_log_forkfail(const int retval);
79066+void gr_log_timechange(void);
79067+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
79068+void gr_log_chdir(const struct dentry *dentry,
79069+ const struct vfsmount *mnt);
79070+void gr_log_chroot_exec(const struct dentry *dentry,
79071+ const struct vfsmount *mnt);
79072+void gr_log_remount(const char *devname, const int retval);
79073+void gr_log_unmount(const char *devname, const int retval);
79074+void gr_log_mount(const char *from, const char *to, const int retval);
79075+void gr_log_textrel(struct vm_area_struct *vma);
79076+void gr_log_ptgnustack(struct file *file);
79077+void gr_log_rwxmmap(struct file *file);
79078+void gr_log_rwxmprotect(struct vm_area_struct *vma);
79079+
79080+int gr_handle_follow_link(const struct inode *parent,
79081+ const struct inode *inode,
79082+ const struct dentry *dentry,
79083+ const struct vfsmount *mnt);
79084+int gr_handle_fifo(const struct dentry *dentry,
79085+ const struct vfsmount *mnt,
79086+ const struct dentry *dir, const int flag,
79087+ const int acc_mode);
79088+int gr_handle_hardlink(const struct dentry *dentry,
79089+ const struct vfsmount *mnt,
79090+ struct inode *inode,
79091+ const int mode, const struct filename *to);
79092+
79093+int gr_is_capable(const int cap);
79094+int gr_is_capable_nolog(const int cap);
79095+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
79096+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
79097+
79098+void gr_copy_label(struct task_struct *tsk);
79099+void gr_handle_crash(struct task_struct *task, const int sig);
79100+int gr_handle_signal(const struct task_struct *p, const int sig);
79101+int gr_check_crash_uid(const kuid_t uid);
79102+int gr_check_protected_task(const struct task_struct *task);
79103+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
79104+int gr_acl_handle_mmap(const struct file *file,
79105+ const unsigned long prot);
79106+int gr_acl_handle_mprotect(const struct file *file,
79107+ const unsigned long prot);
79108+int gr_check_hidden_task(const struct task_struct *tsk);
79109+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
79110+ const struct vfsmount *mnt);
79111+__u32 gr_acl_handle_utime(const struct dentry *dentry,
79112+ const struct vfsmount *mnt);
79113+__u32 gr_acl_handle_access(const struct dentry *dentry,
79114+ const struct vfsmount *mnt, const int fmode);
79115+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
79116+ const struct vfsmount *mnt, umode_t *mode);
79117+__u32 gr_acl_handle_chown(const struct dentry *dentry,
79118+ const struct vfsmount *mnt);
79119+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
79120+ const struct vfsmount *mnt);
79121+__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
79122+ const struct vfsmount *mnt);
79123+int gr_handle_ptrace(struct task_struct *task, const long request);
79124+int gr_handle_proc_ptrace(struct task_struct *task);
79125+__u32 gr_acl_handle_execve(const struct dentry *dentry,
79126+ const struct vfsmount *mnt);
79127+int gr_check_crash_exec(const struct file *filp);
79128+int gr_acl_is_enabled(void);
79129+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
79130+ const kgid_t gid);
79131+int gr_set_proc_label(const struct dentry *dentry,
79132+ const struct vfsmount *mnt,
79133+ const int unsafe_flags);
79134+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
79135+ const struct vfsmount *mnt);
79136+__u32 gr_acl_handle_open(const struct dentry *dentry,
79137+ const struct vfsmount *mnt, int acc_mode);
79138+__u32 gr_acl_handle_creat(const struct dentry *dentry,
79139+ const struct dentry *p_dentry,
79140+ const struct vfsmount *p_mnt,
79141+ int open_flags, int acc_mode, const int imode);
79142+void gr_handle_create(const struct dentry *dentry,
79143+ const struct vfsmount *mnt);
79144+void gr_handle_proc_create(const struct dentry *dentry,
79145+ const struct inode *inode);
79146+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
79147+ const struct dentry *parent_dentry,
79148+ const struct vfsmount *parent_mnt,
79149+ const int mode);
79150+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
79151+ const struct dentry *parent_dentry,
79152+ const struct vfsmount *parent_mnt);
79153+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
79154+ const struct vfsmount *mnt);
79155+void gr_handle_delete(const ino_t ino, const dev_t dev);
79156+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
79157+ const struct vfsmount *mnt);
79158+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
79159+ const struct dentry *parent_dentry,
79160+ const struct vfsmount *parent_mnt,
79161+ const struct filename *from);
79162+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
79163+ const struct dentry *parent_dentry,
79164+ const struct vfsmount *parent_mnt,
79165+ const struct dentry *old_dentry,
79166+ const struct vfsmount *old_mnt, const struct filename *to);
79167+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
79168+int gr_acl_handle_rename(struct dentry *new_dentry,
79169+ struct dentry *parent_dentry,
79170+ const struct vfsmount *parent_mnt,
79171+ struct dentry *old_dentry,
79172+ struct inode *old_parent_inode,
79173+ struct vfsmount *old_mnt, const struct filename *newname);
79174+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
79175+ struct dentry *old_dentry,
79176+ struct dentry *new_dentry,
79177+ struct vfsmount *mnt, const __u8 replace);
79178+__u32 gr_check_link(const struct dentry *new_dentry,
79179+ const struct dentry *parent_dentry,
79180+ const struct vfsmount *parent_mnt,
79181+ const struct dentry *old_dentry,
79182+ const struct vfsmount *old_mnt);
79183+int gr_acl_handle_filldir(const struct file *file, const char *name,
79184+ const unsigned int namelen, const ino_t ino);
79185+
79186+__u32 gr_acl_handle_unix(const struct dentry *dentry,
79187+ const struct vfsmount *mnt);
79188+void gr_acl_handle_exit(void);
79189+void gr_acl_handle_psacct(struct task_struct *task, const long code);
79190+int gr_acl_handle_procpidmem(const struct task_struct *task);
79191+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
79192+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
79193+void gr_audit_ptrace(struct task_struct *task);
79194+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
79195+void gr_put_exec_file(struct task_struct *task);
79196+
79197+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
79198+
79199+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
79200+extern void gr_learn_resource(const struct task_struct *task, const int res,
79201+ const unsigned long wanted, const int gt);
79202+#else
79203+static inline void gr_learn_resource(const struct task_struct *task, const int res,
79204+ const unsigned long wanted, const int gt)
79205+{
79206+}
79207+#endif
79208+
79209+#ifdef CONFIG_GRKERNSEC_RESLOG
79210+extern void gr_log_resource(const struct task_struct *task, const int res,
79211+ const unsigned long wanted, const int gt);
79212+#else
79213+static inline void gr_log_resource(const struct task_struct *task, const int res,
79214+ const unsigned long wanted, const int gt)
79215+{
79216+}
79217+#endif
79218+
79219+#ifdef CONFIG_GRKERNSEC
79220+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
79221+void gr_handle_vm86(void);
79222+void gr_handle_mem_readwrite(u64 from, u64 to);
79223+
79224+void gr_log_badprocpid(const char *entry);
79225+
79226+extern int grsec_enable_dmesg;
79227+extern int grsec_disable_privio;
79228+
79229+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79230+extern kgid_t grsec_proc_gid;
79231+#endif
79232+
79233+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79234+extern int grsec_enable_chroot_findtask;
79235+#endif
79236+#ifdef CONFIG_GRKERNSEC_SETXID
79237+extern int grsec_enable_setxid;
79238+#endif
79239+#endif
79240+
79241+#endif
79242diff --git a/include/linux/grsock.h b/include/linux/grsock.h
79243new file mode 100644
79244index 0000000..e7ffaaf
79245--- /dev/null
79246+++ b/include/linux/grsock.h
79247@@ -0,0 +1,19 @@
79248+#ifndef __GRSOCK_H
79249+#define __GRSOCK_H
79250+
79251+extern void gr_attach_curr_ip(const struct sock *sk);
79252+extern int gr_handle_sock_all(const int family, const int type,
79253+ const int protocol);
79254+extern int gr_handle_sock_server(const struct sockaddr *sck);
79255+extern int gr_handle_sock_server_other(const struct sock *sck);
79256+extern int gr_handle_sock_client(const struct sockaddr *sck);
79257+extern int gr_search_connect(struct socket * sock,
79258+ struct sockaddr_in * addr);
79259+extern int gr_search_bind(struct socket * sock,
79260+ struct sockaddr_in * addr);
79261+extern int gr_search_listen(struct socket * sock);
79262+extern int gr_search_accept(struct socket * sock);
79263+extern int gr_search_socket(const int domain, const int type,
79264+ const int protocol);
79265+
79266+#endif
79267diff --git a/include/linux/highmem.h b/include/linux/highmem.h
79268index 7fb31da..08b5114 100644
79269--- a/include/linux/highmem.h
79270+++ b/include/linux/highmem.h
79271@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
79272 kunmap_atomic(kaddr);
79273 }
79274
79275+static inline void sanitize_highpage(struct page *page)
79276+{
79277+ void *kaddr;
79278+ unsigned long flags;
79279+
79280+ local_irq_save(flags);
79281+ kaddr = kmap_atomic(page);
79282+ clear_page(kaddr);
79283+ kunmap_atomic(kaddr);
79284+ local_irq_restore(flags);
79285+}
79286+
79287 static inline void zero_user_segments(struct page *page,
79288 unsigned start1, unsigned end1,
79289 unsigned start2, unsigned end2)
79290diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
79291index 1c7b89a..7dda400 100644
79292--- a/include/linux/hwmon-sysfs.h
79293+++ b/include/linux/hwmon-sysfs.h
79294@@ -25,7 +25,8 @@
79295 struct sensor_device_attribute{
79296 struct device_attribute dev_attr;
79297 int index;
79298-};
79299+} __do_const;
79300+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
79301 #define to_sensor_dev_attr(_dev_attr) \
79302 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
79303
79304@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
79305 struct device_attribute dev_attr;
79306 u8 index;
79307 u8 nr;
79308-};
79309+} __do_const;
79310+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
79311 #define to_sensor_dev_attr_2(_dev_attr) \
79312 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
79313
79314diff --git a/include/linux/i2c.h b/include/linux/i2c.h
79315index d9c8dbd3..def6e5a 100644
79316--- a/include/linux/i2c.h
79317+++ b/include/linux/i2c.h
79318@@ -364,6 +364,7 @@ struct i2c_algorithm {
79319 /* To determine what the adapter supports */
79320 u32 (*functionality) (struct i2c_adapter *);
79321 };
79322+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
79323
79324 /**
79325 * struct i2c_bus_recovery_info - I2C bus recovery information
79326diff --git a/include/linux/i2o.h b/include/linux/i2o.h
79327index d23c3c2..eb63c81 100644
79328--- a/include/linux/i2o.h
79329+++ b/include/linux/i2o.h
79330@@ -565,7 +565,7 @@ struct i2o_controller {
79331 struct i2o_device *exec; /* Executive */
79332 #if BITS_PER_LONG == 64
79333 spinlock_t context_list_lock; /* lock for context_list */
79334- atomic_t context_list_counter; /* needed for unique contexts */
79335+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
79336 struct list_head context_list; /* list of context id's
79337 and pointers */
79338 #endif
79339diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
79340index aff7ad8..3942bbd 100644
79341--- a/include/linux/if_pppox.h
79342+++ b/include/linux/if_pppox.h
79343@@ -76,7 +76,7 @@ struct pppox_proto {
79344 int (*ioctl)(struct socket *sock, unsigned int cmd,
79345 unsigned long arg);
79346 struct module *owner;
79347-};
79348+} __do_const;
79349
79350 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
79351 extern void unregister_pppox_proto(int proto_num);
79352diff --git a/include/linux/init.h b/include/linux/init.h
79353index 8e68a64..3f977a0 100644
79354--- a/include/linux/init.h
79355+++ b/include/linux/init.h
79356@@ -37,9 +37,17 @@
79357 * section.
79358 */
79359
79360+#define add_init_latent_entropy __latent_entropy
79361+
79362+#ifdef CONFIG_MEMORY_HOTPLUG
79363+#define add_meminit_latent_entropy
79364+#else
79365+#define add_meminit_latent_entropy __latent_entropy
79366+#endif
79367+
79368 /* These are for everybody (although not all archs will actually
79369 discard it in modules) */
79370-#define __init __section(.init.text) __cold notrace
79371+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
79372 #define __initdata __section(.init.data)
79373 #define __initconst __constsection(.init.rodata)
79374 #define __exitdata __section(.exit.data)
79375@@ -100,7 +108,7 @@
79376 #define __cpuexitconst
79377
79378 /* Used for MEMORY_HOTPLUG */
79379-#define __meminit __section(.meminit.text) __cold notrace
79380+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
79381 #define __meminitdata __section(.meminit.data)
79382 #define __meminitconst __constsection(.meminit.rodata)
79383 #define __memexit __section(.memexit.text) __exitused __cold notrace
79384diff --git a/include/linux/init_task.h b/include/linux/init_task.h
79385index b0ed422..d79ea23 100644
79386--- a/include/linux/init_task.h
79387+++ b/include/linux/init_task.h
79388@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
79389
79390 #define INIT_TASK_COMM "swapper"
79391
79392+#ifdef CONFIG_X86
79393+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
79394+#else
79395+#define INIT_TASK_THREAD_INFO
79396+#endif
79397+
79398 /*
79399 * INIT_TASK is used to set up the first task table, touch at
79400 * your own risk!. Base=0, limit=0x1fffff (=2MB)
79401@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
79402 RCU_POINTER_INITIALIZER(cred, &init_cred), \
79403 .comm = INIT_TASK_COMM, \
79404 .thread = INIT_THREAD, \
79405+ INIT_TASK_THREAD_INFO \
79406 .fs = &init_fs, \
79407 .files = &init_files, \
79408 .signal = &init_signals, \
79409diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
79410index db43b58..5d5084b 100644
79411--- a/include/linux/interrupt.h
79412+++ b/include/linux/interrupt.h
79413@@ -360,7 +360,7 @@ enum
79414 /* map softirq index to softirq name. update 'softirq_to_name' in
79415 * kernel/softirq.c when adding a new softirq.
79416 */
79417-extern char *softirq_to_name[NR_SOFTIRQS];
79418+extern const char * const softirq_to_name[NR_SOFTIRQS];
79419
79420 /* softirq mask and active fields moved to irq_cpustat_t in
79421 * asm/hardirq.h to get better cache usage. KAO
79422@@ -368,8 +368,8 @@ extern char *softirq_to_name[NR_SOFTIRQS];
79423
79424 struct softirq_action
79425 {
79426- void (*action)(struct softirq_action *);
79427-};
79428+ void (*action)(void);
79429+} __no_const;
79430
79431 asmlinkage void do_softirq(void);
79432 asmlinkage void __do_softirq(void);
79433@@ -383,7 +383,7 @@ static inline void do_softirq_own_stack(void)
79434 }
79435 #endif
79436
79437-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
79438+extern void open_softirq(int nr, void (*action)(void));
79439 extern void softirq_init(void);
79440 extern void __raise_softirq_irqoff(unsigned int nr);
79441
79442diff --git a/include/linux/iommu.h b/include/linux/iommu.h
79443index a444c79..8c41ea9 100644
79444--- a/include/linux/iommu.h
79445+++ b/include/linux/iommu.h
79446@@ -130,7 +130,7 @@ struct iommu_ops {
79447 u32 (*domain_get_windows)(struct iommu_domain *domain);
79448
79449 unsigned long pgsize_bitmap;
79450-};
79451+} __do_const;
79452
79453 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
79454 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
79455diff --git a/include/linux/ioport.h b/include/linux/ioport.h
79456index 89b7c24..382af74 100644
79457--- a/include/linux/ioport.h
79458+++ b/include/linux/ioport.h
79459@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
79460 int adjust_resource(struct resource *res, resource_size_t start,
79461 resource_size_t size);
79462 resource_size_t resource_alignment(struct resource *res);
79463-static inline resource_size_t resource_size(const struct resource *res)
79464+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
79465 {
79466 return res->end - res->start + 1;
79467 }
79468diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
79469index d6ad91f..f10f279 100644
79470--- a/include/linux/ipc_namespace.h
79471+++ b/include/linux/ipc_namespace.h
79472@@ -70,7 +70,7 @@ struct ipc_namespace {
79473 struct user_namespace *user_ns;
79474
79475 unsigned int proc_inum;
79476-};
79477+} __randomize_layout;
79478
79479 extern struct ipc_namespace init_ipc_ns;
79480 extern atomic_t nr_ipc_ns;
79481diff --git a/include/linux/irq.h b/include/linux/irq.h
79482index 7dc1003..407327b 100644
79483--- a/include/linux/irq.h
79484+++ b/include/linux/irq.h
79485@@ -338,7 +338,8 @@ struct irq_chip {
79486 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
79487
79488 unsigned long flags;
79489-};
79490+} __do_const;
79491+typedef struct irq_chip __no_const irq_chip_no_const;
79492
79493 /*
79494 * irq_chip specific flags
79495diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
79496index cac496b..ffa0567 100644
79497--- a/include/linux/irqchip/arm-gic.h
79498+++ b/include/linux/irqchip/arm-gic.h
79499@@ -61,9 +61,11 @@
79500
79501 #ifndef __ASSEMBLY__
79502
79503+#include <linux/irq.h>
79504+
79505 struct device_node;
79506
79507-extern struct irq_chip gic_arch_extn;
79508+extern irq_chip_no_const gic_arch_extn;
79509
79510 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
79511 u32 offset, struct device_node *);
79512diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
79513index d235e88..8ccbe74 100644
79514--- a/include/linux/jiffies.h
79515+++ b/include/linux/jiffies.h
79516@@ -292,14 +292,14 @@ extern unsigned long preset_lpj;
79517 /*
79518 * Convert various time units to each other:
79519 */
79520-extern unsigned int jiffies_to_msecs(const unsigned long j);
79521-extern unsigned int jiffies_to_usecs(const unsigned long j);
79522-extern unsigned long msecs_to_jiffies(const unsigned int m);
79523-extern unsigned long usecs_to_jiffies(const unsigned int u);
79524-extern unsigned long timespec_to_jiffies(const struct timespec *value);
79525+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
79526+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
79527+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
79528+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
79529+extern unsigned long timespec_to_jiffies(const struct timespec *value) __intentional_overflow(-1);
79530 extern void jiffies_to_timespec(const unsigned long jiffies,
79531 struct timespec *value);
79532-extern unsigned long timeval_to_jiffies(const struct timeval *value);
79533+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
79534 extern void jiffies_to_timeval(const unsigned long jiffies,
79535 struct timeval *value);
79536
79537diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
79538index 6883e19..e854fcb 100644
79539--- a/include/linux/kallsyms.h
79540+++ b/include/linux/kallsyms.h
79541@@ -15,7 +15,8 @@
79542
79543 struct module;
79544
79545-#ifdef CONFIG_KALLSYMS
79546+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
79547+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
79548 /* Lookup the address for a symbol. Returns 0 if not found. */
79549 unsigned long kallsyms_lookup_name(const char *name);
79550
79551@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
79552 /* Stupid that this does nothing, but I didn't create this mess. */
79553 #define __print_symbol(fmt, addr)
79554 #endif /*CONFIG_KALLSYMS*/
79555+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
79556+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
79557+extern unsigned long kallsyms_lookup_name(const char *name);
79558+extern void __print_symbol(const char *fmt, unsigned long address);
79559+extern int sprint_backtrace(char *buffer, unsigned long address);
79560+extern int sprint_symbol(char *buffer, unsigned long address);
79561+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
79562+const char *kallsyms_lookup(unsigned long addr,
79563+ unsigned long *symbolsize,
79564+ unsigned long *offset,
79565+ char **modname, char *namebuf);
79566+extern int kallsyms_lookup_size_offset(unsigned long addr,
79567+ unsigned long *symbolsize,
79568+ unsigned long *offset);
79569+#endif
79570
79571 /* This macro allows us to keep printk typechecking */
79572 static __printf(1, 2)
79573diff --git a/include/linux/key-type.h b/include/linux/key-type.h
79574index a74c3a8..28d3f21 100644
79575--- a/include/linux/key-type.h
79576+++ b/include/linux/key-type.h
79577@@ -131,7 +131,7 @@ struct key_type {
79578 /* internal fields */
79579 struct list_head link; /* link in types list */
79580 struct lock_class_key lock_class; /* key->sem lock class */
79581-};
79582+} __do_const;
79583
79584 extern struct key_type key_type_keyring;
79585
79586diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
79587index dfb4f2f..7927e62 100644
79588--- a/include/linux/kgdb.h
79589+++ b/include/linux/kgdb.h
79590@@ -52,7 +52,7 @@ extern int kgdb_connected;
79591 extern int kgdb_io_module_registered;
79592
79593 extern atomic_t kgdb_setting_breakpoint;
79594-extern atomic_t kgdb_cpu_doing_single_step;
79595+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
79596
79597 extern struct task_struct *kgdb_usethread;
79598 extern struct task_struct *kgdb_contthread;
79599@@ -254,7 +254,7 @@ struct kgdb_arch {
79600 void (*correct_hw_break)(void);
79601
79602 void (*enable_nmi)(bool on);
79603-};
79604+} __do_const;
79605
79606 /**
79607 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
79608@@ -279,7 +279,7 @@ struct kgdb_io {
79609 void (*pre_exception) (void);
79610 void (*post_exception) (void);
79611 int is_console;
79612-};
79613+} __do_const;
79614
79615 extern struct kgdb_arch arch_kgdb_ops;
79616
79617diff --git a/include/linux/kmod.h b/include/linux/kmod.h
79618index 0555cc6..40116ce 100644
79619--- a/include/linux/kmod.h
79620+++ b/include/linux/kmod.h
79621@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
79622 * usually useless though. */
79623 extern __printf(2, 3)
79624 int __request_module(bool wait, const char *name, ...);
79625+extern __printf(3, 4)
79626+int ___request_module(bool wait, char *param_name, const char *name, ...);
79627 #define request_module(mod...) __request_module(true, mod)
79628 #define request_module_nowait(mod...) __request_module(false, mod)
79629 #define try_then_request_module(x, mod...) \
79630@@ -57,6 +59,9 @@ struct subprocess_info {
79631 struct work_struct work;
79632 struct completion *complete;
79633 char *path;
79634+#ifdef CONFIG_GRKERNSEC
79635+ char *origpath;
79636+#endif
79637 char **argv;
79638 char **envp;
79639 int wait;
79640diff --git a/include/linux/kobject.h b/include/linux/kobject.h
79641index e7ba650..0af3acb 100644
79642--- a/include/linux/kobject.h
79643+++ b/include/linux/kobject.h
79644@@ -116,7 +116,7 @@ struct kobj_type {
79645 struct attribute **default_attrs;
79646 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
79647 const void *(*namespace)(struct kobject *kobj);
79648-};
79649+} __do_const;
79650
79651 struct kobj_uevent_env {
79652 char *envp[UEVENT_NUM_ENVP];
79653@@ -139,6 +139,7 @@ struct kobj_attribute {
79654 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
79655 const char *buf, size_t count);
79656 };
79657+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
79658
79659 extern const struct sysfs_ops kobj_sysfs_ops;
79660
79661@@ -166,7 +167,7 @@ struct kset {
79662 spinlock_t list_lock;
79663 struct kobject kobj;
79664 const struct kset_uevent_ops *uevent_ops;
79665-};
79666+} __randomize_layout;
79667
79668 extern void kset_init(struct kset *kset);
79669 extern int __must_check kset_register(struct kset *kset);
79670diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
79671index df32d25..fb52e27 100644
79672--- a/include/linux/kobject_ns.h
79673+++ b/include/linux/kobject_ns.h
79674@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
79675 const void *(*netlink_ns)(struct sock *sk);
79676 const void *(*initial_ns)(void);
79677 void (*drop_ns)(void *);
79678-};
79679+} __do_const;
79680
79681 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
79682 int kobj_ns_type_registered(enum kobj_ns_type type);
79683diff --git a/include/linux/kref.h b/include/linux/kref.h
79684index 484604d..0f6c5b6 100644
79685--- a/include/linux/kref.h
79686+++ b/include/linux/kref.h
79687@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
79688 static inline int kref_sub(struct kref *kref, unsigned int count,
79689 void (*release)(struct kref *kref))
79690 {
79691- WARN_ON(release == NULL);
79692+ BUG_ON(release == NULL);
79693
79694 if (atomic_sub_and_test((int) count, &kref->refcount)) {
79695 release(kref);
79696diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
79697index 9523d2a..16c0424 100644
79698--- a/include/linux/kvm_host.h
79699+++ b/include/linux/kvm_host.h
79700@@ -457,7 +457,7 @@ static inline void kvm_irqfd_exit(void)
79701 {
79702 }
79703 #endif
79704-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79705+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79706 struct module *module);
79707 void kvm_exit(void);
79708
79709@@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
79710 struct kvm_guest_debug *dbg);
79711 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
79712
79713-int kvm_arch_init(void *opaque);
79714+int kvm_arch_init(const void *opaque);
79715 void kvm_arch_exit(void);
79716
79717 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
79718diff --git a/include/linux/libata.h b/include/linux/libata.h
79719index bec6dbe..2873d64 100644
79720--- a/include/linux/libata.h
79721+++ b/include/linux/libata.h
79722@@ -975,7 +975,7 @@ struct ata_port_operations {
79723 * fields must be pointers.
79724 */
79725 const struct ata_port_operations *inherits;
79726-};
79727+} __do_const;
79728
79729 struct ata_port_info {
79730 unsigned long flags;
79731diff --git a/include/linux/linkage.h b/include/linux/linkage.h
79732index d3e8ad2..a949f68 100644
79733--- a/include/linux/linkage.h
79734+++ b/include/linux/linkage.h
79735@@ -31,6 +31,7 @@
79736 #endif
79737
79738 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
79739+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
79740 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
79741
79742 /*
79743diff --git a/include/linux/list.h b/include/linux/list.h
79744index ef95941..82db65a 100644
79745--- a/include/linux/list.h
79746+++ b/include/linux/list.h
79747@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
79748 extern void list_del(struct list_head *entry);
79749 #endif
79750
79751+extern void __pax_list_add(struct list_head *new,
79752+ struct list_head *prev,
79753+ struct list_head *next);
79754+static inline void pax_list_add(struct list_head *new, struct list_head *head)
79755+{
79756+ __pax_list_add(new, head, head->next);
79757+}
79758+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
79759+{
79760+ __pax_list_add(new, head->prev, head);
79761+}
79762+extern void pax_list_del(struct list_head *entry);
79763+
79764 /**
79765 * list_replace - replace old entry by new one
79766 * @old : the element to be replaced
79767@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
79768 INIT_LIST_HEAD(entry);
79769 }
79770
79771+extern void pax_list_del_init(struct list_head *entry);
79772+
79773 /**
79774 * list_move - delete from one list and add as another's head
79775 * @list: the entry to move
79776diff --git a/include/linux/math64.h b/include/linux/math64.h
79777index c45c089..298841c 100644
79778--- a/include/linux/math64.h
79779+++ b/include/linux/math64.h
79780@@ -15,7 +15,7 @@
79781 * This is commonly provided by 32bit archs to provide an optimized 64bit
79782 * divide.
79783 */
79784-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79785+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79786 {
79787 *remainder = dividend % divisor;
79788 return dividend / divisor;
79789@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
79790 /**
79791 * div64_u64 - unsigned 64bit divide with 64bit divisor
79792 */
79793-static inline u64 div64_u64(u64 dividend, u64 divisor)
79794+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
79795 {
79796 return dividend / divisor;
79797 }
79798@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
79799 #define div64_ul(x, y) div_u64((x), (y))
79800
79801 #ifndef div_u64_rem
79802-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79803+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79804 {
79805 *remainder = do_div(dividend, divisor);
79806 return dividend;
79807@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
79808 #endif
79809
79810 #ifndef div64_u64
79811-extern u64 div64_u64(u64 dividend, u64 divisor);
79812+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
79813 #endif
79814
79815 #ifndef div64_s64
79816@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
79817 * divide.
79818 */
79819 #ifndef div_u64
79820-static inline u64 div_u64(u64 dividend, u32 divisor)
79821+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
79822 {
79823 u32 remainder;
79824 return div_u64_rem(dividend, divisor, &remainder);
79825diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
79826index 9fe426b..8148be6 100644
79827--- a/include/linux/mempolicy.h
79828+++ b/include/linux/mempolicy.h
79829@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
79830 }
79831
79832 #define vma_policy(vma) ((vma)->vm_policy)
79833+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
79834+{
79835+ vma->vm_policy = pol;
79836+}
79837
79838 static inline void mpol_get(struct mempolicy *pol)
79839 {
79840@@ -241,6 +245,9 @@ mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
79841 }
79842
79843 #define vma_policy(vma) NULL
79844+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
79845+{
79846+}
79847
79848 static inline int
79849 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
79850diff --git a/include/linux/mm.h b/include/linux/mm.h
79851index 5360b82..4eedf45 100644
79852--- a/include/linux/mm.h
79853+++ b/include/linux/mm.h
79854@@ -117,6 +117,11 @@ extern unsigned int kobjsize(const void *objp);
79855 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
79856 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
79857 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
79858+
79859+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
79860+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
79861+#endif
79862+
79863 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
79864
79865 #ifdef CONFIG_MEM_SOFT_DIRTY
79866@@ -219,8 +224,8 @@ struct vm_operations_struct {
79867 /* called by access_process_vm when get_user_pages() fails, typically
79868 * for use by special VMAs that can switch between memory and hardware
79869 */
79870- int (*access)(struct vm_area_struct *vma, unsigned long addr,
79871- void *buf, int len, int write);
79872+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
79873+ void *buf, size_t len, int write);
79874 #ifdef CONFIG_NUMA
79875 /*
79876 * set_policy() op must add a reference to any non-NULL @new mempolicy
79877@@ -250,6 +255,7 @@ struct vm_operations_struct {
79878 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
79879 unsigned long size, pgoff_t pgoff);
79880 };
79881+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
79882
79883 struct mmu_gather;
79884 struct inode;
79885@@ -1074,8 +1080,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
79886 unsigned long *pfn);
79887 int follow_phys(struct vm_area_struct *vma, unsigned long address,
79888 unsigned int flags, unsigned long *prot, resource_size_t *phys);
79889-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
79890- void *buf, int len, int write);
79891+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
79892+ void *buf, size_t len, int write);
79893
79894 static inline void unmap_shared_mapping_range(struct address_space *mapping,
79895 loff_t const holebegin, loff_t const holelen)
79896@@ -1114,9 +1120,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
79897 }
79898 #endif
79899
79900-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
79901-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
79902- void *buf, int len, int write);
79903+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
79904+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
79905+ void *buf, size_t len, int write);
79906
79907 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
79908 unsigned long start, unsigned long nr_pages,
79909@@ -1148,34 +1154,6 @@ int set_page_dirty(struct page *page);
79910 int set_page_dirty_lock(struct page *page);
79911 int clear_page_dirty_for_io(struct page *page);
79912
79913-/* Is the vma a continuation of the stack vma above it? */
79914-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
79915-{
79916- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
79917-}
79918-
79919-static inline int stack_guard_page_start(struct vm_area_struct *vma,
79920- unsigned long addr)
79921-{
79922- return (vma->vm_flags & VM_GROWSDOWN) &&
79923- (vma->vm_start == addr) &&
79924- !vma_growsdown(vma->vm_prev, addr);
79925-}
79926-
79927-/* Is the vma a continuation of the stack vma below it? */
79928-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
79929-{
79930- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
79931-}
79932-
79933-static inline int stack_guard_page_end(struct vm_area_struct *vma,
79934- unsigned long addr)
79935-{
79936- return (vma->vm_flags & VM_GROWSUP) &&
79937- (vma->vm_end == addr) &&
79938- !vma_growsup(vma->vm_next, addr);
79939-}
79940-
79941 extern pid_t
79942 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
79943
79944@@ -1275,6 +1253,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
79945 }
79946 #endif
79947
79948+#ifdef CONFIG_MMU
79949+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
79950+#else
79951+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
79952+{
79953+ return __pgprot(0);
79954+}
79955+#endif
79956+
79957 int vma_wants_writenotify(struct vm_area_struct *vma);
79958
79959 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
79960@@ -1293,8 +1280,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
79961 {
79962 return 0;
79963 }
79964+
79965+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
79966+ unsigned long address)
79967+{
79968+ return 0;
79969+}
79970 #else
79971 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
79972+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
79973 #endif
79974
79975 #ifdef __PAGETABLE_PMD_FOLDED
79976@@ -1303,8 +1297,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
79977 {
79978 return 0;
79979 }
79980+
79981+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
79982+ unsigned long address)
79983+{
79984+ return 0;
79985+}
79986 #else
79987 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
79988+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
79989 #endif
79990
79991 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
79992@@ -1322,11 +1323,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
79993 NULL: pud_offset(pgd, address);
79994 }
79995
79996+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
79997+{
79998+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
79999+ NULL: pud_offset(pgd, address);
80000+}
80001+
80002 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80003 {
80004 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
80005 NULL: pmd_offset(pud, address);
80006 }
80007+
80008+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80009+{
80010+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
80011+ NULL: pmd_offset(pud, address);
80012+}
80013 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
80014
80015 #if USE_SPLIT_PTE_PTLOCKS
80016@@ -1704,7 +1717,7 @@ extern int install_special_mapping(struct mm_struct *mm,
80017 unsigned long addr, unsigned long len,
80018 unsigned long flags, struct page **pages);
80019
80020-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
80021+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
80022
80023 extern unsigned long mmap_region(struct file *file, unsigned long addr,
80024 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
80025@@ -1712,6 +1725,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80026 unsigned long len, unsigned long prot, unsigned long flags,
80027 unsigned long pgoff, unsigned long *populate);
80028 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
80029+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
80030
80031 #ifdef CONFIG_MMU
80032 extern int __mm_populate(unsigned long addr, unsigned long len,
80033@@ -1740,10 +1754,11 @@ struct vm_unmapped_area_info {
80034 unsigned long high_limit;
80035 unsigned long align_mask;
80036 unsigned long align_offset;
80037+ unsigned long threadstack_offset;
80038 };
80039
80040-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
80041-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80042+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
80043+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
80044
80045 /*
80046 * Search for an unmapped address range.
80047@@ -1755,7 +1770,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80048 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
80049 */
80050 static inline unsigned long
80051-vm_unmapped_area(struct vm_unmapped_area_info *info)
80052+vm_unmapped_area(const struct vm_unmapped_area_info *info)
80053 {
80054 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
80055 return unmapped_area(info);
80056@@ -1818,6 +1833,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
80057 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
80058 struct vm_area_struct **pprev);
80059
80060+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
80061+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
80062+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
80063+
80064 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
80065 NULL if none. Assume start_addr < end_addr. */
80066 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
80067@@ -1846,15 +1865,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
80068 return vma;
80069 }
80070
80071-#ifdef CONFIG_MMU
80072-pgprot_t vm_get_page_prot(unsigned long vm_flags);
80073-#else
80074-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
80075-{
80076- return __pgprot(0);
80077-}
80078-#endif
80079-
80080 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
80081 unsigned long change_prot_numa(struct vm_area_struct *vma,
80082 unsigned long start, unsigned long end);
80083@@ -1906,6 +1916,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
80084 static inline void vm_stat_account(struct mm_struct *mm,
80085 unsigned long flags, struct file *file, long pages)
80086 {
80087+
80088+#ifdef CONFIG_PAX_RANDMMAP
80089+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
80090+#endif
80091+
80092 mm->total_vm += pages;
80093 }
80094 #endif /* CONFIG_PROC_FS */
80095@@ -1987,7 +2002,7 @@ extern int unpoison_memory(unsigned long pfn);
80096 extern int sysctl_memory_failure_early_kill;
80097 extern int sysctl_memory_failure_recovery;
80098 extern void shake_page(struct page *p, int access);
80099-extern atomic_long_t num_poisoned_pages;
80100+extern atomic_long_unchecked_t num_poisoned_pages;
80101 extern int soft_offline_page(struct page *page, int flags);
80102
80103 extern void dump_page(struct page *page);
80104@@ -2024,5 +2039,11 @@ void __init setup_nr_node_ids(void);
80105 static inline void setup_nr_node_ids(void) {}
80106 #endif
80107
80108+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
80109+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
80110+#else
80111+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
80112+#endif
80113+
80114 #endif /* __KERNEL__ */
80115 #endif /* _LINUX_MM_H */
80116diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
80117index 290901a..e99b01c 100644
80118--- a/include/linux/mm_types.h
80119+++ b/include/linux/mm_types.h
80120@@ -307,7 +307,9 @@ struct vm_area_struct {
80121 #ifdef CONFIG_NUMA
80122 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
80123 #endif
80124-};
80125+
80126+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
80127+} __randomize_layout;
80128
80129 struct core_thread {
80130 struct task_struct *task;
80131@@ -453,7 +455,25 @@ struct mm_struct {
80132 bool tlb_flush_pending;
80133 #endif
80134 struct uprobes_state uprobes_state;
80135-};
80136+
80137+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
80138+ unsigned long pax_flags;
80139+#endif
80140+
80141+#ifdef CONFIG_PAX_DLRESOLVE
80142+ unsigned long call_dl_resolve;
80143+#endif
80144+
80145+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
80146+ unsigned long call_syscall;
80147+#endif
80148+
80149+#ifdef CONFIG_PAX_ASLR
80150+ unsigned long delta_mmap; /* randomized offset */
80151+ unsigned long delta_stack; /* randomized offset */
80152+#endif
80153+
80154+} __randomize_layout;
80155
80156 static inline void mm_init_cpumask(struct mm_struct *mm)
80157 {
80158diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
80159index c5d5278..f0b68c8 100644
80160--- a/include/linux/mmiotrace.h
80161+++ b/include/linux/mmiotrace.h
80162@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
80163 /* Called from ioremap.c */
80164 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
80165 void __iomem *addr);
80166-extern void mmiotrace_iounmap(volatile void __iomem *addr);
80167+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
80168
80169 /* For anyone to insert markers. Remember trailing newline. */
80170 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
80171@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
80172 {
80173 }
80174
80175-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
80176+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
80177 {
80178 }
80179
80180diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
80181index bd791e4..8617c34f 100644
80182--- a/include/linux/mmzone.h
80183+++ b/include/linux/mmzone.h
80184@@ -396,7 +396,7 @@ struct zone {
80185 unsigned long flags; /* zone flags, see below */
80186
80187 /* Zone statistics */
80188- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80189+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80190
80191 /*
80192 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
80193diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
80194index 45e9214..a7227d6 100644
80195--- a/include/linux/mod_devicetable.h
80196+++ b/include/linux/mod_devicetable.h
80197@@ -13,7 +13,7 @@
80198 typedef unsigned long kernel_ulong_t;
80199 #endif
80200
80201-#define PCI_ANY_ID (~0)
80202+#define PCI_ANY_ID ((__u16)~0)
80203
80204 struct pci_device_id {
80205 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
80206@@ -139,7 +139,7 @@ struct usb_device_id {
80207 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
80208 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
80209
80210-#define HID_ANY_ID (~0)
80211+#define HID_ANY_ID (~0U)
80212 #define HID_BUS_ANY 0xffff
80213 #define HID_GROUP_ANY 0x0000
80214
80215@@ -467,7 +467,7 @@ struct dmi_system_id {
80216 const char *ident;
80217 struct dmi_strmatch matches[4];
80218 void *driver_data;
80219-};
80220+} __do_const;
80221 /*
80222 * struct dmi_device_id appears during expansion of
80223 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
80224diff --git a/include/linux/module.h b/include/linux/module.h
80225index 15cd6b1..f6e2e6a 100644
80226--- a/include/linux/module.h
80227+++ b/include/linux/module.h
80228@@ -17,9 +17,11 @@
80229 #include <linux/moduleparam.h>
80230 #include <linux/tracepoint.h>
80231 #include <linux/export.h>
80232+#include <linux/fs.h>
80233
80234 #include <linux/percpu.h>
80235 #include <asm/module.h>
80236+#include <asm/pgtable.h>
80237
80238 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
80239 #define MODULE_SIG_STRING "~Module signature appended~\n"
80240@@ -43,7 +45,7 @@ struct module_kobject {
80241 struct kobject *drivers_dir;
80242 struct module_param_attrs *mp;
80243 struct completion *kobj_completion;
80244-};
80245+} __randomize_layout;
80246
80247 struct module_attribute {
80248 struct attribute attr;
80249@@ -55,12 +57,13 @@ struct module_attribute {
80250 int (*test)(struct module *);
80251 void (*free)(struct module *);
80252 };
80253+typedef struct module_attribute __no_const module_attribute_no_const;
80254
80255 struct module_version_attribute {
80256 struct module_attribute mattr;
80257 const char *module_name;
80258 const char *version;
80259-} __attribute__ ((__aligned__(sizeof(void *))));
80260+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
80261
80262 extern ssize_t __modver_version_show(struct module_attribute *,
80263 struct module_kobject *, char *);
80264@@ -238,7 +241,7 @@ struct module
80265
80266 /* Sysfs stuff. */
80267 struct module_kobject mkobj;
80268- struct module_attribute *modinfo_attrs;
80269+ module_attribute_no_const *modinfo_attrs;
80270 const char *version;
80271 const char *srcversion;
80272 struct kobject *holders_dir;
80273@@ -287,19 +290,16 @@ struct module
80274 int (*init)(void);
80275
80276 /* If this is non-NULL, vfree after init() returns */
80277- void *module_init;
80278+ void *module_init_rx, *module_init_rw;
80279
80280 /* Here is the actual code + data, vfree'd on unload. */
80281- void *module_core;
80282+ void *module_core_rx, *module_core_rw;
80283
80284 /* Here are the sizes of the init and core sections */
80285- unsigned int init_size, core_size;
80286+ unsigned int init_size_rw, core_size_rw;
80287
80288 /* The size of the executable code in each section. */
80289- unsigned int init_text_size, core_text_size;
80290-
80291- /* Size of RO sections of the module (text+rodata) */
80292- unsigned int init_ro_size, core_ro_size;
80293+ unsigned int init_size_rx, core_size_rx;
80294
80295 /* Arch-specific module values */
80296 struct mod_arch_specific arch;
80297@@ -355,6 +355,10 @@ struct module
80298 #ifdef CONFIG_EVENT_TRACING
80299 struct ftrace_event_call **trace_events;
80300 unsigned int num_trace_events;
80301+ struct file_operations trace_id;
80302+ struct file_operations trace_enable;
80303+ struct file_operations trace_format;
80304+ struct file_operations trace_filter;
80305 #endif
80306 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
80307 unsigned int num_ftrace_callsites;
80308@@ -378,7 +382,7 @@ struct module
80309 ctor_fn_t *ctors;
80310 unsigned int num_ctors;
80311 #endif
80312-};
80313+} __randomize_layout;
80314 #ifndef MODULE_ARCH_INIT
80315 #define MODULE_ARCH_INIT {}
80316 #endif
80317@@ -399,16 +403,46 @@ bool is_module_address(unsigned long addr);
80318 bool is_module_percpu_address(unsigned long addr);
80319 bool is_module_text_address(unsigned long addr);
80320
80321+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
80322+{
80323+
80324+#ifdef CONFIG_PAX_KERNEXEC
80325+ if (ktla_ktva(addr) >= (unsigned long)start &&
80326+ ktla_ktva(addr) < (unsigned long)start + size)
80327+ return 1;
80328+#endif
80329+
80330+ return ((void *)addr >= start && (void *)addr < start + size);
80331+}
80332+
80333+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
80334+{
80335+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
80336+}
80337+
80338+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
80339+{
80340+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
80341+}
80342+
80343+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
80344+{
80345+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
80346+}
80347+
80348+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
80349+{
80350+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
80351+}
80352+
80353 static inline int within_module_core(unsigned long addr, const struct module *mod)
80354 {
80355- return (unsigned long)mod->module_core <= addr &&
80356- addr < (unsigned long)mod->module_core + mod->core_size;
80357+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
80358 }
80359
80360 static inline int within_module_init(unsigned long addr, const struct module *mod)
80361 {
80362- return (unsigned long)mod->module_init <= addr &&
80363- addr < (unsigned long)mod->module_init + mod->init_size;
80364+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
80365 }
80366
80367 /* Search for module by name: must hold module_mutex. */
80368diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
80369index 560ca53..ef621ef 100644
80370--- a/include/linux/moduleloader.h
80371+++ b/include/linux/moduleloader.h
80372@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
80373 sections. Returns NULL on failure. */
80374 void *module_alloc(unsigned long size);
80375
80376+#ifdef CONFIG_PAX_KERNEXEC
80377+void *module_alloc_exec(unsigned long size);
80378+#else
80379+#define module_alloc_exec(x) module_alloc(x)
80380+#endif
80381+
80382 /* Free memory returned from module_alloc. */
80383 void module_free(struct module *mod, void *module_region);
80384
80385+#ifdef CONFIG_PAX_KERNEXEC
80386+void module_free_exec(struct module *mod, void *module_region);
80387+#else
80388+#define module_free_exec(x, y) module_free((x), (y))
80389+#endif
80390+
80391 /*
80392 * Apply the given relocation to the (simplified) ELF. Return -error
80393 * or 0.
80394@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
80395 unsigned int relsec,
80396 struct module *me)
80397 {
80398+#ifdef CONFIG_MODULES
80399 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80400+#endif
80401 return -ENOEXEC;
80402 }
80403 #endif
80404@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
80405 unsigned int relsec,
80406 struct module *me)
80407 {
80408+#ifdef CONFIG_MODULES
80409 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80410+#endif
80411 return -ENOEXEC;
80412 }
80413 #endif
80414diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
80415index c3eb102..073c4a6 100644
80416--- a/include/linux/moduleparam.h
80417+++ b/include/linux/moduleparam.h
80418@@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
80419 * @len is usually just sizeof(string).
80420 */
80421 #define module_param_string(name, string, len, perm) \
80422- static const struct kparam_string __param_string_##name \
80423+ static const struct kparam_string __param_string_##name __used \
80424 = { len, string }; \
80425 __module_param_call(MODULE_PARAM_PREFIX, name, \
80426 &param_ops_string, \
80427@@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
80428 */
80429 #define module_param_array_named(name, array, type, nump, perm) \
80430 param_check_##type(name, &(array)[0]); \
80431- static const struct kparam_array __param_arr_##name \
80432+ static const struct kparam_array __param_arr_##name __used \
80433 = { .max = ARRAY_SIZE(array), .num = nump, \
80434 .ops = &param_ops_##type, \
80435 .elemsize = sizeof(array[0]), .elem = array }; \
80436diff --git a/include/linux/mount.h b/include/linux/mount.h
80437index 371d346..fba2819 100644
80438--- a/include/linux/mount.h
80439+++ b/include/linux/mount.h
80440@@ -56,7 +56,7 @@ struct vfsmount {
80441 struct dentry *mnt_root; /* root of the mounted tree */
80442 struct super_block *mnt_sb; /* pointer to superblock */
80443 int mnt_flags;
80444-};
80445+} __randomize_layout;
80446
80447 struct file; /* forward dec */
80448
80449diff --git a/include/linux/namei.h b/include/linux/namei.h
80450index 492de72..1bddcd4 100644
80451--- a/include/linux/namei.h
80452+++ b/include/linux/namei.h
80453@@ -19,7 +19,7 @@ struct nameidata {
80454 unsigned seq, m_seq;
80455 int last_type;
80456 unsigned depth;
80457- char *saved_names[MAX_NESTED_LINKS + 1];
80458+ const char *saved_names[MAX_NESTED_LINKS + 1];
80459 };
80460
80461 /*
80462@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
80463
80464 extern void nd_jump_link(struct nameidata *nd, struct path *path);
80465
80466-static inline void nd_set_link(struct nameidata *nd, char *path)
80467+static inline void nd_set_link(struct nameidata *nd, const char *path)
80468 {
80469 nd->saved_names[nd->depth] = path;
80470 }
80471
80472-static inline char *nd_get_link(struct nameidata *nd)
80473+static inline const char *nd_get_link(const struct nameidata *nd)
80474 {
80475 return nd->saved_names[nd->depth];
80476 }
80477diff --git a/include/linux/net.h b/include/linux/net.h
80478index 69be3e6..0fb422d 100644
80479--- a/include/linux/net.h
80480+++ b/include/linux/net.h
80481@@ -192,7 +192,7 @@ struct net_proto_family {
80482 int (*create)(struct net *net, struct socket *sock,
80483 int protocol, int kern);
80484 struct module *owner;
80485-};
80486+} __do_const;
80487
80488 struct iovec;
80489 struct kvec;
80490diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
80491index 2177a6b..67fc561 100644
80492--- a/include/linux/netdevice.h
80493+++ b/include/linux/netdevice.h
80494@@ -1129,6 +1129,7 @@ struct net_device_ops {
80495 struct net_device *dev,
80496 void *priv);
80497 };
80498+typedef struct net_device_ops __no_const net_device_ops_no_const;
80499
80500 /*
80501 * The DEVICE structure.
80502@@ -1211,7 +1212,7 @@ struct net_device {
80503 int iflink;
80504
80505 struct net_device_stats stats;
80506- atomic_long_t rx_dropped; /* dropped packets by core network
80507+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
80508 * Do not use this in drivers.
80509 */
80510
80511diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
80512index 2077489..a15e561 100644
80513--- a/include/linux/netfilter.h
80514+++ b/include/linux/netfilter.h
80515@@ -84,7 +84,7 @@ struct nf_sockopt_ops {
80516 #endif
80517 /* Use the module struct to lock set/get code in place */
80518 struct module *owner;
80519-};
80520+} __do_const;
80521
80522 /* Function to register/unregister hook points. */
80523 int nf_register_hook(struct nf_hook_ops *reg);
80524diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
80525index 28c7436..2d6156a 100644
80526--- a/include/linux/netfilter/nfnetlink.h
80527+++ b/include/linux/netfilter/nfnetlink.h
80528@@ -19,7 +19,7 @@ struct nfnl_callback {
80529 const struct nlattr * const cda[]);
80530 const struct nla_policy *policy; /* netlink attribute policy */
80531 const u_int16_t attr_count; /* number of nlattr's */
80532-};
80533+} __do_const;
80534
80535 struct nfnetlink_subsystem {
80536 const char *name;
80537diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
80538new file mode 100644
80539index 0000000..33f4af8
80540--- /dev/null
80541+++ b/include/linux/netfilter/xt_gradm.h
80542@@ -0,0 +1,9 @@
80543+#ifndef _LINUX_NETFILTER_XT_GRADM_H
80544+#define _LINUX_NETFILTER_XT_GRADM_H 1
80545+
80546+struct xt_gradm_mtinfo {
80547+ __u16 flags;
80548+ __u16 invflags;
80549+};
80550+
80551+#endif
80552diff --git a/include/linux/nls.h b/include/linux/nls.h
80553index 5dc635f..35f5e11 100644
80554--- a/include/linux/nls.h
80555+++ b/include/linux/nls.h
80556@@ -31,7 +31,7 @@ struct nls_table {
80557 const unsigned char *charset2upper;
80558 struct module *owner;
80559 struct nls_table *next;
80560-};
80561+} __do_const;
80562
80563 /* this value hold the maximum octet of charset */
80564 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
80565diff --git a/include/linux/notifier.h b/include/linux/notifier.h
80566index d14a4c3..a078786 100644
80567--- a/include/linux/notifier.h
80568+++ b/include/linux/notifier.h
80569@@ -54,7 +54,8 @@ struct notifier_block {
80570 notifier_fn_t notifier_call;
80571 struct notifier_block __rcu *next;
80572 int priority;
80573-};
80574+} __do_const;
80575+typedef struct notifier_block __no_const notifier_block_no_const;
80576
80577 struct atomic_notifier_head {
80578 spinlock_t lock;
80579diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
80580index b2a0f15..4d7da32 100644
80581--- a/include/linux/oprofile.h
80582+++ b/include/linux/oprofile.h
80583@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
80584 int oprofilefs_create_ro_ulong(struct dentry * root,
80585 char const * name, ulong * val);
80586
80587-/** Create a file for read-only access to an atomic_t. */
80588+/** Create a file for read-only access to an atomic_unchecked_t. */
80589 int oprofilefs_create_ro_atomic(struct dentry * root,
80590- char const * name, atomic_t * val);
80591+ char const * name, atomic_unchecked_t * val);
80592
80593 /** create a directory */
80594 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
80595diff --git a/include/linux/padata.h b/include/linux/padata.h
80596index 4386946..f50c615 100644
80597--- a/include/linux/padata.h
80598+++ b/include/linux/padata.h
80599@@ -129,7 +129,7 @@ struct parallel_data {
80600 struct padata_serial_queue __percpu *squeue;
80601 atomic_t reorder_objects;
80602 atomic_t refcnt;
80603- atomic_t seq_nr;
80604+ atomic_unchecked_t seq_nr;
80605 struct padata_cpumask cpumask;
80606 spinlock_t lock ____cacheline_aligned;
80607 unsigned int processed;
80608diff --git a/include/linux/path.h b/include/linux/path.h
80609index d137218..be0c176 100644
80610--- a/include/linux/path.h
80611+++ b/include/linux/path.h
80612@@ -1,13 +1,15 @@
80613 #ifndef _LINUX_PATH_H
80614 #define _LINUX_PATH_H
80615
80616+#include <linux/compiler.h>
80617+
80618 struct dentry;
80619 struct vfsmount;
80620
80621 struct path {
80622 struct vfsmount *mnt;
80623 struct dentry *dentry;
80624-};
80625+} __randomize_layout;
80626
80627 extern void path_get(const struct path *);
80628 extern void path_put(const struct path *);
80629diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
80630index a2e2f1d..8a391d2 100644
80631--- a/include/linux/pci_hotplug.h
80632+++ b/include/linux/pci_hotplug.h
80633@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
80634 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
80635 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
80636 int (*reset_slot) (struct hotplug_slot *slot, int probe);
80637-};
80638+} __do_const;
80639+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
80640
80641 /**
80642 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
80643diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
80644index 2e069d1..27054b8 100644
80645--- a/include/linux/perf_event.h
80646+++ b/include/linux/perf_event.h
80647@@ -327,8 +327,8 @@ struct perf_event {
80648
80649 enum perf_event_active_state state;
80650 unsigned int attach_state;
80651- local64_t count;
80652- atomic64_t child_count;
80653+ local64_t count; /* PaX: fix it one day */
80654+ atomic64_unchecked_t child_count;
80655
80656 /*
80657 * These are the total time in nanoseconds that the event
80658@@ -379,8 +379,8 @@ struct perf_event {
80659 * These accumulate total time (in nanoseconds) that children
80660 * events have been enabled and running, respectively.
80661 */
80662- atomic64_t child_total_time_enabled;
80663- atomic64_t child_total_time_running;
80664+ atomic64_unchecked_t child_total_time_enabled;
80665+ atomic64_unchecked_t child_total_time_running;
80666
80667 /*
80668 * Protect attach/detach and child_list:
80669@@ -707,7 +707,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
80670 entry->ip[entry->nr++] = ip;
80671 }
80672
80673-extern int sysctl_perf_event_paranoid;
80674+extern int sysctl_perf_event_legitimately_concerned;
80675 extern int sysctl_perf_event_mlock;
80676 extern int sysctl_perf_event_sample_rate;
80677 extern int sysctl_perf_cpu_time_max_percent;
80678@@ -722,19 +722,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
80679 loff_t *ppos);
80680
80681
80682+static inline bool perf_paranoid_any(void)
80683+{
80684+ return sysctl_perf_event_legitimately_concerned > 2;
80685+}
80686+
80687 static inline bool perf_paranoid_tracepoint_raw(void)
80688 {
80689- return sysctl_perf_event_paranoid > -1;
80690+ return sysctl_perf_event_legitimately_concerned > -1;
80691 }
80692
80693 static inline bool perf_paranoid_cpu(void)
80694 {
80695- return sysctl_perf_event_paranoid > 0;
80696+ return sysctl_perf_event_legitimately_concerned > 0;
80697 }
80698
80699 static inline bool perf_paranoid_kernel(void)
80700 {
80701- return sysctl_perf_event_paranoid > 1;
80702+ return sysctl_perf_event_legitimately_concerned > 1;
80703 }
80704
80705 extern void perf_event_init(void);
80706@@ -850,7 +855,7 @@ struct perf_pmu_events_attr {
80707 struct device_attribute attr;
80708 u64 id;
80709 const char *event_str;
80710-};
80711+} __do_const;
80712
80713 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
80714 static struct perf_pmu_events_attr _var = { \
80715diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
80716index 7246ef3..1539ea4 100644
80717--- a/include/linux/pid_namespace.h
80718+++ b/include/linux/pid_namespace.h
80719@@ -43,7 +43,7 @@ struct pid_namespace {
80720 int hide_pid;
80721 int reboot; /* group exit code if this pidns was rebooted */
80722 unsigned int proc_inum;
80723-};
80724+} __randomize_layout;
80725
80726 extern struct pid_namespace init_pid_ns;
80727
80728diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
80729index ab57526..94598804 100644
80730--- a/include/linux/pipe_fs_i.h
80731+++ b/include/linux/pipe_fs_i.h
80732@@ -47,10 +47,10 @@ struct pipe_inode_info {
80733 struct mutex mutex;
80734 wait_queue_head_t wait;
80735 unsigned int nrbufs, curbuf, buffers;
80736- unsigned int readers;
80737- unsigned int writers;
80738- unsigned int files;
80739- unsigned int waiting_writers;
80740+ atomic_t readers;
80741+ atomic_t writers;
80742+ atomic_t files;
80743+ atomic_t waiting_writers;
80744 unsigned int r_counter;
80745 unsigned int w_counter;
80746 struct page *tmp_page;
80747diff --git a/include/linux/pm.h b/include/linux/pm.h
80748index a224c7f..92d8a97 100644
80749--- a/include/linux/pm.h
80750+++ b/include/linux/pm.h
80751@@ -576,6 +576,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
80752 struct dev_pm_domain {
80753 struct dev_pm_ops ops;
80754 };
80755+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
80756
80757 /*
80758 * The PM_EVENT_ messages are also used by drivers implementing the legacy
80759diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
80760index 7c1d252..0e7061d 100644
80761--- a/include/linux/pm_domain.h
80762+++ b/include/linux/pm_domain.h
80763@@ -44,11 +44,11 @@ struct gpd_dev_ops {
80764 int (*thaw_early)(struct device *dev);
80765 int (*thaw)(struct device *dev);
80766 bool (*active_wakeup)(struct device *dev);
80767-};
80768+} __no_const;
80769
80770 struct gpd_cpu_data {
80771 unsigned int saved_exit_latency;
80772- struct cpuidle_state *idle_state;
80773+ cpuidle_state_no_const *idle_state;
80774 };
80775
80776 struct generic_pm_domain {
80777diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
80778index 6fa7cea..7bf6415 100644
80779--- a/include/linux/pm_runtime.h
80780+++ b/include/linux/pm_runtime.h
80781@@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
80782
80783 static inline void pm_runtime_mark_last_busy(struct device *dev)
80784 {
80785- ACCESS_ONCE(dev->power.last_busy) = jiffies;
80786+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
80787 }
80788
80789 #else /* !CONFIG_PM_RUNTIME */
80790diff --git a/include/linux/pnp.h b/include/linux/pnp.h
80791index 195aafc..49a7bc2 100644
80792--- a/include/linux/pnp.h
80793+++ b/include/linux/pnp.h
80794@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
80795 struct pnp_fixup {
80796 char id[7];
80797 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
80798-};
80799+} __do_const;
80800
80801 /* config parameters */
80802 #define PNP_CONFIG_NORMAL 0x0001
80803diff --git a/include/linux/poison.h b/include/linux/poison.h
80804index 2110a81..13a11bb 100644
80805--- a/include/linux/poison.h
80806+++ b/include/linux/poison.h
80807@@ -19,8 +19,8 @@
80808 * under normal circumstances, used to verify that nobody uses
80809 * non-initialized list entries.
80810 */
80811-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
80812-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
80813+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
80814+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
80815
80816 /********** include/linux/timer.h **********/
80817 /*
80818diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
80819index d8b187c3..9a9257a 100644
80820--- a/include/linux/power/smartreflex.h
80821+++ b/include/linux/power/smartreflex.h
80822@@ -238,7 +238,7 @@ struct omap_sr_class_data {
80823 int (*notify)(struct omap_sr *sr, u32 status);
80824 u8 notify_flags;
80825 u8 class_type;
80826-};
80827+} __do_const;
80828
80829 /**
80830 * struct omap_sr_nvalue_table - Smartreflex n-target value info
80831diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
80832index 4ea1d37..80f4b33 100644
80833--- a/include/linux/ppp-comp.h
80834+++ b/include/linux/ppp-comp.h
80835@@ -84,7 +84,7 @@ struct compressor {
80836 struct module *owner;
80837 /* Extra skb space needed by the compressor algorithm */
80838 unsigned int comp_extra;
80839-};
80840+} __do_const;
80841
80842 /*
80843 * The return value from decompress routine is the length of the
80844diff --git a/include/linux/preempt.h b/include/linux/preempt.h
80845index a3d9dc8..8af9922 100644
80846--- a/include/linux/preempt.h
80847+++ b/include/linux/preempt.h
80848@@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
80849 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
80850 #endif
80851
80852+#define raw_preempt_count_add(val) __preempt_count_add(val)
80853+#define raw_preempt_count_sub(val) __preempt_count_sub(val)
80854+
80855 #define __preempt_count_inc() __preempt_count_add(1)
80856 #define __preempt_count_dec() __preempt_count_sub(1)
80857
80858 #define preempt_count_inc() preempt_count_add(1)
80859+#define raw_preempt_count_inc() raw_preempt_count_add(1)
80860 #define preempt_count_dec() preempt_count_sub(1)
80861+#define raw_preempt_count_dec() raw_preempt_count_sub(1)
80862
80863 #ifdef CONFIG_PREEMPT_COUNT
80864
80865@@ -41,6 +46,12 @@ do { \
80866 barrier(); \
80867 } while (0)
80868
80869+#define raw_preempt_disable() \
80870+do { \
80871+ raw_preempt_count_inc(); \
80872+ barrier(); \
80873+} while (0)
80874+
80875 #define sched_preempt_enable_no_resched() \
80876 do { \
80877 barrier(); \
80878@@ -49,6 +60,12 @@ do { \
80879
80880 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
80881
80882+#define raw_preempt_enable_no_resched() \
80883+do { \
80884+ barrier(); \
80885+ raw_preempt_count_dec(); \
80886+} while (0)
80887+
80888 #ifdef CONFIG_PREEMPT
80889 #define preempt_enable() \
80890 do { \
80891@@ -105,8 +122,10 @@ do { \
80892 * region.
80893 */
80894 #define preempt_disable() barrier()
80895+#define raw_preempt_disable() barrier()
80896 #define sched_preempt_enable_no_resched() barrier()
80897 #define preempt_enable_no_resched() barrier()
80898+#define raw_preempt_enable_no_resched() barrier()
80899 #define preempt_enable() barrier()
80900 #define preempt_check_resched() do { } while (0)
80901
80902diff --git a/include/linux/printk.h b/include/linux/printk.h
80903index 6949258..7c4730e 100644
80904--- a/include/linux/printk.h
80905+++ b/include/linux/printk.h
80906@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
80907 void early_printk(const char *s, ...) { }
80908 #endif
80909
80910+extern int kptr_restrict;
80911+
80912 #ifdef CONFIG_PRINTK
80913 asmlinkage __printf(5, 0)
80914 int vprintk_emit(int facility, int level,
80915@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
80916
80917 extern int printk_delay_msec;
80918 extern int dmesg_restrict;
80919-extern int kptr_restrict;
80920
80921 extern void wake_up_klogd(void);
80922
80923diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
80924index 608e60a..c26f864 100644
80925--- a/include/linux/proc_fs.h
80926+++ b/include/linux/proc_fs.h
80927@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
80928 return proc_create_data(name, mode, parent, proc_fops, NULL);
80929 }
80930
80931+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
80932+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
80933+{
80934+#ifdef CONFIG_GRKERNSEC_PROC_USER
80935+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
80936+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
80937+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
80938+#else
80939+ return proc_create_data(name, mode, parent, proc_fops, NULL);
80940+#endif
80941+}
80942+
80943+
80944 extern void proc_set_size(struct proc_dir_entry *, loff_t);
80945 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
80946 extern void *PDE_DATA(const struct inode *);
80947diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
80948index 34a1e10..70f6bde 100644
80949--- a/include/linux/proc_ns.h
80950+++ b/include/linux/proc_ns.h
80951@@ -14,7 +14,7 @@ struct proc_ns_operations {
80952 void (*put)(void *ns);
80953 int (*install)(struct nsproxy *nsproxy, void *ns);
80954 unsigned int (*inum)(void *ns);
80955-};
80956+} __do_const __randomize_layout;
80957
80958 struct proc_ns {
80959 void *ns;
80960diff --git a/include/linux/quota.h b/include/linux/quota.h
80961index cc7494a..1e27036 100644
80962--- a/include/linux/quota.h
80963+++ b/include/linux/quota.h
80964@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
80965
80966 extern bool qid_eq(struct kqid left, struct kqid right);
80967 extern bool qid_lt(struct kqid left, struct kqid right);
80968-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
80969+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
80970 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
80971 extern bool qid_valid(struct kqid qid);
80972
80973diff --git a/include/linux/random.h b/include/linux/random.h
80974index 4002b3d..d5ad855 100644
80975--- a/include/linux/random.h
80976+++ b/include/linux/random.h
80977@@ -10,9 +10,19 @@
80978
80979
80980 extern void add_device_randomness(const void *, unsigned int);
80981+
80982+static inline void add_latent_entropy(void)
80983+{
80984+
80985+#ifdef LATENT_ENTROPY_PLUGIN
80986+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
80987+#endif
80988+
80989+}
80990+
80991 extern void add_input_randomness(unsigned int type, unsigned int code,
80992- unsigned int value);
80993-extern void add_interrupt_randomness(int irq, int irq_flags);
80994+ unsigned int value) __latent_entropy;
80995+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
80996
80997 extern void get_random_bytes(void *buf, int nbytes);
80998 extern void get_random_bytes_arch(void *buf, int nbytes);
80999@@ -23,10 +33,10 @@ extern int random_int_secret_init(void);
81000 extern const struct file_operations random_fops, urandom_fops;
81001 #endif
81002
81003-unsigned int get_random_int(void);
81004+unsigned int __intentional_overflow(-1) get_random_int(void);
81005 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
81006
81007-u32 prandom_u32(void);
81008+u32 prandom_u32(void) __intentional_overflow(-1);
81009 void prandom_bytes(void *buf, int nbytes);
81010 void prandom_seed(u32 seed);
81011 void prandom_reseed_late(void);
81012@@ -38,6 +48,11 @@ struct rnd_state {
81013 u32 prandom_u32_state(struct rnd_state *state);
81014 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
81015
81016+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
81017+{
81018+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
81019+}
81020+
81021 /*
81022 * Handle minimum values for seeds
81023 */
81024diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
81025index fea49b5..2ac22bb 100644
81026--- a/include/linux/rbtree_augmented.h
81027+++ b/include/linux/rbtree_augmented.h
81028@@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
81029 old->rbaugmented = rbcompute(old); \
81030 } \
81031 rbstatic const struct rb_augment_callbacks rbname = { \
81032- rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
81033+ .propagate = rbname ## _propagate, \
81034+ .copy = rbname ## _copy, \
81035+ .rotate = rbname ## _rotate \
81036 };
81037
81038
81039diff --git a/include/linux/rculist.h b/include/linux/rculist.h
81040index 45a0a9e..e83788e 100644
81041--- a/include/linux/rculist.h
81042+++ b/include/linux/rculist.h
81043@@ -29,8 +29,8 @@
81044 */
81045 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
81046 {
81047- ACCESS_ONCE(list->next) = list;
81048- ACCESS_ONCE(list->prev) = list;
81049+ ACCESS_ONCE_RW(list->next) = list;
81050+ ACCESS_ONCE_RW(list->prev) = list;
81051 }
81052
81053 /*
81054@@ -59,6 +59,9 @@ extern void __list_add_rcu(struct list_head *new,
81055 struct list_head *prev, struct list_head *next);
81056 #endif
81057
81058+extern void __pax_list_add_rcu(struct list_head *new,
81059+ struct list_head *prev, struct list_head *next);
81060+
81061 /**
81062 * list_add_rcu - add a new entry to rcu-protected list
81063 * @new: new entry to be added
81064@@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
81065 __list_add_rcu(new, head, head->next);
81066 }
81067
81068+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
81069+{
81070+ __pax_list_add_rcu(new, head, head->next);
81071+}
81072+
81073 /**
81074 * list_add_tail_rcu - add a new entry to rcu-protected list
81075 * @new: new entry to be added
81076@@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
81077 __list_add_rcu(new, head->prev, head);
81078 }
81079
81080+static inline void pax_list_add_tail_rcu(struct list_head *new,
81081+ struct list_head *head)
81082+{
81083+ __pax_list_add_rcu(new, head->prev, head);
81084+}
81085+
81086 /**
81087 * list_del_rcu - deletes entry from list without re-initialization
81088 * @entry: the element to delete from the list.
81089@@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
81090 entry->prev = LIST_POISON2;
81091 }
81092
81093+extern void pax_list_del_rcu(struct list_head *entry);
81094+
81095 /**
81096 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
81097 * @n: the element to delete from the hash list.
81098diff --git a/include/linux/reboot.h b/include/linux/reboot.h
81099index 9e7db9e..7d4fd72 100644
81100--- a/include/linux/reboot.h
81101+++ b/include/linux/reboot.h
81102@@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
81103 */
81104
81105 extern void migrate_to_reboot_cpu(void);
81106-extern void machine_restart(char *cmd);
81107-extern void machine_halt(void);
81108-extern void machine_power_off(void);
81109+extern void machine_restart(char *cmd) __noreturn;
81110+extern void machine_halt(void) __noreturn;
81111+extern void machine_power_off(void) __noreturn;
81112
81113 extern void machine_shutdown(void);
81114 struct pt_regs;
81115@@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
81116 */
81117
81118 extern void kernel_restart_prepare(char *cmd);
81119-extern void kernel_restart(char *cmd);
81120-extern void kernel_halt(void);
81121-extern void kernel_power_off(void);
81122+extern void kernel_restart(char *cmd) __noreturn;
81123+extern void kernel_halt(void) __noreturn;
81124+extern void kernel_power_off(void) __noreturn;
81125
81126 extern int C_A_D; /* for sysctl */
81127 void ctrl_alt_del(void);
81128@@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
81129 * Emergency restart, callable from an interrupt handler.
81130 */
81131
81132-extern void emergency_restart(void);
81133+extern void emergency_restart(void) __noreturn;
81134 #include <asm/emergency-restart.h>
81135
81136 #endif /* _LINUX_REBOOT_H */
81137diff --git a/include/linux/regset.h b/include/linux/regset.h
81138index 8e0c9fe..ac4d221 100644
81139--- a/include/linux/regset.h
81140+++ b/include/linux/regset.h
81141@@ -161,7 +161,8 @@ struct user_regset {
81142 unsigned int align;
81143 unsigned int bias;
81144 unsigned int core_note_type;
81145-};
81146+} __do_const;
81147+typedef struct user_regset __no_const user_regset_no_const;
81148
81149 /**
81150 * struct user_regset_view - available regsets
81151diff --git a/include/linux/relay.h b/include/linux/relay.h
81152index d7c8359..818daf5 100644
81153--- a/include/linux/relay.h
81154+++ b/include/linux/relay.h
81155@@ -157,7 +157,7 @@ struct rchan_callbacks
81156 * The callback should return 0 if successful, negative if not.
81157 */
81158 int (*remove_buf_file)(struct dentry *dentry);
81159-};
81160+} __no_const;
81161
81162 /*
81163 * CONFIG_RELAY kernel API, kernel/relay.c
81164diff --git a/include/linux/rio.h b/include/linux/rio.h
81165index b71d573..2f940bd 100644
81166--- a/include/linux/rio.h
81167+++ b/include/linux/rio.h
81168@@ -355,7 +355,7 @@ struct rio_ops {
81169 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
81170 u64 rstart, u32 size, u32 flags);
81171 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
81172-};
81173+} __no_const;
81174
81175 #define RIO_RESOURCE_MEM 0x00000100
81176 #define RIO_RESOURCE_DOORBELL 0x00000200
81177diff --git a/include/linux/rmap.h b/include/linux/rmap.h
81178index 6dacb93..6174423 100644
81179--- a/include/linux/rmap.h
81180+++ b/include/linux/rmap.h
81181@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
81182 void anon_vma_init(void); /* create anon_vma_cachep */
81183 int anon_vma_prepare(struct vm_area_struct *);
81184 void unlink_anon_vmas(struct vm_area_struct *);
81185-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
81186-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
81187+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
81188+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
81189
81190 static inline void anon_vma_merge(struct vm_area_struct *vma,
81191 struct vm_area_struct *next)
81192diff --git a/include/linux/sched.h b/include/linux/sched.h
81193index 53f97eb..1d90705 100644
81194--- a/include/linux/sched.h
81195+++ b/include/linux/sched.h
81196@@ -63,6 +63,7 @@ struct bio_list;
81197 struct fs_struct;
81198 struct perf_event_context;
81199 struct blk_plug;
81200+struct linux_binprm;
81201
81202 /*
81203 * List of flags we want to share for kernel threads,
81204@@ -304,7 +305,7 @@ extern char __sched_text_start[], __sched_text_end[];
81205 extern int in_sched_functions(unsigned long addr);
81206
81207 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
81208-extern signed long schedule_timeout(signed long timeout);
81209+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
81210 extern signed long schedule_timeout_interruptible(signed long timeout);
81211 extern signed long schedule_timeout_killable(signed long timeout);
81212 extern signed long schedule_timeout_uninterruptible(signed long timeout);
81213@@ -315,6 +316,19 @@ struct nsproxy;
81214 struct user_namespace;
81215
81216 #ifdef CONFIG_MMU
81217+
81218+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
81219+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
81220+#else
81221+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
81222+{
81223+ return 0;
81224+}
81225+#endif
81226+
81227+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
81228+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
81229+
81230 extern void arch_pick_mmap_layout(struct mm_struct *mm);
81231 extern unsigned long
81232 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
81233@@ -600,6 +614,17 @@ struct signal_struct {
81234 #ifdef CONFIG_TASKSTATS
81235 struct taskstats *stats;
81236 #endif
81237+
81238+#ifdef CONFIG_GRKERNSEC
81239+ u32 curr_ip;
81240+ u32 saved_ip;
81241+ u32 gr_saddr;
81242+ u32 gr_daddr;
81243+ u16 gr_sport;
81244+ u16 gr_dport;
81245+ u8 used_accept:1;
81246+#endif
81247+
81248 #ifdef CONFIG_AUDIT
81249 unsigned audit_tty;
81250 unsigned audit_tty_log_passwd;
81251@@ -626,7 +651,7 @@ struct signal_struct {
81252 struct mutex cred_guard_mutex; /* guard against foreign influences on
81253 * credential calculations
81254 * (notably. ptrace) */
81255-};
81256+} __randomize_layout;
81257
81258 /*
81259 * Bits in flags field of signal_struct.
81260@@ -680,6 +705,14 @@ struct user_struct {
81261 struct key *session_keyring; /* UID's default session keyring */
81262 #endif
81263
81264+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
81265+ unsigned char kernel_banned;
81266+#endif
81267+#ifdef CONFIG_GRKERNSEC_BRUTE
81268+ unsigned char suid_banned;
81269+ unsigned long suid_ban_expires;
81270+#endif
81271+
81272 /* Hash table maintenance information */
81273 struct hlist_node uidhash_node;
81274 kuid_t uid;
81275@@ -687,7 +720,7 @@ struct user_struct {
81276 #ifdef CONFIG_PERF_EVENTS
81277 atomic_long_t locked_vm;
81278 #endif
81279-};
81280+} __randomize_layout;
81281
81282 extern int uids_sysfs_init(void);
81283
81284@@ -1162,8 +1195,8 @@ struct task_struct {
81285 struct list_head thread_group;
81286
81287 struct completion *vfork_done; /* for vfork() */
81288- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
81289- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81290+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
81291+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81292
81293 cputime_t utime, stime, utimescaled, stimescaled;
81294 cputime_t gtime;
81295@@ -1188,11 +1221,6 @@ struct task_struct {
81296 struct task_cputime cputime_expires;
81297 struct list_head cpu_timers[3];
81298
81299-/* process credentials */
81300- const struct cred __rcu *real_cred; /* objective and real subjective task
81301- * credentials (COW) */
81302- const struct cred __rcu *cred; /* effective (overridable) subjective task
81303- * credentials (COW) */
81304 char comm[TASK_COMM_LEN]; /* executable name excluding path
81305 - access with [gs]et_task_comm (which lock
81306 it with task_lock())
81307@@ -1209,6 +1237,10 @@ struct task_struct {
81308 #endif
81309 /* CPU-specific state of this task */
81310 struct thread_struct thread;
81311+/* thread_info moved to task_struct */
81312+#ifdef CONFIG_X86
81313+ struct thread_info tinfo;
81314+#endif
81315 /* filesystem information */
81316 struct fs_struct *fs;
81317 /* open file information */
81318@@ -1282,6 +1314,10 @@ struct task_struct {
81319 gfp_t lockdep_reclaim_gfp;
81320 #endif
81321
81322+/* process credentials */
81323+ const struct cred __rcu *real_cred; /* objective and real subjective task
81324+ * credentials (COW) */
81325+
81326 /* journalling filesystem info */
81327 void *journal_info;
81328
81329@@ -1320,6 +1356,10 @@ struct task_struct {
81330 /* cg_list protected by css_set_lock and tsk->alloc_lock */
81331 struct list_head cg_list;
81332 #endif
81333+
81334+ const struct cred __rcu *cred; /* effective (overridable) subjective task
81335+ * credentials (COW) */
81336+
81337 #ifdef CONFIG_FUTEX
81338 struct robust_list_head __user *robust_list;
81339 #ifdef CONFIG_COMPAT
81340@@ -1454,7 +1494,78 @@ struct task_struct {
81341 unsigned int sequential_io;
81342 unsigned int sequential_io_avg;
81343 #endif
81344-};
81345+
81346+#ifdef CONFIG_GRKERNSEC
81347+ /* grsecurity */
81348+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81349+ u64 exec_id;
81350+#endif
81351+#ifdef CONFIG_GRKERNSEC_SETXID
81352+ const struct cred *delayed_cred;
81353+#endif
81354+ struct dentry *gr_chroot_dentry;
81355+ struct acl_subject_label *acl;
81356+ struct acl_subject_label *tmpacl;
81357+ struct acl_role_label *role;
81358+ struct file *exec_file;
81359+ unsigned long brute_expires;
81360+ u16 acl_role_id;
81361+ u8 inherited;
81362+ /* is this the task that authenticated to the special role */
81363+ u8 acl_sp_role;
81364+ u8 is_writable;
81365+ u8 brute;
81366+ u8 gr_is_chrooted;
81367+#endif
81368+
81369+} __randomize_layout;
81370+
81371+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
81372+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
81373+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
81374+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
81375+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
81376+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
81377+
81378+#ifdef CONFIG_PAX_SOFTMODE
81379+extern int pax_softmode;
81380+#endif
81381+
81382+extern int pax_check_flags(unsigned long *);
81383+#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
81384+
81385+/* if tsk != current then task_lock must be held on it */
81386+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
81387+static inline unsigned long pax_get_flags(struct task_struct *tsk)
81388+{
81389+ if (likely(tsk->mm))
81390+ return tsk->mm->pax_flags;
81391+ else
81392+ return 0UL;
81393+}
81394+
81395+/* if tsk != current then task_lock must be held on it */
81396+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
81397+{
81398+ if (likely(tsk->mm)) {
81399+ tsk->mm->pax_flags = flags;
81400+ return 0;
81401+ }
81402+ return -EINVAL;
81403+}
81404+#endif
81405+
81406+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
81407+extern void pax_set_initial_flags(struct linux_binprm *bprm);
81408+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
81409+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
81410+#endif
81411+
81412+struct path;
81413+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
81414+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
81415+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
81416+extern void pax_report_refcount_overflow(struct pt_regs *regs);
81417
81418 /* Future-safe accessor for struct task_struct's cpus_allowed. */
81419 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
81420@@ -1531,7 +1642,7 @@ struct pid_namespace;
81421 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
81422 struct pid_namespace *ns);
81423
81424-static inline pid_t task_pid_nr(struct task_struct *tsk)
81425+static inline pid_t task_pid_nr(const struct task_struct *tsk)
81426 {
81427 return tsk->pid;
81428 }
81429@@ -1981,7 +2092,9 @@ void yield(void);
81430 extern struct exec_domain default_exec_domain;
81431
81432 union thread_union {
81433+#ifndef CONFIG_X86
81434 struct thread_info thread_info;
81435+#endif
81436 unsigned long stack[THREAD_SIZE/sizeof(long)];
81437 };
81438
81439@@ -2014,6 +2127,7 @@ extern struct pid_namespace init_pid_ns;
81440 */
81441
81442 extern struct task_struct *find_task_by_vpid(pid_t nr);
81443+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
81444 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
81445 struct pid_namespace *ns);
81446
81447@@ -2178,7 +2292,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
81448 extern void exit_itimers(struct signal_struct *);
81449 extern void flush_itimer_signals(void);
81450
81451-extern void do_group_exit(int);
81452+extern __noreturn void do_group_exit(int);
81453
81454 extern int allow_signal(int);
81455 extern int disallow_signal(int);
81456@@ -2369,9 +2483,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
81457
81458 #endif
81459
81460-static inline int object_is_on_stack(void *obj)
81461+static inline int object_starts_on_stack(void *obj)
81462 {
81463- void *stack = task_stack_page(current);
81464+ const void *stack = task_stack_page(current);
81465
81466 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
81467 }
81468diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
81469index e3347c5..f682891 100644
81470--- a/include/linux/sched/sysctl.h
81471+++ b/include/linux/sched/sysctl.h
81472@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
81473 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
81474
81475 extern int sysctl_max_map_count;
81476+extern unsigned long sysctl_heap_stack_gap;
81477
81478 extern unsigned int sysctl_sched_latency;
81479 extern unsigned int sysctl_sched_min_granularity;
81480diff --git a/include/linux/security.h b/include/linux/security.h
81481index 5623a7f..7ae77be 100644
81482--- a/include/linux/security.h
81483+++ b/include/linux/security.h
81484@@ -27,6 +27,7 @@
81485 #include <linux/slab.h>
81486 #include <linux/err.h>
81487 #include <linux/string.h>
81488+#include <linux/grsecurity.h>
81489
81490 struct linux_binprm;
81491 struct cred;
81492@@ -116,8 +117,6 @@ struct seq_file;
81493
81494 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
81495
81496-void reset_security_ops(void);
81497-
81498 #ifdef CONFIG_MMU
81499 extern unsigned long mmap_min_addr;
81500 extern unsigned long dac_mmap_min_addr;
81501@@ -1718,7 +1717,7 @@ struct security_operations {
81502 struct audit_context *actx);
81503 void (*audit_rule_free) (void *lsmrule);
81504 #endif /* CONFIG_AUDIT */
81505-};
81506+} __randomize_layout;
81507
81508 /* prototypes */
81509 extern int security_init(void);
81510diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
81511index dc368b8..e895209 100644
81512--- a/include/linux/semaphore.h
81513+++ b/include/linux/semaphore.h
81514@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
81515 }
81516
81517 extern void down(struct semaphore *sem);
81518-extern int __must_check down_interruptible(struct semaphore *sem);
81519+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
81520 extern int __must_check down_killable(struct semaphore *sem);
81521 extern int __must_check down_trylock(struct semaphore *sem);
81522 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
81523diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
81524index 52e0097..09625ef 100644
81525--- a/include/linux/seq_file.h
81526+++ b/include/linux/seq_file.h
81527@@ -27,6 +27,9 @@ struct seq_file {
81528 struct mutex lock;
81529 const struct seq_operations *op;
81530 int poll_event;
81531+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81532+ u64 exec_id;
81533+#endif
81534 #ifdef CONFIG_USER_NS
81535 struct user_namespace *user_ns;
81536 #endif
81537@@ -39,6 +42,7 @@ struct seq_operations {
81538 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
81539 int (*show) (struct seq_file *m, void *v);
81540 };
81541+typedef struct seq_operations __no_const seq_operations_no_const;
81542
81543 #define SEQ_SKIP 1
81544
81545diff --git a/include/linux/shm.h b/include/linux/shm.h
81546index 429c199..4d42e38 100644
81547--- a/include/linux/shm.h
81548+++ b/include/linux/shm.h
81549@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
81550
81551 /* The task created the shm object. NULL if the task is dead. */
81552 struct task_struct *shm_creator;
81553+#ifdef CONFIG_GRKERNSEC
81554+ time_t shm_createtime;
81555+ pid_t shm_lapid;
81556+#endif
81557 };
81558
81559 /* shm_mode upper byte flags */
81560diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
81561index 37cb679..dbaebc0 100644
81562--- a/include/linux/skbuff.h
81563+++ b/include/linux/skbuff.h
81564@@ -643,7 +643,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
81565 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
81566 int node);
81567 struct sk_buff *build_skb(void *data, unsigned int frag_size);
81568-static inline struct sk_buff *alloc_skb(unsigned int size,
81569+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
81570 gfp_t priority)
81571 {
81572 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
81573@@ -750,7 +750,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
81574 */
81575 static inline int skb_queue_empty(const struct sk_buff_head *list)
81576 {
81577- return list->next == (struct sk_buff *)list;
81578+ return list->next == (const struct sk_buff *)list;
81579 }
81580
81581 /**
81582@@ -763,7 +763,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
81583 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
81584 const struct sk_buff *skb)
81585 {
81586- return skb->next == (struct sk_buff *)list;
81587+ return skb->next == (const struct sk_buff *)list;
81588 }
81589
81590 /**
81591@@ -776,7 +776,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
81592 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
81593 const struct sk_buff *skb)
81594 {
81595- return skb->prev == (struct sk_buff *)list;
81596+ return skb->prev == (const struct sk_buff *)list;
81597 }
81598
81599 /**
81600@@ -1686,7 +1686,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
81601 return skb->inner_transport_header - skb->inner_network_header;
81602 }
81603
81604-static inline int skb_network_offset(const struct sk_buff *skb)
81605+static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
81606 {
81607 return skb_network_header(skb) - skb->data;
81608 }
81609@@ -1746,7 +1746,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
81610 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
81611 */
81612 #ifndef NET_SKB_PAD
81613-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
81614+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
81615 #endif
81616
81617 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
81618@@ -2345,7 +2345,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
81619 int *err);
81620 unsigned int datagram_poll(struct file *file, struct socket *sock,
81621 struct poll_table_struct *wait);
81622-int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
81623+int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
81624 struct iovec *to, int size);
81625 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
81626 struct iovec *iov);
81627@@ -2618,6 +2618,9 @@ static inline void nf_reset(struct sk_buff *skb)
81628 nf_bridge_put(skb->nf_bridge);
81629 skb->nf_bridge = NULL;
81630 #endif
81631+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
81632+ skb->nf_trace = 0;
81633+#endif
81634 }
81635
81636 static inline void nf_reset_trace(struct sk_buff *skb)
81637diff --git a/include/linux/slab.h b/include/linux/slab.h
81638index 1e2f4fe..df49ca6 100644
81639--- a/include/linux/slab.h
81640+++ b/include/linux/slab.h
81641@@ -14,15 +14,29 @@
81642 #include <linux/gfp.h>
81643 #include <linux/types.h>
81644 #include <linux/workqueue.h>
81645-
81646+#include <linux/err.h>
81647
81648 /*
81649 * Flags to pass to kmem_cache_create().
81650 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
81651 */
81652 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
81653+
81654+#ifdef CONFIG_PAX_USERCOPY_SLABS
81655+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
81656+#else
81657+#define SLAB_USERCOPY 0x00000000UL
81658+#endif
81659+
81660 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
81661 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
81662+
81663+#ifdef CONFIG_PAX_MEMORY_SANITIZE
81664+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
81665+#else
81666+#define SLAB_NO_SANITIZE 0x00000000UL
81667+#endif
81668+
81669 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
81670 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
81671 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
81672@@ -98,10 +112,13 @@
81673 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
81674 * Both make kfree a no-op.
81675 */
81676-#define ZERO_SIZE_PTR ((void *)16)
81677+#define ZERO_SIZE_PTR \
81678+({ \
81679+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
81680+ (void *)(-MAX_ERRNO-1L); \
81681+})
81682
81683-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
81684- (unsigned long)ZERO_SIZE_PTR)
81685+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
81686
81687 #include <linux/kmemleak.h>
81688
81689@@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
81690 void kfree(const void *);
81691 void kzfree(const void *);
81692 size_t ksize(const void *);
81693+const char *check_heap_object(const void *ptr, unsigned long n);
81694+bool is_usercopy_object(const void *ptr);
81695
81696 /*
81697 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
81698@@ -174,7 +193,7 @@ struct kmem_cache {
81699 unsigned int align; /* Alignment as calculated */
81700 unsigned long flags; /* Active flags on the slab */
81701 const char *name; /* Slab name for sysfs */
81702- int refcount; /* Use counter */
81703+ atomic_t refcount; /* Use counter */
81704 void (*ctor)(void *); /* Called on object slot creation */
81705 struct list_head list; /* List of all slab caches on the system */
81706 };
81707@@ -248,6 +267,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
81708 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
81709 #endif
81710
81711+#ifdef CONFIG_PAX_USERCOPY_SLABS
81712+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
81713+#endif
81714+
81715 /*
81716 * Figure out which kmalloc slab an allocation of a certain size
81717 * belongs to.
81718@@ -256,7 +279,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
81719 * 2 = 120 .. 192 bytes
81720 * n = 2^(n-1) .. 2^n -1
81721 */
81722-static __always_inline int kmalloc_index(size_t size)
81723+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
81724 {
81725 if (!size)
81726 return 0;
81727@@ -299,11 +322,11 @@ static __always_inline int kmalloc_index(size_t size)
81728 }
81729 #endif /* !CONFIG_SLOB */
81730
81731-void *__kmalloc(size_t size, gfp_t flags);
81732+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
81733 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
81734
81735 #ifdef CONFIG_NUMA
81736-void *__kmalloc_node(size_t size, gfp_t flags, int node);
81737+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
81738 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
81739 #else
81740 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
81741diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
81742index 09bfffb..4fc80fb 100644
81743--- a/include/linux/slab_def.h
81744+++ b/include/linux/slab_def.h
81745@@ -36,7 +36,7 @@ struct kmem_cache {
81746 /* 4) cache creation/removal */
81747 const char *name;
81748 struct list_head list;
81749- int refcount;
81750+ atomic_t refcount;
81751 int object_size;
81752 int align;
81753
81754@@ -52,10 +52,14 @@ struct kmem_cache {
81755 unsigned long node_allocs;
81756 unsigned long node_frees;
81757 unsigned long node_overflow;
81758- atomic_t allochit;
81759- atomic_t allocmiss;
81760- atomic_t freehit;
81761- atomic_t freemiss;
81762+ atomic_unchecked_t allochit;
81763+ atomic_unchecked_t allocmiss;
81764+ atomic_unchecked_t freehit;
81765+ atomic_unchecked_t freemiss;
81766+#ifdef CONFIG_PAX_MEMORY_SANITIZE
81767+ atomic_unchecked_t sanitized;
81768+ atomic_unchecked_t not_sanitized;
81769+#endif
81770
81771 /*
81772 * If debugging is enabled, then the allocator can add additional
81773diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
81774index f56bfa9..8378a26 100644
81775--- a/include/linux/slub_def.h
81776+++ b/include/linux/slub_def.h
81777@@ -74,7 +74,7 @@ struct kmem_cache {
81778 struct kmem_cache_order_objects max;
81779 struct kmem_cache_order_objects min;
81780 gfp_t allocflags; /* gfp flags to use on each alloc */
81781- int refcount; /* Refcount for slab cache destroy */
81782+ atomic_t refcount; /* Refcount for slab cache destroy */
81783 void (*ctor)(void *);
81784 int inuse; /* Offset to metadata */
81785 int align; /* Alignment */
81786diff --git a/include/linux/smp.h b/include/linux/smp.h
81787index 5da22ee..71d8a28 100644
81788--- a/include/linux/smp.h
81789+++ b/include/linux/smp.h
81790@@ -176,7 +176,9 @@ static inline void kick_all_cpus_sync(void) { }
81791 #endif
81792
81793 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
81794+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
81795 #define put_cpu() preempt_enable()
81796+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
81797
81798 /*
81799 * Callback to arch code if there's nosmp or maxcpus=0 on the
81800diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
81801index 54f91d3..be2c379 100644
81802--- a/include/linux/sock_diag.h
81803+++ b/include/linux/sock_diag.h
81804@@ -11,7 +11,7 @@ struct sock;
81805 struct sock_diag_handler {
81806 __u8 family;
81807 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
81808-};
81809+} __do_const;
81810
81811 int sock_diag_register(const struct sock_diag_handler *h);
81812 void sock_diag_unregister(const struct sock_diag_handler *h);
81813diff --git a/include/linux/sonet.h b/include/linux/sonet.h
81814index 680f9a3..f13aeb0 100644
81815--- a/include/linux/sonet.h
81816+++ b/include/linux/sonet.h
81817@@ -7,7 +7,7 @@
81818 #include <uapi/linux/sonet.h>
81819
81820 struct k_sonet_stats {
81821-#define __HANDLE_ITEM(i) atomic_t i
81822+#define __HANDLE_ITEM(i) atomic_unchecked_t i
81823 __SONET_ITEMS
81824 #undef __HANDLE_ITEM
81825 };
81826diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
81827index 07d8e53..dc934c9 100644
81828--- a/include/linux/sunrpc/addr.h
81829+++ b/include/linux/sunrpc/addr.h
81830@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
81831 {
81832 switch (sap->sa_family) {
81833 case AF_INET:
81834- return ntohs(((struct sockaddr_in *)sap)->sin_port);
81835+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
81836 case AF_INET6:
81837- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
81838+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
81839 }
81840 return 0;
81841 }
81842@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
81843 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
81844 const struct sockaddr *src)
81845 {
81846- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
81847+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
81848 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
81849
81850 dsin->sin_family = ssin->sin_family;
81851@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
81852 if (sa->sa_family != AF_INET6)
81853 return 0;
81854
81855- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
81856+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
81857 }
81858
81859 #endif /* _LINUX_SUNRPC_ADDR_H */
81860diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
81861index 8af2804..c7414ef 100644
81862--- a/include/linux/sunrpc/clnt.h
81863+++ b/include/linux/sunrpc/clnt.h
81864@@ -97,7 +97,7 @@ struct rpc_procinfo {
81865 unsigned int p_timer; /* Which RTT timer to use */
81866 u32 p_statidx; /* Which procedure to account */
81867 const char * p_name; /* name of procedure */
81868-};
81869+} __do_const;
81870
81871 #ifdef __KERNEL__
81872
81873diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
81874index 6eecfc2..7ada79d 100644
81875--- a/include/linux/sunrpc/svc.h
81876+++ b/include/linux/sunrpc/svc.h
81877@@ -410,7 +410,7 @@ struct svc_procedure {
81878 unsigned int pc_count; /* call count */
81879 unsigned int pc_cachetype; /* cache info (NFS) */
81880 unsigned int pc_xdrressize; /* maximum size of XDR reply */
81881-};
81882+} __do_const;
81883
81884 /*
81885 * Function prototypes.
81886diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
81887index 0b8e3e6..33e0a01 100644
81888--- a/include/linux/sunrpc/svc_rdma.h
81889+++ b/include/linux/sunrpc/svc_rdma.h
81890@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
81891 extern unsigned int svcrdma_max_requests;
81892 extern unsigned int svcrdma_max_req_size;
81893
81894-extern atomic_t rdma_stat_recv;
81895-extern atomic_t rdma_stat_read;
81896-extern atomic_t rdma_stat_write;
81897-extern atomic_t rdma_stat_sq_starve;
81898-extern atomic_t rdma_stat_rq_starve;
81899-extern atomic_t rdma_stat_rq_poll;
81900-extern atomic_t rdma_stat_rq_prod;
81901-extern atomic_t rdma_stat_sq_poll;
81902-extern atomic_t rdma_stat_sq_prod;
81903+extern atomic_unchecked_t rdma_stat_recv;
81904+extern atomic_unchecked_t rdma_stat_read;
81905+extern atomic_unchecked_t rdma_stat_write;
81906+extern atomic_unchecked_t rdma_stat_sq_starve;
81907+extern atomic_unchecked_t rdma_stat_rq_starve;
81908+extern atomic_unchecked_t rdma_stat_rq_poll;
81909+extern atomic_unchecked_t rdma_stat_rq_prod;
81910+extern atomic_unchecked_t rdma_stat_sq_poll;
81911+extern atomic_unchecked_t rdma_stat_sq_prod;
81912
81913 #define RPCRDMA_VERSION 1
81914
81915diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
81916index 8d71d65..f79586e 100644
81917--- a/include/linux/sunrpc/svcauth.h
81918+++ b/include/linux/sunrpc/svcauth.h
81919@@ -120,7 +120,7 @@ struct auth_ops {
81920 int (*release)(struct svc_rqst *rq);
81921 void (*domain_release)(struct auth_domain *);
81922 int (*set_client)(struct svc_rqst *rq);
81923-};
81924+} __do_const;
81925
81926 #define SVC_GARBAGE 1
81927 #define SVC_SYSERR 2
81928diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
81929index a5ffd32..0935dea 100644
81930--- a/include/linux/swiotlb.h
81931+++ b/include/linux/swiotlb.h
81932@@ -60,7 +60,8 @@ extern void
81933
81934 extern void
81935 swiotlb_free_coherent(struct device *hwdev, size_t size,
81936- void *vaddr, dma_addr_t dma_handle);
81937+ void *vaddr, dma_addr_t dma_handle,
81938+ struct dma_attrs *attrs);
81939
81940 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
81941 unsigned long offset, size_t size,
81942diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
81943index 94273bb..c2e05fc 100644
81944--- a/include/linux/syscalls.h
81945+++ b/include/linux/syscalls.h
81946@@ -97,8 +97,14 @@ struct sigaltstack;
81947 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
81948
81949 #define __SC_DECL(t, a) t a
81950+#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))
81951 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
81952-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
81953+#define __SC_LONG(t, a) __typeof( \
81954+ __builtin_choose_expr( \
81955+ sizeof(t) > sizeof(int), \
81956+ (t) 0, \
81957+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
81958+ )) a
81959 #define __SC_CAST(t, a) (t) a
81960 #define __SC_ARGS(t, a) a
81961 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
81962@@ -363,11 +369,11 @@ asmlinkage long sys_sync(void);
81963 asmlinkage long sys_fsync(unsigned int fd);
81964 asmlinkage long sys_fdatasync(unsigned int fd);
81965 asmlinkage long sys_bdflush(int func, long data);
81966-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
81967- char __user *type, unsigned long flags,
81968+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
81969+ const char __user *type, unsigned long flags,
81970 void __user *data);
81971-asmlinkage long sys_umount(char __user *name, int flags);
81972-asmlinkage long sys_oldumount(char __user *name);
81973+asmlinkage long sys_umount(const char __user *name, int flags);
81974+asmlinkage long sys_oldumount(const char __user *name);
81975 asmlinkage long sys_truncate(const char __user *path, long length);
81976 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
81977 asmlinkage long sys_stat(const char __user *filename,
81978@@ -579,7 +585,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
81979 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
81980 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
81981 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
81982- struct sockaddr __user *, int);
81983+ struct sockaddr __user *, int) __intentional_overflow(0);
81984 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
81985 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
81986 unsigned int vlen, unsigned flags);
81987diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
81988index 27b3b0b..e093dd9 100644
81989--- a/include/linux/syscore_ops.h
81990+++ b/include/linux/syscore_ops.h
81991@@ -16,7 +16,7 @@ struct syscore_ops {
81992 int (*suspend)(void);
81993 void (*resume)(void);
81994 void (*shutdown)(void);
81995-};
81996+} __do_const;
81997
81998 extern void register_syscore_ops(struct syscore_ops *ops);
81999 extern void unregister_syscore_ops(struct syscore_ops *ops);
82000diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
82001index 14a8ff2..fa95f3a 100644
82002--- a/include/linux/sysctl.h
82003+++ b/include/linux/sysctl.h
82004@@ -34,13 +34,13 @@ struct ctl_table_root;
82005 struct ctl_table_header;
82006 struct ctl_dir;
82007
82008-typedef struct ctl_table ctl_table;
82009-
82010 typedef int proc_handler (struct ctl_table *ctl, int write,
82011 void __user *buffer, size_t *lenp, loff_t *ppos);
82012
82013 extern int proc_dostring(struct ctl_table *, int,
82014 void __user *, size_t *, loff_t *);
82015+extern int proc_dostring_modpriv(struct ctl_table *, int,
82016+ void __user *, size_t *, loff_t *);
82017 extern int proc_dointvec(struct ctl_table *, int,
82018 void __user *, size_t *, loff_t *);
82019 extern int proc_dointvec_minmax(struct ctl_table *, int,
82020@@ -115,7 +115,9 @@ struct ctl_table
82021 struct ctl_table_poll *poll;
82022 void *extra1;
82023 void *extra2;
82024-};
82025+} __do_const __randomize_layout;
82026+typedef struct ctl_table __no_const ctl_table_no_const;
82027+typedef struct ctl_table ctl_table;
82028
82029 struct ctl_node {
82030 struct rb_node node;
82031diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
82032index 6695040..3d4192d 100644
82033--- a/include/linux/sysfs.h
82034+++ b/include/linux/sysfs.h
82035@@ -33,7 +33,8 @@ struct attribute {
82036 struct lock_class_key *key;
82037 struct lock_class_key skey;
82038 #endif
82039-};
82040+} __do_const;
82041+typedef struct attribute __no_const attribute_no_const;
82042
82043 /**
82044 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
82045@@ -62,7 +63,8 @@ struct attribute_group {
82046 struct attribute *, int);
82047 struct attribute **attrs;
82048 struct bin_attribute **bin_attrs;
82049-};
82050+} __do_const;
82051+typedef struct attribute_group __no_const attribute_group_no_const;
82052
82053 /**
82054 * Use these macros to make defining attributes easier. See include/linux/device.h
82055@@ -126,7 +128,8 @@ struct bin_attribute {
82056 char *, loff_t, size_t);
82057 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
82058 struct vm_area_struct *vma);
82059-};
82060+} __do_const;
82061+typedef struct bin_attribute __no_const bin_attribute_no_const;
82062
82063 /**
82064 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
82065diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
82066index 387fa7d..3fcde6b 100644
82067--- a/include/linux/sysrq.h
82068+++ b/include/linux/sysrq.h
82069@@ -16,6 +16,7 @@
82070
82071 #include <linux/errno.h>
82072 #include <linux/types.h>
82073+#include <linux/compiler.h>
82074
82075 /* Possible values of bitmask for enabling sysrq functions */
82076 /* 0x0001 is reserved for enable everything */
82077@@ -33,7 +34,7 @@ struct sysrq_key_op {
82078 char *help_msg;
82079 char *action_msg;
82080 int enable_mask;
82081-};
82082+} __do_const;
82083
82084 #ifdef CONFIG_MAGIC_SYSRQ
82085
82086diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
82087index fddbe20..0312de8 100644
82088--- a/include/linux/thread_info.h
82089+++ b/include/linux/thread_info.h
82090@@ -161,6 +161,15 @@ static inline bool test_and_clear_restore_sigmask(void)
82091 #error "no set_restore_sigmask() provided and default one won't work"
82092 #endif
82093
82094+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
82095+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
82096+{
82097+#ifndef CONFIG_PAX_USERCOPY_DEBUG
82098+ if (!__builtin_constant_p(n))
82099+#endif
82100+ __check_object_size(ptr, n, to_user);
82101+}
82102+
82103 #endif /* __KERNEL__ */
82104
82105 #endif /* _LINUX_THREAD_INFO_H */
82106diff --git a/include/linux/tty.h b/include/linux/tty.h
82107index 97d660e..6356755 100644
82108--- a/include/linux/tty.h
82109+++ b/include/linux/tty.h
82110@@ -196,7 +196,7 @@ struct tty_port {
82111 const struct tty_port_operations *ops; /* Port operations */
82112 spinlock_t lock; /* Lock protecting tty field */
82113 int blocked_open; /* Waiting to open */
82114- int count; /* Usage count */
82115+ atomic_t count; /* Usage count */
82116 wait_queue_head_t open_wait; /* Open waiters */
82117 wait_queue_head_t close_wait; /* Close waiters */
82118 wait_queue_head_t delta_msr_wait; /* Modem status change */
82119@@ -278,7 +278,7 @@ struct tty_struct {
82120 /* If the tty has a pending do_SAK, queue it here - akpm */
82121 struct work_struct SAK_work;
82122 struct tty_port *port;
82123-};
82124+} __randomize_layout;
82125
82126 /* Each of a tty's open files has private_data pointing to tty_file_private */
82127 struct tty_file_private {
82128@@ -545,7 +545,7 @@ extern int tty_port_open(struct tty_port *port,
82129 struct tty_struct *tty, struct file *filp);
82130 static inline int tty_port_users(struct tty_port *port)
82131 {
82132- return port->count + port->blocked_open;
82133+ return atomic_read(&port->count) + port->blocked_open;
82134 }
82135
82136 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
82137diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
82138index 756a609..89db85e 100644
82139--- a/include/linux/tty_driver.h
82140+++ b/include/linux/tty_driver.h
82141@@ -285,7 +285,7 @@ struct tty_operations {
82142 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
82143 #endif
82144 const struct file_operations *proc_fops;
82145-};
82146+} __do_const __randomize_layout;
82147
82148 struct tty_driver {
82149 int magic; /* magic number for this structure */
82150@@ -319,7 +319,7 @@ struct tty_driver {
82151
82152 const struct tty_operations *ops;
82153 struct list_head tty_drivers;
82154-};
82155+} __randomize_layout;
82156
82157 extern struct list_head tty_drivers;
82158
82159diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
82160index f15c898..207b7d1 100644
82161--- a/include/linux/tty_ldisc.h
82162+++ b/include/linux/tty_ldisc.h
82163@@ -211,7 +211,7 @@ struct tty_ldisc_ops {
82164
82165 struct module *owner;
82166
82167- int refcount;
82168+ atomic_t refcount;
82169 };
82170
82171 struct tty_ldisc {
82172diff --git a/include/linux/types.h b/include/linux/types.h
82173index 4d118ba..c3ee9bf 100644
82174--- a/include/linux/types.h
82175+++ b/include/linux/types.h
82176@@ -176,10 +176,26 @@ typedef struct {
82177 int counter;
82178 } atomic_t;
82179
82180+#ifdef CONFIG_PAX_REFCOUNT
82181+typedef struct {
82182+ int counter;
82183+} atomic_unchecked_t;
82184+#else
82185+typedef atomic_t atomic_unchecked_t;
82186+#endif
82187+
82188 #ifdef CONFIG_64BIT
82189 typedef struct {
82190 long counter;
82191 } atomic64_t;
82192+
82193+#ifdef CONFIG_PAX_REFCOUNT
82194+typedef struct {
82195+ long counter;
82196+} atomic64_unchecked_t;
82197+#else
82198+typedef atomic64_t atomic64_unchecked_t;
82199+#endif
82200 #endif
82201
82202 struct list_head {
82203diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
82204index 9d8cf05..0ed74dd 100644
82205--- a/include/linux/uaccess.h
82206+++ b/include/linux/uaccess.h
82207@@ -72,11 +72,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
82208 long ret; \
82209 mm_segment_t old_fs = get_fs(); \
82210 \
82211- set_fs(KERNEL_DS); \
82212 pagefault_disable(); \
82213- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
82214- pagefault_enable(); \
82215+ set_fs(KERNEL_DS); \
82216+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
82217 set_fs(old_fs); \
82218+ pagefault_enable(); \
82219 ret; \
82220 })
82221
82222diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
82223index 8e522cbc..aa8572d 100644
82224--- a/include/linux/uidgid.h
82225+++ b/include/linux/uidgid.h
82226@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
82227
82228 #endif /* CONFIG_USER_NS */
82229
82230+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
82231+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
82232+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
82233+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
82234+
82235 #endif /* _LINUX_UIDGID_H */
82236diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
82237index 99c1b4d..562e6f3 100644
82238--- a/include/linux/unaligned/access_ok.h
82239+++ b/include/linux/unaligned/access_ok.h
82240@@ -4,34 +4,34 @@
82241 #include <linux/kernel.h>
82242 #include <asm/byteorder.h>
82243
82244-static inline u16 get_unaligned_le16(const void *p)
82245+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
82246 {
82247- return le16_to_cpup((__le16 *)p);
82248+ return le16_to_cpup((const __le16 *)p);
82249 }
82250
82251-static inline u32 get_unaligned_le32(const void *p)
82252+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
82253 {
82254- return le32_to_cpup((__le32 *)p);
82255+ return le32_to_cpup((const __le32 *)p);
82256 }
82257
82258-static inline u64 get_unaligned_le64(const void *p)
82259+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
82260 {
82261- return le64_to_cpup((__le64 *)p);
82262+ return le64_to_cpup((const __le64 *)p);
82263 }
82264
82265-static inline u16 get_unaligned_be16(const void *p)
82266+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
82267 {
82268- return be16_to_cpup((__be16 *)p);
82269+ return be16_to_cpup((const __be16 *)p);
82270 }
82271
82272-static inline u32 get_unaligned_be32(const void *p)
82273+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
82274 {
82275- return be32_to_cpup((__be32 *)p);
82276+ return be32_to_cpup((const __be32 *)p);
82277 }
82278
82279-static inline u64 get_unaligned_be64(const void *p)
82280+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
82281 {
82282- return be64_to_cpup((__be64 *)p);
82283+ return be64_to_cpup((const __be64 *)p);
82284 }
82285
82286 static inline void put_unaligned_le16(u16 val, void *p)
82287diff --git a/include/linux/usb.h b/include/linux/usb.h
82288index 7454865..29f4bfa 100644
82289--- a/include/linux/usb.h
82290+++ b/include/linux/usb.h
82291@@ -563,7 +563,7 @@ struct usb_device {
82292 int maxchild;
82293
82294 u32 quirks;
82295- atomic_t urbnum;
82296+ atomic_unchecked_t urbnum;
82297
82298 unsigned long active_duration;
82299
82300@@ -1641,7 +1641,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
82301
82302 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
82303 __u8 request, __u8 requesttype, __u16 value, __u16 index,
82304- void *data, __u16 size, int timeout);
82305+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
82306 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
82307 void *data, int len, int *actual_length, int timeout);
82308 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
82309diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
82310index e452ba6..78f8e80 100644
82311--- a/include/linux/usb/renesas_usbhs.h
82312+++ b/include/linux/usb/renesas_usbhs.h
82313@@ -39,7 +39,7 @@ enum {
82314 */
82315 struct renesas_usbhs_driver_callback {
82316 int (*notify_hotplug)(struct platform_device *pdev);
82317-};
82318+} __no_const;
82319
82320 /*
82321 * callback functions for platform
82322diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
82323index 4836ba3..603f6ee 100644
82324--- a/include/linux/user_namespace.h
82325+++ b/include/linux/user_namespace.h
82326@@ -33,7 +33,7 @@ struct user_namespace {
82327 struct key *persistent_keyring_register;
82328 struct rw_semaphore persistent_keyring_register_sem;
82329 #endif
82330-};
82331+} __randomize_layout;
82332
82333 extern struct user_namespace init_user_ns;
82334
82335diff --git a/include/linux/utsname.h b/include/linux/utsname.h
82336index 239e277..22a5cf5 100644
82337--- a/include/linux/utsname.h
82338+++ b/include/linux/utsname.h
82339@@ -24,7 +24,7 @@ struct uts_namespace {
82340 struct new_utsname name;
82341 struct user_namespace *user_ns;
82342 unsigned int proc_inum;
82343-};
82344+} __randomize_layout;
82345 extern struct uts_namespace init_uts_ns;
82346
82347 #ifdef CONFIG_UTS_NS
82348diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
82349index 6f8fbcf..4efc177 100644
82350--- a/include/linux/vermagic.h
82351+++ b/include/linux/vermagic.h
82352@@ -25,9 +25,42 @@
82353 #define MODULE_ARCH_VERMAGIC ""
82354 #endif
82355
82356+#ifdef CONFIG_PAX_REFCOUNT
82357+#define MODULE_PAX_REFCOUNT "REFCOUNT "
82358+#else
82359+#define MODULE_PAX_REFCOUNT ""
82360+#endif
82361+
82362+#ifdef CONSTIFY_PLUGIN
82363+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
82364+#else
82365+#define MODULE_CONSTIFY_PLUGIN ""
82366+#endif
82367+
82368+#ifdef STACKLEAK_PLUGIN
82369+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
82370+#else
82371+#define MODULE_STACKLEAK_PLUGIN ""
82372+#endif
82373+
82374+#ifdef RANDSTRUCT_PLUGIN
82375+#include <generated/randomize_layout_hash.h>
82376+#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
82377+#else
82378+#define MODULE_RANDSTRUCT_PLUGIN
82379+#endif
82380+
82381+#ifdef CONFIG_GRKERNSEC
82382+#define MODULE_GRSEC "GRSEC "
82383+#else
82384+#define MODULE_GRSEC ""
82385+#endif
82386+
82387 #define VERMAGIC_STRING \
82388 UTS_RELEASE " " \
82389 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
82390 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
82391- MODULE_ARCH_VERMAGIC
82392+ MODULE_ARCH_VERMAGIC \
82393+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
82394+ MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
82395
82396diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
82397index 502073a..a7de024 100644
82398--- a/include/linux/vga_switcheroo.h
82399+++ b/include/linux/vga_switcheroo.h
82400@@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
82401
82402 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
82403
82404-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
82405-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
82406+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
82407+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
82408 #else
82409
82410 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
82411@@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
82412
82413 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
82414
82415-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
82416-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
82417+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
82418+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
82419
82420 #endif
82421 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
82422diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
82423index 4b8a891..cb8df6e 100644
82424--- a/include/linux/vmalloc.h
82425+++ b/include/linux/vmalloc.h
82426@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
82427 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
82428 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
82429 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
82430+
82431+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
82432+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
82433+#endif
82434+
82435 /* bits [20..32] reserved for arch specific ioremap internals */
82436
82437 /*
82438@@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
82439
82440 /* for /dev/kmem */
82441 extern long vread(char *buf, char *addr, unsigned long count);
82442-extern long vwrite(char *buf, char *addr, unsigned long count);
82443+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
82444
82445 /*
82446 * Internals. Dont't use..
82447diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
82448index a67b384..f52a537 100644
82449--- a/include/linux/vmstat.h
82450+++ b/include/linux/vmstat.h
82451@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
82452 /*
82453 * Zone based page accounting with per cpu differentials.
82454 */
82455-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
82456+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
82457
82458 static inline void zone_page_state_add(long x, struct zone *zone,
82459 enum zone_stat_item item)
82460 {
82461- atomic_long_add(x, &zone->vm_stat[item]);
82462- atomic_long_add(x, &vm_stat[item]);
82463+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
82464+ atomic_long_add_unchecked(x, &vm_stat[item]);
82465 }
82466
82467-static inline unsigned long global_page_state(enum zone_stat_item item)
82468+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
82469 {
82470- long x = atomic_long_read(&vm_stat[item]);
82471+ long x = atomic_long_read_unchecked(&vm_stat[item]);
82472 #ifdef CONFIG_SMP
82473 if (x < 0)
82474 x = 0;
82475@@ -109,10 +109,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
82476 return x;
82477 }
82478
82479-static inline unsigned long zone_page_state(struct zone *zone,
82480+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
82481 enum zone_stat_item item)
82482 {
82483- long x = atomic_long_read(&zone->vm_stat[item]);
82484+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
82485 #ifdef CONFIG_SMP
82486 if (x < 0)
82487 x = 0;
82488@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
82489 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
82490 enum zone_stat_item item)
82491 {
82492- long x = atomic_long_read(&zone->vm_stat[item]);
82493+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
82494
82495 #ifdef CONFIG_SMP
82496 int cpu;
82497@@ -218,8 +218,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
82498
82499 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
82500 {
82501- atomic_long_inc(&zone->vm_stat[item]);
82502- atomic_long_inc(&vm_stat[item]);
82503+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
82504+ atomic_long_inc_unchecked(&vm_stat[item]);
82505 }
82506
82507 static inline void __inc_zone_page_state(struct page *page,
82508@@ -230,8 +230,8 @@ static inline void __inc_zone_page_state(struct page *page,
82509
82510 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
82511 {
82512- atomic_long_dec(&zone->vm_stat[item]);
82513- atomic_long_dec(&vm_stat[item]);
82514+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
82515+ atomic_long_dec_unchecked(&vm_stat[item]);
82516 }
82517
82518 static inline void __dec_zone_page_state(struct page *page,
82519diff --git a/include/linux/xattr.h b/include/linux/xattr.h
82520index 91b0a68..0e9adf6 100644
82521--- a/include/linux/xattr.h
82522+++ b/include/linux/xattr.h
82523@@ -28,7 +28,7 @@ struct xattr_handler {
82524 size_t size, int handler_flags);
82525 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
82526 size_t size, int flags, int handler_flags);
82527-};
82528+} __do_const;
82529
82530 struct xattr {
82531 const char *name;
82532@@ -37,6 +37,9 @@ struct xattr {
82533 };
82534
82535 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
82536+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82537+ssize_t pax_getxattr(struct dentry *, void *, size_t);
82538+#endif
82539 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
82540 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
82541 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
82542diff --git a/include/linux/zlib.h b/include/linux/zlib.h
82543index 9c5a6b4..09c9438 100644
82544--- a/include/linux/zlib.h
82545+++ b/include/linux/zlib.h
82546@@ -31,6 +31,7 @@
82547 #define _ZLIB_H
82548
82549 #include <linux/zconf.h>
82550+#include <linux/compiler.h>
82551
82552 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
82553 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
82554@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
82555
82556 /* basic functions */
82557
82558-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
82559+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
82560 /*
82561 Returns the number of bytes that needs to be allocated for a per-
82562 stream workspace with the specified parameters. A pointer to this
82563diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
82564index c768c9f..bdcaa5a 100644
82565--- a/include/media/v4l2-dev.h
82566+++ b/include/media/v4l2-dev.h
82567@@ -76,7 +76,7 @@ struct v4l2_file_operations {
82568 int (*mmap) (struct file *, struct vm_area_struct *);
82569 int (*open) (struct file *);
82570 int (*release) (struct file *);
82571-};
82572+} __do_const;
82573
82574 /*
82575 * Newer version of video_device, handled by videodev2.c
82576diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
82577index c9b1593..a572459 100644
82578--- a/include/media/v4l2-device.h
82579+++ b/include/media/v4l2-device.h
82580@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
82581 this function returns 0. If the name ends with a digit (e.g. cx18),
82582 then the name will be set to cx18-0 since cx180 looks really odd. */
82583 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
82584- atomic_t *instance);
82585+ atomic_unchecked_t *instance);
82586
82587 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
82588 Since the parent disappears this ensures that v4l2_dev doesn't have an
82589diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
82590index 9a36d92..0aafe2a 100644
82591--- a/include/net/9p/transport.h
82592+++ b/include/net/9p/transport.h
82593@@ -60,7 +60,7 @@ struct p9_trans_module {
82594 int (*cancel) (struct p9_client *, struct p9_req_t *req);
82595 int (*zc_request)(struct p9_client *, struct p9_req_t *,
82596 char *, char *, int , int, int, int);
82597-};
82598+} __do_const;
82599
82600 void v9fs_register_trans(struct p9_trans_module *m);
82601 void v9fs_unregister_trans(struct p9_trans_module *m);
82602diff --git a/include/net/af_unix.h b/include/net/af_unix.h
82603index a175ba4..196eb82 100644
82604--- a/include/net/af_unix.h
82605+++ b/include/net/af_unix.h
82606@@ -36,7 +36,7 @@ struct unix_skb_parms {
82607 u32 secid; /* Security ID */
82608 #endif
82609 u32 consumed;
82610-};
82611+} __randomize_layout;
82612
82613 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
82614 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
82615diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
82616index c853b16d..37fccb7 100644
82617--- a/include/net/bluetooth/l2cap.h
82618+++ b/include/net/bluetooth/l2cap.h
82619@@ -557,7 +557,7 @@ struct l2cap_ops {
82620 long (*get_sndtimeo) (struct l2cap_chan *chan);
82621 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
82622 unsigned long len, int nb);
82623-};
82624+} __do_const;
82625
82626 struct l2cap_conn {
82627 struct hci_conn *hcon;
82628diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
82629index f2ae33d..c457cf0 100644
82630--- a/include/net/caif/cfctrl.h
82631+++ b/include/net/caif/cfctrl.h
82632@@ -52,7 +52,7 @@ struct cfctrl_rsp {
82633 void (*radioset_rsp)(void);
82634 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
82635 struct cflayer *client_layer);
82636-};
82637+} __no_const;
82638
82639 /* Link Setup Parameters for CAIF-Links. */
82640 struct cfctrl_link_param {
82641@@ -101,8 +101,8 @@ struct cfctrl_request_info {
82642 struct cfctrl {
82643 struct cfsrvl serv;
82644 struct cfctrl_rsp res;
82645- atomic_t req_seq_no;
82646- atomic_t rsp_seq_no;
82647+ atomic_unchecked_t req_seq_no;
82648+ atomic_unchecked_t rsp_seq_no;
82649 struct list_head list;
82650 /* Protects from simultaneous access to first_req list */
82651 spinlock_t info_list_lock;
82652diff --git a/include/net/flow.h b/include/net/flow.h
82653index 65ce471..b7bbe9b 100644
82654--- a/include/net/flow.h
82655+++ b/include/net/flow.h
82656@@ -222,6 +222,6 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
82657
82658 void flow_cache_flush(void);
82659 void flow_cache_flush_deferred(void);
82660-extern atomic_t flow_cache_genid;
82661+extern atomic_unchecked_t flow_cache_genid;
82662
82663 #endif
82664diff --git a/include/net/genetlink.h b/include/net/genetlink.h
82665index 1b177ed..a24a138 100644
82666--- a/include/net/genetlink.h
82667+++ b/include/net/genetlink.h
82668@@ -118,7 +118,7 @@ struct genl_ops {
82669 u8 cmd;
82670 u8 internal_flags;
82671 u8 flags;
82672-};
82673+} __do_const;
82674
82675 int __genl_register_family(struct genl_family *family);
82676
82677diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
82678index 734d9b5..48a9a4b 100644
82679--- a/include/net/gro_cells.h
82680+++ b/include/net/gro_cells.h
82681@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
82682 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
82683
82684 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
82685- atomic_long_inc(&dev->rx_dropped);
82686+ atomic_long_inc_unchecked(&dev->rx_dropped);
82687 kfree_skb(skb);
82688 return;
82689 }
82690diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
82691index c55aeed..b3393f4 100644
82692--- a/include/net/inet_connection_sock.h
82693+++ b/include/net/inet_connection_sock.h
82694@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
82695 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
82696 int (*bind_conflict)(const struct sock *sk,
82697 const struct inet_bind_bucket *tb, bool relax);
82698-};
82699+} __do_const;
82700
82701 /** inet_connection_sock - INET connection oriented sock
82702 *
82703diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
82704index f4e127a..c3d5e9c 100644
82705--- a/include/net/inetpeer.h
82706+++ b/include/net/inetpeer.h
82707@@ -47,8 +47,8 @@ struct inet_peer {
82708 */
82709 union {
82710 struct {
82711- atomic_t rid; /* Frag reception counter */
82712- atomic_t ip_id_count; /* IP ID for the next packet */
82713+ atomic_unchecked_t rid; /* Frag reception counter */
82714+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
82715 };
82716 struct rcu_head rcu;
82717 struct inet_peer *gc_next;
82718@@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
82719 /* can be called with or without local BH being disabled */
82720 static inline int inet_getid(struct inet_peer *p, int more)
82721 {
82722- int old, new;
82723+ int id;
82724 more++;
82725 inet_peer_refcheck(p);
82726- do {
82727- old = atomic_read(&p->ip_id_count);
82728- new = old + more;
82729- if (!new)
82730- new = 1;
82731- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
82732- return new;
82733+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
82734+ if (!id)
82735+ id = atomic_inc_return_unchecked(&p->ip_id_count);
82736+ return id;
82737 }
82738
82739 #endif /* _NET_INETPEER_H */
82740diff --git a/include/net/ip.h b/include/net/ip.h
82741index 5a25f36..2e73203 100644
82742--- a/include/net/ip.h
82743+++ b/include/net/ip.h
82744@@ -219,7 +219,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
82745
82746 void inet_get_local_port_range(struct net *net, int *low, int *high);
82747
82748-extern unsigned long *sysctl_local_reserved_ports;
82749+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
82750 static inline int inet_is_reserved_local_port(int port)
82751 {
82752 return test_bit(port, sysctl_local_reserved_ports);
82753diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
82754index 9922093..a1755d6 100644
82755--- a/include/net/ip_fib.h
82756+++ b/include/net/ip_fib.h
82757@@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
82758
82759 #define FIB_RES_SADDR(net, res) \
82760 ((FIB_RES_NH(res).nh_saddr_genid == \
82761- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
82762+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
82763 FIB_RES_NH(res).nh_saddr : \
82764 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
82765 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
82766diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
82767index 5679d92..2e7a690 100644
82768--- a/include/net/ip_vs.h
82769+++ b/include/net/ip_vs.h
82770@@ -558,7 +558,7 @@ struct ip_vs_conn {
82771 struct ip_vs_conn *control; /* Master control connection */
82772 atomic_t n_control; /* Number of controlled ones */
82773 struct ip_vs_dest *dest; /* real server */
82774- atomic_t in_pkts; /* incoming packet counter */
82775+ atomic_unchecked_t in_pkts; /* incoming packet counter */
82776
82777 /* packet transmitter for different forwarding methods. If it
82778 mangles the packet, it must return NF_DROP or better NF_STOLEN,
82779@@ -705,7 +705,7 @@ struct ip_vs_dest {
82780 __be16 port; /* port number of the server */
82781 union nf_inet_addr addr; /* IP address of the server */
82782 volatile unsigned int flags; /* dest status flags */
82783- atomic_t conn_flags; /* flags to copy to conn */
82784+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
82785 atomic_t weight; /* server weight */
82786
82787 atomic_t refcnt; /* reference counter */
82788@@ -960,11 +960,11 @@ struct netns_ipvs {
82789 /* ip_vs_lblc */
82790 int sysctl_lblc_expiration;
82791 struct ctl_table_header *lblc_ctl_header;
82792- struct ctl_table *lblc_ctl_table;
82793+ ctl_table_no_const *lblc_ctl_table;
82794 /* ip_vs_lblcr */
82795 int sysctl_lblcr_expiration;
82796 struct ctl_table_header *lblcr_ctl_header;
82797- struct ctl_table *lblcr_ctl_table;
82798+ ctl_table_no_const *lblcr_ctl_table;
82799 /* ip_vs_est */
82800 struct list_head est_list; /* estimator list */
82801 spinlock_t est_lock;
82802diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
82803index 0224402..dafaf94a 100644
82804--- a/include/net/irda/ircomm_tty.h
82805+++ b/include/net/irda/ircomm_tty.h
82806@@ -35,6 +35,7 @@
82807 #include <linux/termios.h>
82808 #include <linux/timer.h>
82809 #include <linux/tty.h> /* struct tty_struct */
82810+#include <asm/local.h>
82811
82812 #include <net/irda/irias_object.h>
82813 #include <net/irda/ircomm_core.h>
82814diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
82815index 714cc9a..ea05f3e 100644
82816--- a/include/net/iucv/af_iucv.h
82817+++ b/include/net/iucv/af_iucv.h
82818@@ -149,7 +149,7 @@ struct iucv_skb_cb {
82819 struct iucv_sock_list {
82820 struct hlist_head head;
82821 rwlock_t lock;
82822- atomic_t autobind_name;
82823+ atomic_unchecked_t autobind_name;
82824 };
82825
82826 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
82827diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
82828index f3be818..bf46196 100644
82829--- a/include/net/llc_c_ac.h
82830+++ b/include/net/llc_c_ac.h
82831@@ -87,7 +87,7 @@
82832 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
82833 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
82834
82835-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
82836+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
82837
82838 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
82839 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
82840diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
82841index 3948cf1..83b28c4 100644
82842--- a/include/net/llc_c_ev.h
82843+++ b/include/net/llc_c_ev.h
82844@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
82845 return (struct llc_conn_state_ev *)skb->cb;
82846 }
82847
82848-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
82849-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
82850+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
82851+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
82852
82853 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
82854 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
82855diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
82856index 0e79cfb..f46db31 100644
82857--- a/include/net/llc_c_st.h
82858+++ b/include/net/llc_c_st.h
82859@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
82860 u8 next_state;
82861 llc_conn_ev_qfyr_t *ev_qualifiers;
82862 llc_conn_action_t *ev_actions;
82863-};
82864+} __do_const;
82865
82866 struct llc_conn_state {
82867 u8 current_state;
82868diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
82869index a61b98c..aade1eb 100644
82870--- a/include/net/llc_s_ac.h
82871+++ b/include/net/llc_s_ac.h
82872@@ -23,7 +23,7 @@
82873 #define SAP_ACT_TEST_IND 9
82874
82875 /* All action functions must look like this */
82876-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
82877+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
82878
82879 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
82880 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
82881diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
82882index 567c681..cd73ac0 100644
82883--- a/include/net/llc_s_st.h
82884+++ b/include/net/llc_s_st.h
82885@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
82886 llc_sap_ev_t ev;
82887 u8 next_state;
82888 llc_sap_action_t *ev_actions;
82889-};
82890+} __do_const;
82891
82892 struct llc_sap_state {
82893 u8 curr_state;
82894diff --git a/include/net/mac80211.h b/include/net/mac80211.h
82895index 7ceed99..d3ffaa2 100644
82896--- a/include/net/mac80211.h
82897+++ b/include/net/mac80211.h
82898@@ -4407,7 +4407,7 @@ struct rate_control_ops {
82899 void (*add_sta_debugfs)(void *priv, void *priv_sta,
82900 struct dentry *dir);
82901 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
82902-};
82903+} __do_const;
82904
82905 static inline int rate_supported(struct ieee80211_sta *sta,
82906 enum ieee80211_band band,
82907diff --git a/include/net/neighbour.h b/include/net/neighbour.h
82908index 536501a..47b7982 100644
82909--- a/include/net/neighbour.h
82910+++ b/include/net/neighbour.h
82911@@ -123,7 +123,7 @@ struct neigh_ops {
82912 void (*error_report)(struct neighbour *, struct sk_buff *);
82913 int (*output)(struct neighbour *, struct sk_buff *);
82914 int (*connected_output)(struct neighbour *, struct sk_buff *);
82915-};
82916+} __do_const;
82917
82918 struct pneigh_entry {
82919 struct pneigh_entry *next;
82920@@ -163,7 +163,6 @@ struct neigh_table {
82921 void (*proxy_redo)(struct sk_buff *skb);
82922 char *id;
82923 struct neigh_parms parms;
82924- /* HACK. gc_* should follow parms without a gap! */
82925 int gc_interval;
82926 int gc_thresh1;
82927 int gc_thresh2;
82928@@ -178,7 +177,7 @@ struct neigh_table {
82929 struct neigh_statistics __percpu *stats;
82930 struct neigh_hash_table __rcu *nht;
82931 struct pneigh_entry **phash_buckets;
82932-};
82933+} __randomize_layout;
82934
82935 #define NEIGH_PRIV_ALIGN sizeof(long long)
82936 #define NEIGH_ENTRY_SIZE(size) ALIGN((size), NEIGH_PRIV_ALIGN)
82937diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
82938index da68c9a..c4a0720 100644
82939--- a/include/net/net_namespace.h
82940+++ b/include/net/net_namespace.h
82941@@ -124,8 +124,8 @@ struct net {
82942 struct netns_ipvs *ipvs;
82943 #endif
82944 struct sock *diag_nlsk;
82945- atomic_t fnhe_genid;
82946-};
82947+ atomic_unchecked_t fnhe_genid;
82948+} __randomize_layout;
82949
82950 /*
82951 * ifindex generation is per-net namespace, and loopback is
82952@@ -281,7 +281,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
82953 #define __net_init __init
82954 #define __net_exit __exit_refok
82955 #define __net_initdata __initdata
82956+#ifdef CONSTIFY_PLUGIN
82957 #define __net_initconst __initconst
82958+#else
82959+#define __net_initconst __initdata
82960+#endif
82961 #endif
82962
82963 struct pernet_operations {
82964@@ -291,7 +295,7 @@ struct pernet_operations {
82965 void (*exit_batch)(struct list_head *net_exit_list);
82966 int *id;
82967 size_t size;
82968-};
82969+} __do_const;
82970
82971 /*
82972 * Use these carefully. If you implement a network device and it
82973@@ -339,23 +343,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
82974
82975 static inline int rt_genid_ipv4(struct net *net)
82976 {
82977- return atomic_read(&net->ipv4.rt_genid);
82978+ return atomic_read_unchecked(&net->ipv4.rt_genid);
82979 }
82980
82981 static inline void rt_genid_bump_ipv4(struct net *net)
82982 {
82983- atomic_inc(&net->ipv4.rt_genid);
82984+ atomic_inc_unchecked(&net->ipv4.rt_genid);
82985 }
82986
82987 #if IS_ENABLED(CONFIG_IPV6)
82988 static inline int rt_genid_ipv6(struct net *net)
82989 {
82990- return atomic_read(&net->ipv6.rt_genid);
82991+ return atomic_read_unchecked(&net->ipv6.rt_genid);
82992 }
82993
82994 static inline void rt_genid_bump_ipv6(struct net *net)
82995 {
82996- atomic_inc(&net->ipv6.rt_genid);
82997+ atomic_inc_unchecked(&net->ipv6.rt_genid);
82998 }
82999 #else
83000 static inline int rt_genid_ipv6(struct net *net)
83001@@ -377,12 +381,12 @@ static inline void rt_genid_bump_all(struct net *net)
83002
83003 static inline int fnhe_genid(struct net *net)
83004 {
83005- return atomic_read(&net->fnhe_genid);
83006+ return atomic_read_unchecked(&net->fnhe_genid);
83007 }
83008
83009 static inline void fnhe_genid_bump(struct net *net)
83010 {
83011- atomic_inc(&net->fnhe_genid);
83012+ atomic_inc_unchecked(&net->fnhe_genid);
83013 }
83014
83015 #endif /* __NET_NET_NAMESPACE_H */
83016diff --git a/include/net/netdma.h b/include/net/netdma.h
83017index 8ba8ce2..99b7fff 100644
83018--- a/include/net/netdma.h
83019+++ b/include/net/netdma.h
83020@@ -24,7 +24,7 @@
83021 #include <linux/dmaengine.h>
83022 #include <linux/skbuff.h>
83023
83024-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83025+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83026 struct sk_buff *skb, int offset, struct iovec *to,
83027 size_t len, struct dma_pinned_list *pinned_list);
83028
83029diff --git a/include/net/netlink.h b/include/net/netlink.h
83030index 2b47eaa..6d5bcc2 100644
83031--- a/include/net/netlink.h
83032+++ b/include/net/netlink.h
83033@@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
83034 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
83035 {
83036 if (mark)
83037- skb_trim(skb, (unsigned char *) mark - skb->data);
83038+ skb_trim(skb, (const unsigned char *) mark - skb->data);
83039 }
83040
83041 /**
83042diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
83043index c9c0c53..53f24c3 100644
83044--- a/include/net/netns/conntrack.h
83045+++ b/include/net/netns/conntrack.h
83046@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
83047 struct nf_proto_net {
83048 #ifdef CONFIG_SYSCTL
83049 struct ctl_table_header *ctl_table_header;
83050- struct ctl_table *ctl_table;
83051+ ctl_table_no_const *ctl_table;
83052 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
83053 struct ctl_table_header *ctl_compat_header;
83054- struct ctl_table *ctl_compat_table;
83055+ ctl_table_no_const *ctl_compat_table;
83056 #endif
83057 #endif
83058 unsigned int users;
83059@@ -58,7 +58,7 @@ struct nf_ip_net {
83060 struct nf_icmp_net icmpv6;
83061 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
83062 struct ctl_table_header *ctl_table_header;
83063- struct ctl_table *ctl_table;
83064+ ctl_table_no_const *ctl_table;
83065 #endif
83066 };
83067
83068diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
83069index ee520cb..9a0fd88 100644
83070--- a/include/net/netns/ipv4.h
83071+++ b/include/net/netns/ipv4.h
83072@@ -72,7 +72,7 @@ struct netns_ipv4 {
83073
83074 kgid_t sysctl_ping_group_range[2];
83075
83076- atomic_t dev_addr_genid;
83077+ atomic_unchecked_t dev_addr_genid;
83078
83079 #ifdef CONFIG_IP_MROUTE
83080 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
83081@@ -82,6 +82,6 @@ struct netns_ipv4 {
83082 struct fib_rules_ops *mr_rules_ops;
83083 #endif
83084 #endif
83085- atomic_t rt_genid;
83086+ atomic_unchecked_t rt_genid;
83087 };
83088 #endif
83089diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
83090index 0fb2401..477d81c 100644
83091--- a/include/net/netns/ipv6.h
83092+++ b/include/net/netns/ipv6.h
83093@@ -71,8 +71,8 @@ struct netns_ipv6 {
83094 struct fib_rules_ops *mr6_rules_ops;
83095 #endif
83096 #endif
83097- atomic_t dev_addr_genid;
83098- atomic_t rt_genid;
83099+ atomic_unchecked_t dev_addr_genid;
83100+ atomic_unchecked_t rt_genid;
83101 };
83102
83103 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
83104diff --git a/include/net/ping.h b/include/net/ping.h
83105index 90f4841..74446a8 100644
83106--- a/include/net/ping.h
83107+++ b/include/net/ping.h
83108@@ -56,7 +56,7 @@ struct ping_iter_state {
83109 extern struct proto ping_prot;
83110 extern struct ping_table ping_table;
83111 #if IS_ENABLED(CONFIG_IPV6)
83112-extern struct pingv6_ops pingv6_ops;
83113+extern struct pingv6_ops *pingv6_ops;
83114 #endif
83115
83116 struct pingfakehdr {
83117diff --git a/include/net/protocol.h b/include/net/protocol.h
83118index fbf7676..a5e21c3 100644
83119--- a/include/net/protocol.h
83120+++ b/include/net/protocol.h
83121@@ -44,7 +44,7 @@ struct net_protocol {
83122 void (*err_handler)(struct sk_buff *skb, u32 info);
83123 unsigned int no_policy:1,
83124 netns_ok:1;
83125-};
83126+} __do_const;
83127
83128 #if IS_ENABLED(CONFIG_IPV6)
83129 struct inet6_protocol {
83130@@ -57,7 +57,7 @@ struct inet6_protocol {
83131 u8 type, u8 code, int offset,
83132 __be32 info);
83133 unsigned int flags; /* INET6_PROTO_xxx */
83134-};
83135+} __do_const;
83136
83137 #define INET6_PROTO_NOPOLICY 0x1
83138 #define INET6_PROTO_FINAL 0x2
83139diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
83140index bb13a18..e734116 100644
83141--- a/include/net/rtnetlink.h
83142+++ b/include/net/rtnetlink.h
83143@@ -79,7 +79,7 @@ struct rtnl_link_ops {
83144 const struct net_device *dev);
83145 unsigned int (*get_num_tx_queues)(void);
83146 unsigned int (*get_num_rx_queues)(void);
83147-};
83148+} __do_const;
83149
83150 int __rtnl_link_register(struct rtnl_link_ops *ops);
83151 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
83152diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
83153index 6bd44fe..96f364e 100644
83154--- a/include/net/sctp/checksum.h
83155+++ b/include/net/sctp/checksum.h
83156@@ -62,8 +62,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
83157 unsigned int offset)
83158 {
83159 struct sctphdr *sh = sctp_hdr(skb);
83160- __le32 ret, old = sh->checksum;
83161- const struct skb_checksum_ops ops = {
83162+ __le32 ret, old = sh->checksum;
83163+ static const struct skb_checksum_ops ops = {
83164 .update = sctp_csum_update,
83165 .combine = sctp_csum_combine,
83166 };
83167diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
83168index 4ef75af..5aa073a 100644
83169--- a/include/net/sctp/sm.h
83170+++ b/include/net/sctp/sm.h
83171@@ -81,7 +81,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
83172 typedef struct {
83173 sctp_state_fn_t *fn;
83174 const char *name;
83175-} sctp_sm_table_entry_t;
83176+} __do_const sctp_sm_table_entry_t;
83177
83178 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
83179 * currently in use.
83180@@ -293,7 +293,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
83181 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
83182
83183 /* Extern declarations for major data structures. */
83184-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83185+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83186
83187
83188 /* Get the size of a DATA chunk payload. */
83189diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
83190index 0a248b3..4dcbe5c 100644
83191--- a/include/net/sctp/structs.h
83192+++ b/include/net/sctp/structs.h
83193@@ -508,7 +508,7 @@ struct sctp_pf {
83194 struct sctp_association *asoc);
83195 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
83196 struct sctp_af *af;
83197-};
83198+} __do_const;
83199
83200
83201 /* Structure to track chunk fragments that have been acked, but peer
83202diff --git a/include/net/sock.h b/include/net/sock.h
83203index 2ef3c3e..c89ee4c 100644
83204--- a/include/net/sock.h
83205+++ b/include/net/sock.h
83206@@ -348,7 +348,7 @@ struct sock {
83207 unsigned int sk_napi_id;
83208 unsigned int sk_ll_usec;
83209 #endif
83210- atomic_t sk_drops;
83211+ atomic_unchecked_t sk_drops;
83212 int sk_rcvbuf;
83213
83214 struct sk_filter __rcu *sk_filter;
83215@@ -1022,7 +1022,7 @@ struct proto {
83216 void (*destroy_cgroup)(struct mem_cgroup *memcg);
83217 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
83218 #endif
83219-};
83220+} __randomize_layout;
83221
83222 /*
83223 * Bits in struct cg_proto.flags
83224@@ -1209,7 +1209,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
83225 return ret >> PAGE_SHIFT;
83226 }
83227
83228-static inline long
83229+static inline long __intentional_overflow(-1)
83230 sk_memory_allocated(const struct sock *sk)
83231 {
83232 struct proto *prot = sk->sk_prot;
83233@@ -1354,7 +1354,7 @@ struct sock_iocb {
83234 struct scm_cookie *scm;
83235 struct msghdr *msg, async_msg;
83236 struct kiocb *kiocb;
83237-};
83238+} __randomize_layout;
83239
83240 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
83241 {
83242@@ -1813,7 +1813,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
83243 }
83244
83245 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
83246- char __user *from, char *to,
83247+ char __user *from, unsigned char *to,
83248 int copy, int offset)
83249 {
83250 if (skb->ip_summed == CHECKSUM_NONE) {
83251@@ -2075,7 +2075,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
83252 }
83253 }
83254
83255-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83256+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83257
83258 /**
83259 * sk_page_frag - return an appropriate page_frag
83260diff --git a/include/net/tcp.h b/include/net/tcp.h
83261index 9250d62..10a7f03 100644
83262--- a/include/net/tcp.h
83263+++ b/include/net/tcp.h
83264@@ -480,20 +480,21 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
83265 #ifdef CONFIG_SYN_COOKIES
83266 #include <linux/ktime.h>
83267
83268-/* Syncookies use a monotonic timer which increments every 64 seconds.
83269+/* Syncookies use a monotonic timer which increments every 60 seconds.
83270 * This counter is used both as a hash input and partially encoded into
83271 * the cookie value. A cookie is only validated further if the delta
83272 * between the current counter value and the encoded one is less than this,
83273- * i.e. a sent cookie is valid only at most for 128 seconds (or less if
83274+ * i.e. a sent cookie is valid only at most for 2*60 seconds (or less if
83275 * the counter advances immediately after a cookie is generated).
83276 */
83277 #define MAX_SYNCOOKIE_AGE 2
83278
83279 static inline u32 tcp_cookie_time(void)
83280 {
83281- struct timespec now;
83282- getnstimeofday(&now);
83283- return now.tv_sec >> 6; /* 64 seconds granularity */
83284+ u64 val = get_jiffies_64();
83285+
83286+ do_div(val, 60 * HZ);
83287+ return val;
83288 }
83289
83290 u32 __cookie_v4_init_sequence(const struct iphdr *iph, const struct tcphdr *th,
83291@@ -540,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
83292 void tcp_xmit_retransmit_queue(struct sock *);
83293 void tcp_simple_retransmit(struct sock *);
83294 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
83295-int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83296+int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83297
83298 void tcp_send_probe0(struct sock *);
83299 void tcp_send_partial(struct sock *);
83300@@ -711,8 +712,8 @@ struct tcp_skb_cb {
83301 struct inet6_skb_parm h6;
83302 #endif
83303 } header; /* For incoming frames */
83304- __u32 seq; /* Starting sequence number */
83305- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
83306+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
83307+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
83308 __u32 when; /* used to compute rtt's */
83309 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
83310
83311@@ -726,7 +727,7 @@ struct tcp_skb_cb {
83312
83313 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
83314 /* 1 byte hole */
83315- __u32 ack_seq; /* Sequence number ACK'd */
83316+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
83317 };
83318
83319 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
83320diff --git a/include/net/xfrm.h b/include/net/xfrm.h
83321index 6b82fdf..14d74d2 100644
83322--- a/include/net/xfrm.h
83323+++ b/include/net/xfrm.h
83324@@ -287,7 +287,6 @@ struct xfrm_dst;
83325 struct xfrm_policy_afinfo {
83326 unsigned short family;
83327 struct dst_ops *dst_ops;
83328- void (*garbage_collect)(struct net *net);
83329 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
83330 const xfrm_address_t *saddr,
83331 const xfrm_address_t *daddr);
83332@@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
83333 struct net_device *dev,
83334 const struct flowi *fl);
83335 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
83336-};
83337+} __do_const;
83338
83339 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
83340 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
83341@@ -344,7 +343,7 @@ struct xfrm_state_afinfo {
83342 int (*transport_finish)(struct sk_buff *skb,
83343 int async);
83344 void (*local_error)(struct sk_buff *skb, u32 mtu);
83345-};
83346+} __do_const;
83347
83348 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
83349 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
83350@@ -429,7 +428,7 @@ struct xfrm_mode {
83351 struct module *owner;
83352 unsigned int encap;
83353 int flags;
83354-};
83355+} __do_const;
83356
83357 /* Flags for xfrm_mode. */
83358 enum {
83359@@ -526,7 +525,7 @@ struct xfrm_policy {
83360 struct timer_list timer;
83361
83362 struct flow_cache_object flo;
83363- atomic_t genid;
83364+ atomic_unchecked_t genid;
83365 u32 priority;
83366 u32 index;
83367 struct xfrm_mark mark;
83368@@ -1166,6 +1165,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
83369 }
83370
83371 void xfrm_garbage_collect(struct net *net);
83372+void xfrm_garbage_collect_deferred(struct net *net);
83373
83374 #else
83375
83376@@ -1204,6 +1204,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
83377 static inline void xfrm_garbage_collect(struct net *net)
83378 {
83379 }
83380+static inline void xfrm_garbage_collect_deferred(struct net *net)
83381+{
83382+}
83383 #endif
83384
83385 static __inline__
83386diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
83387index 1017e0b..227aa4d 100644
83388--- a/include/rdma/iw_cm.h
83389+++ b/include/rdma/iw_cm.h
83390@@ -122,7 +122,7 @@ struct iw_cm_verbs {
83391 int backlog);
83392
83393 int (*destroy_listen)(struct iw_cm_id *cm_id);
83394-};
83395+} __no_const;
83396
83397 /**
83398 * iw_create_cm_id - Create an IW CM identifier.
83399diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
83400index 52beadf..598734c 100644
83401--- a/include/scsi/libfc.h
83402+++ b/include/scsi/libfc.h
83403@@ -771,6 +771,7 @@ struct libfc_function_template {
83404 */
83405 void (*disc_stop_final) (struct fc_lport *);
83406 };
83407+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
83408
83409 /**
83410 * struct fc_disc - Discovery context
83411@@ -875,7 +876,7 @@ struct fc_lport {
83412 struct fc_vport *vport;
83413
83414 /* Operational Information */
83415- struct libfc_function_template tt;
83416+ libfc_function_template_no_const tt;
83417 u8 link_up;
83418 u8 qfull;
83419 enum fc_lport_state state;
83420diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
83421index d65fbec..f80fef2 100644
83422--- a/include/scsi/scsi_device.h
83423+++ b/include/scsi/scsi_device.h
83424@@ -180,9 +180,9 @@ struct scsi_device {
83425 unsigned int max_device_blocked; /* what device_blocked counts down from */
83426 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
83427
83428- atomic_t iorequest_cnt;
83429- atomic_t iodone_cnt;
83430- atomic_t ioerr_cnt;
83431+ atomic_unchecked_t iorequest_cnt;
83432+ atomic_unchecked_t iodone_cnt;
83433+ atomic_unchecked_t ioerr_cnt;
83434
83435 struct device sdev_gendev,
83436 sdev_dev;
83437diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
83438index b797e8f..8e2c3aa 100644
83439--- a/include/scsi/scsi_transport_fc.h
83440+++ b/include/scsi/scsi_transport_fc.h
83441@@ -751,7 +751,8 @@ struct fc_function_template {
83442 unsigned long show_host_system_hostname:1;
83443
83444 unsigned long disable_target_scan:1;
83445-};
83446+} __do_const;
83447+typedef struct fc_function_template __no_const fc_function_template_no_const;
83448
83449
83450 /**
83451diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
83452index ae6c3b8..fd748ac 100644
83453--- a/include/sound/compress_driver.h
83454+++ b/include/sound/compress_driver.h
83455@@ -128,7 +128,7 @@ struct snd_compr_ops {
83456 struct snd_compr_caps *caps);
83457 int (*get_codec_caps) (struct snd_compr_stream *stream,
83458 struct snd_compr_codec_caps *codec);
83459-};
83460+} __no_const;
83461
83462 /**
83463 * struct snd_compr: Compressed device
83464diff --git a/include/sound/soc.h b/include/sound/soc.h
83465index 1f741cb..8cefc08 100644
83466--- a/include/sound/soc.h
83467+++ b/include/sound/soc.h
83468@@ -763,7 +763,7 @@ struct snd_soc_codec_driver {
83469 /* probe ordering - for components with runtime dependencies */
83470 int probe_order;
83471 int remove_order;
83472-};
83473+} __do_const;
83474
83475 /* SoC platform interface */
83476 struct snd_soc_platform_driver {
83477@@ -809,7 +809,7 @@ struct snd_soc_platform_driver {
83478 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
83479 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
83480 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
83481-};
83482+} __do_const;
83483
83484 struct snd_soc_platform {
83485 const char *name;
83486diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
83487index e3569f8..6544ffd 100644
83488--- a/include/target/target_core_base.h
83489+++ b/include/target/target_core_base.h
83490@@ -687,7 +687,7 @@ struct se_device {
83491 atomic_long_t write_bytes;
83492 /* Active commands on this virtual SE device */
83493 atomic_t simple_cmds;
83494- atomic_t dev_ordered_id;
83495+ atomic_unchecked_t dev_ordered_id;
83496 atomic_t dev_ordered_sync;
83497 atomic_t dev_qf_count;
83498 int export_count;
83499diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
83500new file mode 100644
83501index 0000000..fb634b7
83502--- /dev/null
83503+++ b/include/trace/events/fs.h
83504@@ -0,0 +1,53 @@
83505+#undef TRACE_SYSTEM
83506+#define TRACE_SYSTEM fs
83507+
83508+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
83509+#define _TRACE_FS_H
83510+
83511+#include <linux/fs.h>
83512+#include <linux/tracepoint.h>
83513+
83514+TRACE_EVENT(do_sys_open,
83515+
83516+ TP_PROTO(const char *filename, int flags, int mode),
83517+
83518+ TP_ARGS(filename, flags, mode),
83519+
83520+ TP_STRUCT__entry(
83521+ __string( filename, filename )
83522+ __field( int, flags )
83523+ __field( int, mode )
83524+ ),
83525+
83526+ TP_fast_assign(
83527+ __assign_str(filename, filename);
83528+ __entry->flags = flags;
83529+ __entry->mode = mode;
83530+ ),
83531+
83532+ TP_printk("\"%s\" %x %o",
83533+ __get_str(filename), __entry->flags, __entry->mode)
83534+);
83535+
83536+TRACE_EVENT(open_exec,
83537+
83538+ TP_PROTO(const char *filename),
83539+
83540+ TP_ARGS(filename),
83541+
83542+ TP_STRUCT__entry(
83543+ __string( filename, filename )
83544+ ),
83545+
83546+ TP_fast_assign(
83547+ __assign_str(filename, filename);
83548+ ),
83549+
83550+ TP_printk("\"%s\"",
83551+ __get_str(filename))
83552+);
83553+
83554+#endif /* _TRACE_FS_H */
83555+
83556+/* This part must be outside protection */
83557+#include <trace/define_trace.h>
83558diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
83559index 1c09820..7f5ec79 100644
83560--- a/include/trace/events/irq.h
83561+++ b/include/trace/events/irq.h
83562@@ -36,7 +36,7 @@ struct softirq_action;
83563 */
83564 TRACE_EVENT(irq_handler_entry,
83565
83566- TP_PROTO(int irq, struct irqaction *action),
83567+ TP_PROTO(int irq, const struct irqaction *action),
83568
83569 TP_ARGS(irq, action),
83570
83571@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
83572 */
83573 TRACE_EVENT(irq_handler_exit,
83574
83575- TP_PROTO(int irq, struct irqaction *action, int ret),
83576+ TP_PROTO(int irq, const struct irqaction *action, int ret),
83577
83578 TP_ARGS(irq, action, ret),
83579
83580diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
83581index 7caf44c..23c6f27 100644
83582--- a/include/uapi/linux/a.out.h
83583+++ b/include/uapi/linux/a.out.h
83584@@ -39,6 +39,14 @@ enum machine_type {
83585 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
83586 };
83587
83588+/* Constants for the N_FLAGS field */
83589+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
83590+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
83591+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
83592+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
83593+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
83594+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
83595+
83596 #if !defined (N_MAGIC)
83597 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
83598 #endif
83599diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
83600index d876736..ccce5c0 100644
83601--- a/include/uapi/linux/byteorder/little_endian.h
83602+++ b/include/uapi/linux/byteorder/little_endian.h
83603@@ -42,51 +42,51 @@
83604
83605 static inline __le64 __cpu_to_le64p(const __u64 *p)
83606 {
83607- return (__force __le64)*p;
83608+ return (__force const __le64)*p;
83609 }
83610-static inline __u64 __le64_to_cpup(const __le64 *p)
83611+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
83612 {
83613- return (__force __u64)*p;
83614+ return (__force const __u64)*p;
83615 }
83616 static inline __le32 __cpu_to_le32p(const __u32 *p)
83617 {
83618- return (__force __le32)*p;
83619+ return (__force const __le32)*p;
83620 }
83621 static inline __u32 __le32_to_cpup(const __le32 *p)
83622 {
83623- return (__force __u32)*p;
83624+ return (__force const __u32)*p;
83625 }
83626 static inline __le16 __cpu_to_le16p(const __u16 *p)
83627 {
83628- return (__force __le16)*p;
83629+ return (__force const __le16)*p;
83630 }
83631 static inline __u16 __le16_to_cpup(const __le16 *p)
83632 {
83633- return (__force __u16)*p;
83634+ return (__force const __u16)*p;
83635 }
83636 static inline __be64 __cpu_to_be64p(const __u64 *p)
83637 {
83638- return (__force __be64)__swab64p(p);
83639+ return (__force const __be64)__swab64p(p);
83640 }
83641 static inline __u64 __be64_to_cpup(const __be64 *p)
83642 {
83643- return __swab64p((__u64 *)p);
83644+ return __swab64p((const __u64 *)p);
83645 }
83646 static inline __be32 __cpu_to_be32p(const __u32 *p)
83647 {
83648- return (__force __be32)__swab32p(p);
83649+ return (__force const __be32)__swab32p(p);
83650 }
83651-static inline __u32 __be32_to_cpup(const __be32 *p)
83652+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
83653 {
83654- return __swab32p((__u32 *)p);
83655+ return __swab32p((const __u32 *)p);
83656 }
83657 static inline __be16 __cpu_to_be16p(const __u16 *p)
83658 {
83659- return (__force __be16)__swab16p(p);
83660+ return (__force const __be16)__swab16p(p);
83661 }
83662 static inline __u16 __be16_to_cpup(const __be16 *p)
83663 {
83664- return __swab16p((__u16 *)p);
83665+ return __swab16p((const __u16 *)p);
83666 }
83667 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
83668 #define __le64_to_cpus(x) do { (void)(x); } while (0)
83669diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
83670index ef6103b..d4e65dd 100644
83671--- a/include/uapi/linux/elf.h
83672+++ b/include/uapi/linux/elf.h
83673@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
83674 #define PT_GNU_EH_FRAME 0x6474e550
83675
83676 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
83677+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
83678+
83679+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
83680+
83681+/* Constants for the e_flags field */
83682+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
83683+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
83684+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
83685+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
83686+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
83687+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
83688
83689 /*
83690 * Extended Numbering
83691@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
83692 #define DT_DEBUG 21
83693 #define DT_TEXTREL 22
83694 #define DT_JMPREL 23
83695+#define DT_FLAGS 30
83696+ #define DF_TEXTREL 0x00000004
83697 #define DT_ENCODING 32
83698 #define OLD_DT_LOOS 0x60000000
83699 #define DT_LOOS 0x6000000d
83700@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
83701 #define PF_W 0x2
83702 #define PF_X 0x1
83703
83704+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
83705+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
83706+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
83707+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
83708+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
83709+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
83710+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
83711+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
83712+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
83713+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
83714+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
83715+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
83716+
83717 typedef struct elf32_phdr{
83718 Elf32_Word p_type;
83719 Elf32_Off p_offset;
83720@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
83721 #define EI_OSABI 7
83722 #define EI_PAD 8
83723
83724+#define EI_PAX 14
83725+
83726 #define ELFMAG0 0x7f /* EI_MAG */
83727 #define ELFMAG1 'E'
83728 #define ELFMAG2 'L'
83729diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
83730index aa169c4..6a2771d 100644
83731--- a/include/uapi/linux/personality.h
83732+++ b/include/uapi/linux/personality.h
83733@@ -30,6 +30,7 @@ enum {
83734 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
83735 ADDR_NO_RANDOMIZE | \
83736 ADDR_COMPAT_LAYOUT | \
83737+ ADDR_LIMIT_3GB | \
83738 MMAP_PAGE_ZERO)
83739
83740 /*
83741diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
83742index 7530e74..e714828 100644
83743--- a/include/uapi/linux/screen_info.h
83744+++ b/include/uapi/linux/screen_info.h
83745@@ -43,7 +43,8 @@ struct screen_info {
83746 __u16 pages; /* 0x32 */
83747 __u16 vesa_attributes; /* 0x34 */
83748 __u32 capabilities; /* 0x36 */
83749- __u8 _reserved[6]; /* 0x3a */
83750+ __u16 vesapm_size; /* 0x3a */
83751+ __u8 _reserved[4]; /* 0x3c */
83752 } __attribute__((packed));
83753
83754 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
83755diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
83756index 0e011eb..82681b1 100644
83757--- a/include/uapi/linux/swab.h
83758+++ b/include/uapi/linux/swab.h
83759@@ -43,7 +43,7 @@
83760 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
83761 */
83762
83763-static inline __attribute_const__ __u16 __fswab16(__u16 val)
83764+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
83765 {
83766 #ifdef __HAVE_BUILTIN_BSWAP16__
83767 return __builtin_bswap16(val);
83768@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
83769 #endif
83770 }
83771
83772-static inline __attribute_const__ __u32 __fswab32(__u32 val)
83773+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
83774 {
83775 #ifdef __HAVE_BUILTIN_BSWAP32__
83776 return __builtin_bswap32(val);
83777@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
83778 #endif
83779 }
83780
83781-static inline __attribute_const__ __u64 __fswab64(__u64 val)
83782+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
83783 {
83784 #ifdef __HAVE_BUILTIN_BSWAP64__
83785 return __builtin_bswap64(val);
83786diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
83787index 6d67213..552fdd9 100644
83788--- a/include/uapi/linux/sysctl.h
83789+++ b/include/uapi/linux/sysctl.h
83790@@ -155,8 +155,6 @@ enum
83791 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
83792 };
83793
83794-
83795-
83796 /* CTL_VM names: */
83797 enum
83798 {
83799diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
83800index 437f1b0..0eeb38d 100644
83801--- a/include/uapi/linux/videodev2.h
83802+++ b/include/uapi/linux/videodev2.h
83803@@ -1227,7 +1227,7 @@ struct v4l2_ext_control {
83804 union {
83805 __s32 value;
83806 __s64 value64;
83807- char *string;
83808+ char __user *string;
83809 };
83810 } __attribute__ ((packed));
83811
83812diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
83813index e4629b9..6958086 100644
83814--- a/include/uapi/linux/xattr.h
83815+++ b/include/uapi/linux/xattr.h
83816@@ -63,5 +63,9 @@
83817 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
83818 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
83819
83820+/* User namespace */
83821+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
83822+#define XATTR_PAX_FLAGS_SUFFIX "flags"
83823+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
83824
83825 #endif /* _UAPI_LINUX_XATTR_H */
83826diff --git a/include/video/udlfb.h b/include/video/udlfb.h
83827index f9466fa..f4e2b81 100644
83828--- a/include/video/udlfb.h
83829+++ b/include/video/udlfb.h
83830@@ -53,10 +53,10 @@ struct dlfb_data {
83831 u32 pseudo_palette[256];
83832 int blank_mode; /*one of FB_BLANK_ */
83833 /* blit-only rendering path metrics, exposed through sysfs */
83834- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
83835- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
83836- atomic_t bytes_sent; /* to usb, after compression including overhead */
83837- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
83838+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
83839+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
83840+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
83841+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
83842 };
83843
83844 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
83845diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
83846index 30f5362..8ed8ac9 100644
83847--- a/include/video/uvesafb.h
83848+++ b/include/video/uvesafb.h
83849@@ -122,6 +122,7 @@ struct uvesafb_par {
83850 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
83851 u8 pmi_setpal; /* PMI for palette changes */
83852 u16 *pmi_base; /* protected mode interface location */
83853+ u8 *pmi_code; /* protected mode code location */
83854 void *pmi_start;
83855 void *pmi_pal;
83856 u8 *vbe_state_orig; /*
83857diff --git a/init/Kconfig b/init/Kconfig
83858index 4e5d96a..93cd8a1 100644
83859--- a/init/Kconfig
83860+++ b/init/Kconfig
83861@@ -1079,6 +1079,7 @@ endif # CGROUPS
83862
83863 config CHECKPOINT_RESTORE
83864 bool "Checkpoint/restore support" if EXPERT
83865+ depends on !GRKERNSEC
83866 default n
83867 help
83868 Enables additional kernel features in a sake of checkpoint/restore.
83869@@ -1550,7 +1551,7 @@ config SLUB_DEBUG
83870
83871 config COMPAT_BRK
83872 bool "Disable heap randomization"
83873- default y
83874+ default n
83875 help
83876 Randomizing heap placement makes heap exploits harder, but it
83877 also breaks ancient binaries (including anything libc5 based).
83878@@ -1838,7 +1839,7 @@ config INIT_ALL_POSSIBLE
83879 config STOP_MACHINE
83880 bool
83881 default y
83882- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
83883+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
83884 help
83885 Need stop_machine() primitive.
83886
83887diff --git a/init/Makefile b/init/Makefile
83888index 7bc47ee..6da2dc7 100644
83889--- a/init/Makefile
83890+++ b/init/Makefile
83891@@ -2,6 +2,9 @@
83892 # Makefile for the linux kernel.
83893 #
83894
83895+ccflags-y := $(GCC_PLUGINS_CFLAGS)
83896+asflags-y := $(GCC_PLUGINS_AFLAGS)
83897+
83898 obj-y := main.o version.o mounts.o
83899 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
83900 obj-y += noinitramfs.o
83901diff --git a/init/do_mounts.c b/init/do_mounts.c
83902index 8e5addc..c96ea61 100644
83903--- a/init/do_mounts.c
83904+++ b/init/do_mounts.c
83905@@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
83906 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
83907 {
83908 struct super_block *s;
83909- int err = sys_mount(name, "/root", fs, flags, data);
83910+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
83911 if (err)
83912 return err;
83913
83914- sys_chdir("/root");
83915+ sys_chdir((const char __force_user *)"/root");
83916 s = current->fs->pwd.dentry->d_sb;
83917 ROOT_DEV = s->s_dev;
83918 printk(KERN_INFO
83919@@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
83920 va_start(args, fmt);
83921 vsprintf(buf, fmt, args);
83922 va_end(args);
83923- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
83924+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
83925 if (fd >= 0) {
83926 sys_ioctl(fd, FDEJECT, 0);
83927 sys_close(fd);
83928 }
83929 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
83930- fd = sys_open("/dev/console", O_RDWR, 0);
83931+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
83932 if (fd >= 0) {
83933 sys_ioctl(fd, TCGETS, (long)&termios);
83934 termios.c_lflag &= ~ICANON;
83935 sys_ioctl(fd, TCSETSF, (long)&termios);
83936- sys_read(fd, &c, 1);
83937+ sys_read(fd, (char __user *)&c, 1);
83938 termios.c_lflag |= ICANON;
83939 sys_ioctl(fd, TCSETSF, (long)&termios);
83940 sys_close(fd);
83941@@ -589,8 +589,8 @@ void __init prepare_namespace(void)
83942 mount_root();
83943 out:
83944 devtmpfs_mount("dev");
83945- sys_mount(".", "/", NULL, MS_MOVE, NULL);
83946- sys_chroot(".");
83947+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
83948+ sys_chroot((const char __force_user *)".");
83949 }
83950
83951 static bool is_tmpfs;
83952diff --git a/init/do_mounts.h b/init/do_mounts.h
83953index f5b978a..69dbfe8 100644
83954--- a/init/do_mounts.h
83955+++ b/init/do_mounts.h
83956@@ -15,15 +15,15 @@ extern int root_mountflags;
83957
83958 static inline int create_dev(char *name, dev_t dev)
83959 {
83960- sys_unlink(name);
83961- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
83962+ sys_unlink((char __force_user *)name);
83963+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
83964 }
83965
83966 #if BITS_PER_LONG == 32
83967 static inline u32 bstat(char *name)
83968 {
83969 struct stat64 stat;
83970- if (sys_stat64(name, &stat) != 0)
83971+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
83972 return 0;
83973 if (!S_ISBLK(stat.st_mode))
83974 return 0;
83975@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
83976 static inline u32 bstat(char *name)
83977 {
83978 struct stat stat;
83979- if (sys_newstat(name, &stat) != 0)
83980+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
83981 return 0;
83982 if (!S_ISBLK(stat.st_mode))
83983 return 0;
83984diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
83985index 3e0878e..8a9d7a0 100644
83986--- a/init/do_mounts_initrd.c
83987+++ b/init/do_mounts_initrd.c
83988@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
83989 {
83990 sys_unshare(CLONE_FS | CLONE_FILES);
83991 /* stdin/stdout/stderr for /linuxrc */
83992- sys_open("/dev/console", O_RDWR, 0);
83993+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
83994 sys_dup(0);
83995 sys_dup(0);
83996 /* move initrd over / and chdir/chroot in initrd root */
83997- sys_chdir("/root");
83998- sys_mount(".", "/", NULL, MS_MOVE, NULL);
83999- sys_chroot(".");
84000+ sys_chdir((const char __force_user *)"/root");
84001+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84002+ sys_chroot((const char __force_user *)".");
84003 sys_setsid();
84004 return 0;
84005 }
84006@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
84007 create_dev("/dev/root.old", Root_RAM0);
84008 /* mount initrd on rootfs' /root */
84009 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
84010- sys_mkdir("/old", 0700);
84011- sys_chdir("/old");
84012+ sys_mkdir((const char __force_user *)"/old", 0700);
84013+ sys_chdir((const char __force_user *)"/old");
84014
84015 /* try loading default modules from initrd */
84016 load_default_modules();
84017@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
84018 current->flags &= ~PF_FREEZER_SKIP;
84019
84020 /* move initrd to rootfs' /old */
84021- sys_mount("..", ".", NULL, MS_MOVE, NULL);
84022+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
84023 /* switch root and cwd back to / of rootfs */
84024- sys_chroot("..");
84025+ sys_chroot((const char __force_user *)"..");
84026
84027 if (new_decode_dev(real_root_dev) == Root_RAM0) {
84028- sys_chdir("/old");
84029+ sys_chdir((const char __force_user *)"/old");
84030 return;
84031 }
84032
84033- sys_chdir("/");
84034+ sys_chdir((const char __force_user *)"/");
84035 ROOT_DEV = new_decode_dev(real_root_dev);
84036 mount_root();
84037
84038 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
84039- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
84040+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
84041 if (!error)
84042 printk("okay\n");
84043 else {
84044- int fd = sys_open("/dev/root.old", O_RDWR, 0);
84045+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
84046 if (error == -ENOENT)
84047 printk("/initrd does not exist. Ignored.\n");
84048 else
84049 printk("failed\n");
84050 printk(KERN_NOTICE "Unmounting old root\n");
84051- sys_umount("/old", MNT_DETACH);
84052+ sys_umount((char __force_user *)"/old", MNT_DETACH);
84053 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
84054 if (fd < 0) {
84055 error = fd;
84056@@ -127,11 +127,11 @@ int __init initrd_load(void)
84057 * mounted in the normal path.
84058 */
84059 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
84060- sys_unlink("/initrd.image");
84061+ sys_unlink((const char __force_user *)"/initrd.image");
84062 handle_initrd();
84063 return 1;
84064 }
84065 }
84066- sys_unlink("/initrd.image");
84067+ sys_unlink((const char __force_user *)"/initrd.image");
84068 return 0;
84069 }
84070diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
84071index 8cb6db5..d729f50 100644
84072--- a/init/do_mounts_md.c
84073+++ b/init/do_mounts_md.c
84074@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
84075 partitioned ? "_d" : "", minor,
84076 md_setup_args[ent].device_names);
84077
84078- fd = sys_open(name, 0, 0);
84079+ fd = sys_open((char __force_user *)name, 0, 0);
84080 if (fd < 0) {
84081 printk(KERN_ERR "md: open failed - cannot start "
84082 "array %s\n", name);
84083@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
84084 * array without it
84085 */
84086 sys_close(fd);
84087- fd = sys_open(name, 0, 0);
84088+ fd = sys_open((char __force_user *)name, 0, 0);
84089 sys_ioctl(fd, BLKRRPART, 0);
84090 }
84091 sys_close(fd);
84092@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
84093
84094 wait_for_device_probe();
84095
84096- fd = sys_open("/dev/md0", 0, 0);
84097+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
84098 if (fd >= 0) {
84099 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
84100 sys_close(fd);
84101diff --git a/init/init_task.c b/init/init_task.c
84102index ba0a7f36..2bcf1d5 100644
84103--- a/init/init_task.c
84104+++ b/init/init_task.c
84105@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
84106 * Initial thread structure. Alignment of this is handled by a special
84107 * linker map entry.
84108 */
84109+#ifdef CONFIG_X86
84110+union thread_union init_thread_union __init_task_data;
84111+#else
84112 union thread_union init_thread_union __init_task_data =
84113 { INIT_THREAD_INFO(init_task) };
84114+#endif
84115diff --git a/init/initramfs.c b/init/initramfs.c
84116index a67ef9d..2d17ed9 100644
84117--- a/init/initramfs.c
84118+++ b/init/initramfs.c
84119@@ -84,7 +84,7 @@ static void __init free_hash(void)
84120 }
84121 }
84122
84123-static long __init do_utime(char *filename, time_t mtime)
84124+static long __init do_utime(char __force_user *filename, time_t mtime)
84125 {
84126 struct timespec t[2];
84127
84128@@ -119,7 +119,7 @@ static void __init dir_utime(void)
84129 struct dir_entry *de, *tmp;
84130 list_for_each_entry_safe(de, tmp, &dir_list, list) {
84131 list_del(&de->list);
84132- do_utime(de->name, de->mtime);
84133+ do_utime((char __force_user *)de->name, de->mtime);
84134 kfree(de->name);
84135 kfree(de);
84136 }
84137@@ -281,7 +281,7 @@ static int __init maybe_link(void)
84138 if (nlink >= 2) {
84139 char *old = find_link(major, minor, ino, mode, collected);
84140 if (old)
84141- return (sys_link(old, collected) < 0) ? -1 : 1;
84142+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
84143 }
84144 return 0;
84145 }
84146@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
84147 {
84148 struct stat st;
84149
84150- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
84151+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
84152 if (S_ISDIR(st.st_mode))
84153- sys_rmdir(path);
84154+ sys_rmdir((char __force_user *)path);
84155 else
84156- sys_unlink(path);
84157+ sys_unlink((char __force_user *)path);
84158 }
84159 }
84160
84161@@ -315,7 +315,7 @@ static int __init do_name(void)
84162 int openflags = O_WRONLY|O_CREAT;
84163 if (ml != 1)
84164 openflags |= O_TRUNC;
84165- wfd = sys_open(collected, openflags, mode);
84166+ wfd = sys_open((char __force_user *)collected, openflags, mode);
84167
84168 if (wfd >= 0) {
84169 sys_fchown(wfd, uid, gid);
84170@@ -327,17 +327,17 @@ static int __init do_name(void)
84171 }
84172 }
84173 } else if (S_ISDIR(mode)) {
84174- sys_mkdir(collected, mode);
84175- sys_chown(collected, uid, gid);
84176- sys_chmod(collected, mode);
84177+ sys_mkdir((char __force_user *)collected, mode);
84178+ sys_chown((char __force_user *)collected, uid, gid);
84179+ sys_chmod((char __force_user *)collected, mode);
84180 dir_add(collected, mtime);
84181 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
84182 S_ISFIFO(mode) || S_ISSOCK(mode)) {
84183 if (maybe_link() == 0) {
84184- sys_mknod(collected, mode, rdev);
84185- sys_chown(collected, uid, gid);
84186- sys_chmod(collected, mode);
84187- do_utime(collected, mtime);
84188+ sys_mknod((char __force_user *)collected, mode, rdev);
84189+ sys_chown((char __force_user *)collected, uid, gid);
84190+ sys_chmod((char __force_user *)collected, mode);
84191+ do_utime((char __force_user *)collected, mtime);
84192 }
84193 }
84194 return 0;
84195@@ -346,15 +346,15 @@ static int __init do_name(void)
84196 static int __init do_copy(void)
84197 {
84198 if (count >= body_len) {
84199- sys_write(wfd, victim, body_len);
84200+ sys_write(wfd, (char __force_user *)victim, body_len);
84201 sys_close(wfd);
84202- do_utime(vcollected, mtime);
84203+ do_utime((char __force_user *)vcollected, mtime);
84204 kfree(vcollected);
84205 eat(body_len);
84206 state = SkipIt;
84207 return 0;
84208 } else {
84209- sys_write(wfd, victim, count);
84210+ sys_write(wfd, (char __force_user *)victim, count);
84211 body_len -= count;
84212 eat(count);
84213 return 1;
84214@@ -365,9 +365,9 @@ static int __init do_symlink(void)
84215 {
84216 collected[N_ALIGN(name_len) + body_len] = '\0';
84217 clean_path(collected, 0);
84218- sys_symlink(collected + N_ALIGN(name_len), collected);
84219- sys_lchown(collected, uid, gid);
84220- do_utime(collected, mtime);
84221+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
84222+ sys_lchown((char __force_user *)collected, uid, gid);
84223+ do_utime((char __force_user *)collected, mtime);
84224 state = SkipIt;
84225 next_state = Reset;
84226 return 0;
84227@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
84228 {
84229 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
84230 if (err)
84231- panic(err); /* Failed to decompress INTERNAL initramfs */
84232+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
84233 if (initrd_start) {
84234 #ifdef CONFIG_BLK_DEV_RAM
84235 int fd;
84236diff --git a/init/main.c b/init/main.c
84237index febc511..f0851763 100644
84238--- a/init/main.c
84239+++ b/init/main.c
84240@@ -103,6 +103,8 @@ static inline void mark_rodata_ro(void) { }
84241 extern void tc_init(void);
84242 #endif
84243
84244+extern void grsecurity_init(void);
84245+
84246 /*
84247 * Debug helper: via this flag we know that we are in 'early bootup code'
84248 * where only the boot processor is running with IRQ disabled. This means
84249@@ -164,6 +166,75 @@ static int __init set_reset_devices(char *str)
84250
84251 __setup("reset_devices", set_reset_devices);
84252
84253+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
84254+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
84255+static int __init setup_grsec_proc_gid(char *str)
84256+{
84257+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
84258+ return 1;
84259+}
84260+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
84261+#endif
84262+
84263+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
84264+unsigned long pax_user_shadow_base __read_only;
84265+EXPORT_SYMBOL(pax_user_shadow_base);
84266+extern char pax_enter_kernel_user[];
84267+extern char pax_exit_kernel_user[];
84268+#endif
84269+
84270+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
84271+static int __init setup_pax_nouderef(char *str)
84272+{
84273+#ifdef CONFIG_X86_32
84274+ unsigned int cpu;
84275+ struct desc_struct *gdt;
84276+
84277+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
84278+ gdt = get_cpu_gdt_table(cpu);
84279+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
84280+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
84281+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
84282+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
84283+ }
84284+ loadsegment(ds, __KERNEL_DS);
84285+ loadsegment(es, __KERNEL_DS);
84286+ loadsegment(ss, __KERNEL_DS);
84287+#else
84288+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
84289+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
84290+ clone_pgd_mask = ~(pgdval_t)0UL;
84291+ pax_user_shadow_base = 0UL;
84292+ setup_clear_cpu_cap(X86_FEATURE_PCID);
84293+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
84294+#endif
84295+
84296+ return 0;
84297+}
84298+early_param("pax_nouderef", setup_pax_nouderef);
84299+
84300+#ifdef CONFIG_X86_64
84301+static int __init setup_pax_weakuderef(char *str)
84302+{
84303+ if (clone_pgd_mask != ~(pgdval_t)0UL)
84304+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
84305+ return 1;
84306+}
84307+__setup("pax_weakuderef", setup_pax_weakuderef);
84308+#endif
84309+#endif
84310+
84311+#ifdef CONFIG_PAX_SOFTMODE
84312+int pax_softmode;
84313+
84314+static int __init setup_pax_softmode(char *str)
84315+{
84316+ get_option(&str, &pax_softmode);
84317+ return 1;
84318+}
84319+__setup("pax_softmode=", setup_pax_softmode);
84320+#endif
84321+
84322 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
84323 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
84324 static const char *panic_later, *panic_param;
84325@@ -691,25 +762,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
84326 {
84327 int count = preempt_count();
84328 int ret;
84329- char msgbuf[64];
84330+ const char *msg1 = "", *msg2 = "";
84331
84332 if (initcall_debug)
84333 ret = do_one_initcall_debug(fn);
84334 else
84335 ret = fn();
84336
84337- msgbuf[0] = 0;
84338-
84339 if (preempt_count() != count) {
84340- sprintf(msgbuf, "preemption imbalance ");
84341+ msg1 = " preemption imbalance";
84342 preempt_count_set(count);
84343 }
84344 if (irqs_disabled()) {
84345- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
84346+ msg2 = " disabled interrupts";
84347 local_irq_enable();
84348 }
84349- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
84350+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
84351
84352+ add_latent_entropy();
84353 return ret;
84354 }
84355
84356@@ -816,8 +886,8 @@ static int run_init_process(const char *init_filename)
84357 {
84358 argv_init[0] = init_filename;
84359 return do_execve(init_filename,
84360- (const char __user *const __user *)argv_init,
84361- (const char __user *const __user *)envp_init);
84362+ (const char __user *const __force_user *)argv_init,
84363+ (const char __user *const __force_user *)envp_init);
84364 }
84365
84366 static int try_to_run_init_process(const char *init_filename)
84367@@ -834,6 +904,10 @@ static int try_to_run_init_process(const char *init_filename)
84368 return ret;
84369 }
84370
84371+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84372+extern int gr_init_ran;
84373+#endif
84374+
84375 static noinline void __init kernel_init_freeable(void);
84376
84377 static int __ref kernel_init(void *unused)
84378@@ -858,6 +932,11 @@ static int __ref kernel_init(void *unused)
84379 ramdisk_execute_command, ret);
84380 }
84381
84382+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84383+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
84384+ gr_init_ran = 1;
84385+#endif
84386+
84387 /*
84388 * We try each of these until one succeeds.
84389 *
84390@@ -913,7 +992,7 @@ static noinline void __init kernel_init_freeable(void)
84391 do_basic_setup();
84392
84393 /* Open the /dev/console on the rootfs, this should never fail */
84394- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
84395+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
84396 pr_err("Warning: unable to open an initial console.\n");
84397
84398 (void) sys_dup(0);
84399@@ -926,11 +1005,13 @@ static noinline void __init kernel_init_freeable(void)
84400 if (!ramdisk_execute_command)
84401 ramdisk_execute_command = "/init";
84402
84403- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
84404+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
84405 ramdisk_execute_command = NULL;
84406 prepare_namespace();
84407 }
84408
84409+ grsecurity_init();
84410+
84411 /*
84412 * Ok, we have completed the initial bootup, and
84413 * we're essentially up and running. Get rid of the
84414diff --git a/ipc/compat.c b/ipc/compat.c
84415index 892f658..e7c6320 100644
84416--- a/ipc/compat.c
84417+++ b/ipc/compat.c
84418@@ -399,7 +399,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
84419 COMPAT_SHMLBA);
84420 if (err < 0)
84421 return err;
84422- return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
84423+ return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
84424 }
84425 case SHMDT:
84426 return sys_shmdt(compat_ptr(ptr));
84427diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
84428index b0e99de..09f385c 100644
84429--- a/ipc/ipc_sysctl.c
84430+++ b/ipc/ipc_sysctl.c
84431@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
84432 static int proc_ipc_dointvec(ctl_table *table, int write,
84433 void __user *buffer, size_t *lenp, loff_t *ppos)
84434 {
84435- struct ctl_table ipc_table;
84436+ ctl_table_no_const ipc_table;
84437
84438 memcpy(&ipc_table, table, sizeof(ipc_table));
84439 ipc_table.data = get_ipc(table);
84440@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
84441 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
84442 void __user *buffer, size_t *lenp, loff_t *ppos)
84443 {
84444- struct ctl_table ipc_table;
84445+ ctl_table_no_const ipc_table;
84446
84447 memcpy(&ipc_table, table, sizeof(ipc_table));
84448 ipc_table.data = get_ipc(table);
84449@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
84450 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
84451 void __user *buffer, size_t *lenp, loff_t *ppos)
84452 {
84453- struct ctl_table ipc_table;
84454+ ctl_table_no_const ipc_table;
84455 size_t lenp_bef = *lenp;
84456 int rc;
84457
84458@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
84459 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
84460 void __user *buffer, size_t *lenp, loff_t *ppos)
84461 {
84462- struct ctl_table ipc_table;
84463+ ctl_table_no_const ipc_table;
84464 memcpy(&ipc_table, table, sizeof(ipc_table));
84465 ipc_table.data = get_ipc(table);
84466
84467@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
84468 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
84469 void __user *buffer, size_t *lenp, loff_t *ppos)
84470 {
84471- struct ctl_table ipc_table;
84472+ ctl_table_no_const ipc_table;
84473 size_t lenp_bef = *lenp;
84474 int oldval;
84475 int rc;
84476diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
84477index 5bb8bfe..a38ec05 100644
84478--- a/ipc/mq_sysctl.c
84479+++ b/ipc/mq_sysctl.c
84480@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
84481 static int proc_mq_dointvec(ctl_table *table, int write,
84482 void __user *buffer, size_t *lenp, loff_t *ppos)
84483 {
84484- struct ctl_table mq_table;
84485+ ctl_table_no_const mq_table;
84486 memcpy(&mq_table, table, sizeof(mq_table));
84487 mq_table.data = get_mq(table);
84488
84489@@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
84490 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
84491 void __user *buffer, size_t *lenp, loff_t *ppos)
84492 {
84493- struct ctl_table mq_table;
84494+ ctl_table_no_const mq_table;
84495 memcpy(&mq_table, table, sizeof(mq_table));
84496 mq_table.data = get_mq(table);
84497
84498diff --git a/ipc/mqueue.c b/ipc/mqueue.c
84499index b8d4aed..96a4fe8 100644
84500--- a/ipc/mqueue.c
84501+++ b/ipc/mqueue.c
84502@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
84503 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
84504 info->attr.mq_msgsize);
84505
84506+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
84507 spin_lock(&mq_lock);
84508 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
84509 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
84510diff --git a/ipc/msg.c b/ipc/msg.c
84511index 52770bf..1c60a6f 100644
84512--- a/ipc/msg.c
84513+++ b/ipc/msg.c
84514@@ -297,18 +297,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
84515 return security_msg_queue_associate(msq, msgflg);
84516 }
84517
84518+static struct ipc_ops msg_ops = {
84519+ .getnew = newque,
84520+ .associate = msg_security,
84521+ .more_checks = NULL
84522+};
84523+
84524 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
84525 {
84526 struct ipc_namespace *ns;
84527- struct ipc_ops msg_ops;
84528 struct ipc_params msg_params;
84529
84530 ns = current->nsproxy->ipc_ns;
84531
84532- msg_ops.getnew = newque;
84533- msg_ops.associate = msg_security;
84534- msg_ops.more_checks = NULL;
84535-
84536 msg_params.key = key;
84537 msg_params.flg = msgflg;
84538
84539diff --git a/ipc/sem.c b/ipc/sem.c
84540index db9d241..bc8427c 100644
84541--- a/ipc/sem.c
84542+++ b/ipc/sem.c
84543@@ -562,10 +562,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
84544 return 0;
84545 }
84546
84547+static struct ipc_ops sem_ops = {
84548+ .getnew = newary,
84549+ .associate = sem_security,
84550+ .more_checks = sem_more_checks
84551+};
84552+
84553 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
84554 {
84555 struct ipc_namespace *ns;
84556- struct ipc_ops sem_ops;
84557 struct ipc_params sem_params;
84558
84559 ns = current->nsproxy->ipc_ns;
84560@@ -573,10 +578,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
84561 if (nsems < 0 || nsems > ns->sc_semmsl)
84562 return -EINVAL;
84563
84564- sem_ops.getnew = newary;
84565- sem_ops.associate = sem_security;
84566- sem_ops.more_checks = sem_more_checks;
84567-
84568 sem_params.key = key;
84569 sem_params.flg = semflg;
84570 sem_params.u.nsems = nsems;
84571diff --git a/ipc/shm.c b/ipc/shm.c
84572index 7a51443..3a257d8 100644
84573--- a/ipc/shm.c
84574+++ b/ipc/shm.c
84575@@ -72,6 +72,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
84576 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
84577 #endif
84578
84579+#ifdef CONFIG_GRKERNSEC
84580+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
84581+ const time_t shm_createtime, const kuid_t cuid,
84582+ const int shmid);
84583+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
84584+ const time_t shm_createtime);
84585+#endif
84586+
84587 void shm_init_ns(struct ipc_namespace *ns)
84588 {
84589 ns->shm_ctlmax = SHMMAX;
84590@@ -554,6 +562,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
84591 shp->shm_lprid = 0;
84592 shp->shm_atim = shp->shm_dtim = 0;
84593 shp->shm_ctim = get_seconds();
84594+#ifdef CONFIG_GRKERNSEC
84595+ {
84596+ struct timespec timeval;
84597+ do_posix_clock_monotonic_gettime(&timeval);
84598+
84599+ shp->shm_createtime = timeval.tv_sec;
84600+ }
84601+#endif
84602 shp->shm_segsz = size;
84603 shp->shm_nattch = 0;
84604 shp->shm_file = file;
84605@@ -607,18 +623,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
84606 return 0;
84607 }
84608
84609+static struct ipc_ops shm_ops = {
84610+ .getnew = newseg,
84611+ .associate = shm_security,
84612+ .more_checks = shm_more_checks
84613+};
84614+
84615 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
84616 {
84617 struct ipc_namespace *ns;
84618- struct ipc_ops shm_ops;
84619 struct ipc_params shm_params;
84620
84621 ns = current->nsproxy->ipc_ns;
84622
84623- shm_ops.getnew = newseg;
84624- shm_ops.associate = shm_security;
84625- shm_ops.more_checks = shm_more_checks;
84626-
84627 shm_params.key = key;
84628 shm_params.flg = shmflg;
84629 shm_params.u.size = size;
84630@@ -1089,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84631 f_mode = FMODE_READ | FMODE_WRITE;
84632 }
84633 if (shmflg & SHM_EXEC) {
84634+
84635+#ifdef CONFIG_PAX_MPROTECT
84636+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
84637+ goto out;
84638+#endif
84639+
84640 prot |= PROT_EXEC;
84641 acc_mode |= S_IXUGO;
84642 }
84643@@ -1113,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84644 if (err)
84645 goto out_unlock;
84646
84647+#ifdef CONFIG_GRKERNSEC
84648+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
84649+ shp->shm_perm.cuid, shmid) ||
84650+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
84651+ err = -EACCES;
84652+ goto out_unlock;
84653+ }
84654+#endif
84655+
84656 ipc_lock_object(&shp->shm_perm);
84657
84658 /* check if shm_destroy() is tearing down shp */
84659@@ -1125,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84660 path = shp->shm_file->f_path;
84661 path_get(&path);
84662 shp->shm_nattch++;
84663+#ifdef CONFIG_GRKERNSEC
84664+ shp->shm_lapid = current->pid;
84665+#endif
84666 size = i_size_read(path.dentry->d_inode);
84667 ipc_unlock_object(&shp->shm_perm);
84668 rcu_read_unlock();
84669diff --git a/ipc/util.c b/ipc/util.c
84670index 3ae17a4..d67c32f 100644
84671--- a/ipc/util.c
84672+++ b/ipc/util.c
84673@@ -71,6 +71,8 @@ struct ipc_proc_iface {
84674 int (*show)(struct seq_file *, void *);
84675 };
84676
84677+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
84678+
84679 static void ipc_memory_notifier(struct work_struct *work)
84680 {
84681 ipcns_notify(IPCNS_MEMCHANGED);
84682@@ -558,6 +560,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
84683 granted_mode >>= 6;
84684 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
84685 granted_mode >>= 3;
84686+
84687+ if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
84688+ return -1;
84689+
84690 /* is there some bit set in requested_mode but not in granted_mode? */
84691 if ((requested_mode & ~granted_mode & 0007) &&
84692 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
84693diff --git a/kernel/acct.c b/kernel/acct.c
84694index 8d6e145..33e0b1e 100644
84695--- a/kernel/acct.c
84696+++ b/kernel/acct.c
84697@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
84698 */
84699 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
84700 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
84701- file->f_op->write(file, (char *)&ac,
84702+ file->f_op->write(file, (char __force_user *)&ac,
84703 sizeof(acct_t), &file->f_pos);
84704 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
84705 set_fs(fs);
84706diff --git a/kernel/audit.c b/kernel/audit.c
84707index 15ec13a..986322e 100644
84708--- a/kernel/audit.c
84709+++ b/kernel/audit.c
84710@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
84711 3) suppressed due to audit_rate_limit
84712 4) suppressed due to audit_backlog_limit
84713 */
84714-static atomic_t audit_lost = ATOMIC_INIT(0);
84715+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
84716
84717 /* The netlink socket. */
84718 static struct sock *audit_sock;
84719@@ -251,7 +251,7 @@ void audit_log_lost(const char *message)
84720 unsigned long now;
84721 int print;
84722
84723- atomic_inc(&audit_lost);
84724+ atomic_inc_unchecked(&audit_lost);
84725
84726 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
84727
84728@@ -270,7 +270,7 @@ void audit_log_lost(const char *message)
84729 printk(KERN_WARNING
84730 "audit: audit_lost=%d audit_rate_limit=%d "
84731 "audit_backlog_limit=%d\n",
84732- atomic_read(&audit_lost),
84733+ atomic_read_unchecked(&audit_lost),
84734 audit_rate_limit,
84735 audit_backlog_limit);
84736 audit_panic(message);
84737@@ -766,7 +766,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
84738 status_set.pid = audit_pid;
84739 status_set.rate_limit = audit_rate_limit;
84740 status_set.backlog_limit = audit_backlog_limit;
84741- status_set.lost = atomic_read(&audit_lost);
84742+ status_set.lost = atomic_read_unchecked(&audit_lost);
84743 status_set.backlog = skb_queue_len(&audit_skb_queue);
84744 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
84745 &status_set, sizeof(status_set));
84746@@ -1359,7 +1359,7 @@ void audit_log_n_hex(struct audit_buffer *ab, const unsigned char *buf,
84747 int i, avail, new_len;
84748 unsigned char *ptr;
84749 struct sk_buff *skb;
84750- static const unsigned char *hex = "0123456789ABCDEF";
84751+ static const unsigned char hex[] = "0123456789ABCDEF";
84752
84753 if (!ab)
84754 return;
84755diff --git a/kernel/auditsc.c b/kernel/auditsc.c
84756index ff32843..27fc708 100644
84757--- a/kernel/auditsc.c
84758+++ b/kernel/auditsc.c
84759@@ -1945,7 +1945,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
84760 }
84761
84762 /* global counter which is incremented every time something logs in */
84763-static atomic_t session_id = ATOMIC_INIT(0);
84764+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
84765
84766 static int audit_set_loginuid_perm(kuid_t loginuid)
84767 {
84768@@ -2011,7 +2011,7 @@ int audit_set_loginuid(kuid_t loginuid)
84769
84770 /* are we setting or clearing? */
84771 if (uid_valid(loginuid))
84772- sessionid = atomic_inc_return(&session_id);
84773+ sessionid = atomic_inc_return_unchecked(&session_id);
84774
84775 task->sessionid = sessionid;
84776 task->loginuid = loginuid;
84777diff --git a/kernel/capability.c b/kernel/capability.c
84778index 4e66bf9..cdccecf 100644
84779--- a/kernel/capability.c
84780+++ b/kernel/capability.c
84781@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
84782 * before modification is attempted and the application
84783 * fails.
84784 */
84785+ if (tocopy > ARRAY_SIZE(kdata))
84786+ return -EFAULT;
84787+
84788 if (copy_to_user(dataptr, kdata, tocopy
84789 * sizeof(struct __user_cap_data_struct))) {
84790 return -EFAULT;
84791@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
84792 int ret;
84793
84794 rcu_read_lock();
84795- ret = security_capable(__task_cred(t), ns, cap);
84796+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
84797+ gr_task_is_capable(t, __task_cred(t), cap);
84798 rcu_read_unlock();
84799
84800- return (ret == 0);
84801+ return ret;
84802 }
84803
84804 /**
84805@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
84806 int ret;
84807
84808 rcu_read_lock();
84809- ret = security_capable_noaudit(__task_cred(t), ns, cap);
84810+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
84811 rcu_read_unlock();
84812
84813- return (ret == 0);
84814+ return ret;
84815 }
84816
84817 /**
84818@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
84819 BUG();
84820 }
84821
84822- if (security_capable(current_cred(), ns, cap) == 0) {
84823+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
84824 current->flags |= PF_SUPERPRIV;
84825 return true;
84826 }
84827@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
84828 }
84829 EXPORT_SYMBOL(ns_capable);
84830
84831+bool ns_capable_nolog(struct user_namespace *ns, int cap)
84832+{
84833+ if (unlikely(!cap_valid(cap))) {
84834+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
84835+ BUG();
84836+ }
84837+
84838+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
84839+ current->flags |= PF_SUPERPRIV;
84840+ return true;
84841+ }
84842+ return false;
84843+}
84844+EXPORT_SYMBOL(ns_capable_nolog);
84845+
84846 /**
84847 * file_ns_capable - Determine if the file's opener had a capability in effect
84848 * @file: The file we want to check
84849@@ -432,6 +451,12 @@ bool capable(int cap)
84850 }
84851 EXPORT_SYMBOL(capable);
84852
84853+bool capable_nolog(int cap)
84854+{
84855+ return ns_capable_nolog(&init_user_ns, cap);
84856+}
84857+EXPORT_SYMBOL(capable_nolog);
84858+
84859 /**
84860 * inode_capable - Check superior capability over inode
84861 * @inode: The inode in question
84862@@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
84863 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
84864 }
84865 EXPORT_SYMBOL(inode_capable);
84866+
84867+bool inode_capable_nolog(const struct inode *inode, int cap)
84868+{
84869+ struct user_namespace *ns = current_user_ns();
84870+
84871+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
84872+}
84873+EXPORT_SYMBOL(inode_capable_nolog);
84874diff --git a/kernel/cgroup.c b/kernel/cgroup.c
84875index b44dd49..94c2826 100644
84876--- a/kernel/cgroup.c
84877+++ b/kernel/cgroup.c
84878@@ -5609,7 +5609,7 @@ static int cgroup_css_links_read(struct cgroup_subsys_state *css,
84879 struct css_set *cset = link->cset;
84880 struct task_struct *task;
84881 int count = 0;
84882- seq_printf(seq, "css_set %p\n", cset);
84883+ seq_printf(seq, "css_set %pK\n", cset);
84884 list_for_each_entry(task, &cset->tasks, cg_list) {
84885 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
84886 seq_puts(seq, " ...\n");
84887diff --git a/kernel/compat.c b/kernel/compat.c
84888index 0a09e48..b46b3d78 100644
84889--- a/kernel/compat.c
84890+++ b/kernel/compat.c
84891@@ -13,6 +13,7 @@
84892
84893 #include <linux/linkage.h>
84894 #include <linux/compat.h>
84895+#include <linux/module.h>
84896 #include <linux/errno.h>
84897 #include <linux/time.h>
84898 #include <linux/signal.h>
84899@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
84900 mm_segment_t oldfs;
84901 long ret;
84902
84903- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
84904+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
84905 oldfs = get_fs();
84906 set_fs(KERNEL_DS);
84907 ret = hrtimer_nanosleep_restart(restart);
84908@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
84909 oldfs = get_fs();
84910 set_fs(KERNEL_DS);
84911 ret = hrtimer_nanosleep(&tu,
84912- rmtp ? (struct timespec __user *)&rmt : NULL,
84913+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
84914 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
84915 set_fs(oldfs);
84916
84917@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
84918 mm_segment_t old_fs = get_fs();
84919
84920 set_fs(KERNEL_DS);
84921- ret = sys_sigpending((old_sigset_t __user *) &s);
84922+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
84923 set_fs(old_fs);
84924 if (ret == 0)
84925 ret = put_user(s, set);
84926@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
84927 mm_segment_t old_fs = get_fs();
84928
84929 set_fs(KERNEL_DS);
84930- ret = sys_old_getrlimit(resource, &r);
84931+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
84932 set_fs(old_fs);
84933
84934 if (!ret) {
84935@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
84936 set_fs (KERNEL_DS);
84937 ret = sys_wait4(pid,
84938 (stat_addr ?
84939- (unsigned int __user *) &status : NULL),
84940- options, (struct rusage __user *) &r);
84941+ (unsigned int __force_user *) &status : NULL),
84942+ options, (struct rusage __force_user *) &r);
84943 set_fs (old_fs);
84944
84945 if (ret > 0) {
84946@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
84947 memset(&info, 0, sizeof(info));
84948
84949 set_fs(KERNEL_DS);
84950- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
84951- uru ? (struct rusage __user *)&ru : NULL);
84952+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
84953+ uru ? (struct rusage __force_user *)&ru : NULL);
84954 set_fs(old_fs);
84955
84956 if ((ret < 0) || (info.si_signo == 0))
84957@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
84958 oldfs = get_fs();
84959 set_fs(KERNEL_DS);
84960 err = sys_timer_settime(timer_id, flags,
84961- (struct itimerspec __user *) &newts,
84962- (struct itimerspec __user *) &oldts);
84963+ (struct itimerspec __force_user *) &newts,
84964+ (struct itimerspec __force_user *) &oldts);
84965 set_fs(oldfs);
84966 if (!err && old && put_compat_itimerspec(old, &oldts))
84967 return -EFAULT;
84968@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
84969 oldfs = get_fs();
84970 set_fs(KERNEL_DS);
84971 err = sys_timer_gettime(timer_id,
84972- (struct itimerspec __user *) &ts);
84973+ (struct itimerspec __force_user *) &ts);
84974 set_fs(oldfs);
84975 if (!err && put_compat_itimerspec(setting, &ts))
84976 return -EFAULT;
84977@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
84978 oldfs = get_fs();
84979 set_fs(KERNEL_DS);
84980 err = sys_clock_settime(which_clock,
84981- (struct timespec __user *) &ts);
84982+ (struct timespec __force_user *) &ts);
84983 set_fs(oldfs);
84984 return err;
84985 }
84986@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
84987 oldfs = get_fs();
84988 set_fs(KERNEL_DS);
84989 err = sys_clock_gettime(which_clock,
84990- (struct timespec __user *) &ts);
84991+ (struct timespec __force_user *) &ts);
84992 set_fs(oldfs);
84993 if (!err && put_compat_timespec(&ts, tp))
84994 return -EFAULT;
84995@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
84996
84997 oldfs = get_fs();
84998 set_fs(KERNEL_DS);
84999- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
85000+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
85001 set_fs(oldfs);
85002
85003 err = compat_put_timex(utp, &txc);
85004@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
85005 oldfs = get_fs();
85006 set_fs(KERNEL_DS);
85007 err = sys_clock_getres(which_clock,
85008- (struct timespec __user *) &ts);
85009+ (struct timespec __force_user *) &ts);
85010 set_fs(oldfs);
85011 if (!err && tp && put_compat_timespec(&ts, tp))
85012 return -EFAULT;
85013@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
85014 long err;
85015 mm_segment_t oldfs;
85016 struct timespec tu;
85017- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
85018+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
85019
85020- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
85021+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
85022 oldfs = get_fs();
85023 set_fs(KERNEL_DS);
85024 err = clock_nanosleep_restart(restart);
85025@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
85026 oldfs = get_fs();
85027 set_fs(KERNEL_DS);
85028 err = sys_clock_nanosleep(which_clock, flags,
85029- (struct timespec __user *) &in,
85030- (struct timespec __user *) &out);
85031+ (struct timespec __force_user *) &in,
85032+ (struct timespec __force_user *) &out);
85033 set_fs(oldfs);
85034
85035 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
85036@@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
85037 mm_segment_t old_fs = get_fs();
85038
85039 set_fs(KERNEL_DS);
85040- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
85041+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
85042 set_fs(old_fs);
85043 if (put_compat_timespec(&t, interval))
85044 return -EFAULT;
85045diff --git a/kernel/configs.c b/kernel/configs.c
85046index c18b1f1..b9a0132 100644
85047--- a/kernel/configs.c
85048+++ b/kernel/configs.c
85049@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
85050 struct proc_dir_entry *entry;
85051
85052 /* create the current config file */
85053+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
85054+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
85055+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
85056+ &ikconfig_file_ops);
85057+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
85058+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
85059+ &ikconfig_file_ops);
85060+#endif
85061+#else
85062 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
85063 &ikconfig_file_ops);
85064+#endif
85065+
85066 if (!entry)
85067 return -ENOMEM;
85068
85069diff --git a/kernel/cred.c b/kernel/cred.c
85070index e0573a4..3874e41 100644
85071--- a/kernel/cred.c
85072+++ b/kernel/cred.c
85073@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
85074 validate_creds(cred);
85075 alter_cred_subscribers(cred, -1);
85076 put_cred(cred);
85077+
85078+#ifdef CONFIG_GRKERNSEC_SETXID
85079+ cred = (struct cred *) tsk->delayed_cred;
85080+ if (cred != NULL) {
85081+ tsk->delayed_cred = NULL;
85082+ validate_creds(cred);
85083+ alter_cred_subscribers(cred, -1);
85084+ put_cred(cred);
85085+ }
85086+#endif
85087 }
85088
85089 /**
85090@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
85091 * Always returns 0 thus allowing this function to be tail-called at the end
85092 * of, say, sys_setgid().
85093 */
85094-int commit_creds(struct cred *new)
85095+static int __commit_creds(struct cred *new)
85096 {
85097 struct task_struct *task = current;
85098 const struct cred *old = task->real_cred;
85099@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
85100
85101 get_cred(new); /* we will require a ref for the subj creds too */
85102
85103+ gr_set_role_label(task, new->uid, new->gid);
85104+
85105 /* dumpability changes */
85106 if (!uid_eq(old->euid, new->euid) ||
85107 !gid_eq(old->egid, new->egid) ||
85108@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
85109 put_cred(old);
85110 return 0;
85111 }
85112+#ifdef CONFIG_GRKERNSEC_SETXID
85113+extern int set_user(struct cred *new);
85114+
85115+void gr_delayed_cred_worker(void)
85116+{
85117+ const struct cred *new = current->delayed_cred;
85118+ struct cred *ncred;
85119+
85120+ current->delayed_cred = NULL;
85121+
85122+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
85123+ // from doing get_cred on it when queueing this
85124+ put_cred(new);
85125+ return;
85126+ } else if (new == NULL)
85127+ return;
85128+
85129+ ncred = prepare_creds();
85130+ if (!ncred)
85131+ goto die;
85132+ // uids
85133+ ncred->uid = new->uid;
85134+ ncred->euid = new->euid;
85135+ ncred->suid = new->suid;
85136+ ncred->fsuid = new->fsuid;
85137+ // gids
85138+ ncred->gid = new->gid;
85139+ ncred->egid = new->egid;
85140+ ncred->sgid = new->sgid;
85141+ ncred->fsgid = new->fsgid;
85142+ // groups
85143+ if (set_groups(ncred, new->group_info) < 0) {
85144+ abort_creds(ncred);
85145+ goto die;
85146+ }
85147+ // caps
85148+ ncred->securebits = new->securebits;
85149+ ncred->cap_inheritable = new->cap_inheritable;
85150+ ncred->cap_permitted = new->cap_permitted;
85151+ ncred->cap_effective = new->cap_effective;
85152+ ncred->cap_bset = new->cap_bset;
85153+
85154+ if (set_user(ncred)) {
85155+ abort_creds(ncred);
85156+ goto die;
85157+ }
85158+
85159+ // from doing get_cred on it when queueing this
85160+ put_cred(new);
85161+
85162+ __commit_creds(ncred);
85163+ return;
85164+die:
85165+ // from doing get_cred on it when queueing this
85166+ put_cred(new);
85167+ do_group_exit(SIGKILL);
85168+}
85169+#endif
85170+
85171+int commit_creds(struct cred *new)
85172+{
85173+#ifdef CONFIG_GRKERNSEC_SETXID
85174+ int ret;
85175+ int schedule_it = 0;
85176+ struct task_struct *t;
85177+
85178+ /* we won't get called with tasklist_lock held for writing
85179+ and interrupts disabled as the cred struct in that case is
85180+ init_cred
85181+ */
85182+ if (grsec_enable_setxid && !current_is_single_threaded() &&
85183+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
85184+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
85185+ schedule_it = 1;
85186+ }
85187+ ret = __commit_creds(new);
85188+ if (schedule_it) {
85189+ rcu_read_lock();
85190+ read_lock(&tasklist_lock);
85191+ for (t = next_thread(current); t != current;
85192+ t = next_thread(t)) {
85193+ if (t->delayed_cred == NULL) {
85194+ t->delayed_cred = get_cred(new);
85195+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
85196+ set_tsk_need_resched(t);
85197+ }
85198+ }
85199+ read_unlock(&tasklist_lock);
85200+ rcu_read_unlock();
85201+ }
85202+ return ret;
85203+#else
85204+ return __commit_creds(new);
85205+#endif
85206+}
85207+
85208 EXPORT_SYMBOL(commit_creds);
85209
85210 /**
85211diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
85212index 7d2f35e..1bafcd0 100644
85213--- a/kernel/debug/debug_core.c
85214+++ b/kernel/debug/debug_core.c
85215@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
85216 */
85217 static atomic_t masters_in_kgdb;
85218 static atomic_t slaves_in_kgdb;
85219-static atomic_t kgdb_break_tasklet_var;
85220+static atomic_unchecked_t kgdb_break_tasklet_var;
85221 atomic_t kgdb_setting_breakpoint;
85222
85223 struct task_struct *kgdb_usethread;
85224@@ -133,7 +133,7 @@ int kgdb_single_step;
85225 static pid_t kgdb_sstep_pid;
85226
85227 /* to keep track of the CPU which is doing the single stepping*/
85228-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85229+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85230
85231 /*
85232 * If you are debugging a problem where roundup (the collection of
85233@@ -541,7 +541,7 @@ return_normal:
85234 * kernel will only try for the value of sstep_tries before
85235 * giving up and continuing on.
85236 */
85237- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
85238+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
85239 (kgdb_info[cpu].task &&
85240 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
85241 atomic_set(&kgdb_active, -1);
85242@@ -639,8 +639,8 @@ cpu_master_loop:
85243 }
85244
85245 kgdb_restore:
85246- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
85247- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
85248+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
85249+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
85250 if (kgdb_info[sstep_cpu].task)
85251 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
85252 else
85253@@ -916,18 +916,18 @@ static void kgdb_unregister_callbacks(void)
85254 static void kgdb_tasklet_bpt(unsigned long ing)
85255 {
85256 kgdb_breakpoint();
85257- atomic_set(&kgdb_break_tasklet_var, 0);
85258+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
85259 }
85260
85261 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
85262
85263 void kgdb_schedule_breakpoint(void)
85264 {
85265- if (atomic_read(&kgdb_break_tasklet_var) ||
85266+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
85267 atomic_read(&kgdb_active) != -1 ||
85268 atomic_read(&kgdb_setting_breakpoint))
85269 return;
85270- atomic_inc(&kgdb_break_tasklet_var);
85271+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
85272 tasklet_schedule(&kgdb_tasklet_breakpoint);
85273 }
85274 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
85275diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
85276index 0b097c8..11dd5c5 100644
85277--- a/kernel/debug/kdb/kdb_main.c
85278+++ b/kernel/debug/kdb/kdb_main.c
85279@@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
85280 continue;
85281
85282 kdb_printf("%-20s%8u 0x%p ", mod->name,
85283- mod->core_size, (void *)mod);
85284+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
85285 #ifdef CONFIG_MODULE_UNLOAD
85286 kdb_printf("%4ld ", module_refcount(mod));
85287 #endif
85288@@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
85289 kdb_printf(" (Loading)");
85290 else
85291 kdb_printf(" (Live)");
85292- kdb_printf(" 0x%p", mod->module_core);
85293+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
85294
85295 #ifdef CONFIG_MODULE_UNLOAD
85296 {
85297diff --git a/kernel/events/core.c b/kernel/events/core.c
85298index 6ed1163..f36346e 100644
85299--- a/kernel/events/core.c
85300+++ b/kernel/events/core.c
85301@@ -157,8 +157,15 @@ static struct srcu_struct pmus_srcu;
85302 * 0 - disallow raw tracepoint access for unpriv
85303 * 1 - disallow cpu events for unpriv
85304 * 2 - disallow kernel profiling for unpriv
85305+ * 3 - disallow all unpriv perf event use
85306 */
85307-int sysctl_perf_event_paranoid __read_mostly = 1;
85308+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85309+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
85310+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
85311+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
85312+#else
85313+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
85314+#endif
85315
85316 /* Minimum for 512 kiB + 1 user control page */
85317 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
85318@@ -184,7 +191,7 @@ void update_perf_cpu_limits(void)
85319
85320 tmp *= sysctl_perf_cpu_time_max_percent;
85321 do_div(tmp, 100);
85322- ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
85323+ ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
85324 }
85325
85326 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
85327@@ -271,7 +278,7 @@ void perf_sample_event_took(u64 sample_len_ns)
85328 update_perf_cpu_limits();
85329 }
85330
85331-static atomic64_t perf_event_id;
85332+static atomic64_unchecked_t perf_event_id;
85333
85334 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
85335 enum event_type_t event_type);
85336@@ -2985,7 +2992,7 @@ static void __perf_event_read(void *info)
85337
85338 static inline u64 perf_event_count(struct perf_event *event)
85339 {
85340- return local64_read(&event->count) + atomic64_read(&event->child_count);
85341+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
85342 }
85343
85344 static u64 perf_event_read(struct perf_event *event)
85345@@ -3353,9 +3360,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
85346 mutex_lock(&event->child_mutex);
85347 total += perf_event_read(event);
85348 *enabled += event->total_time_enabled +
85349- atomic64_read(&event->child_total_time_enabled);
85350+ atomic64_read_unchecked(&event->child_total_time_enabled);
85351 *running += event->total_time_running +
85352- atomic64_read(&event->child_total_time_running);
85353+ atomic64_read_unchecked(&event->child_total_time_running);
85354
85355 list_for_each_entry(child, &event->child_list, child_list) {
85356 total += perf_event_read(child);
85357@@ -3770,10 +3777,10 @@ void perf_event_update_userpage(struct perf_event *event)
85358 userpg->offset -= local64_read(&event->hw.prev_count);
85359
85360 userpg->time_enabled = enabled +
85361- atomic64_read(&event->child_total_time_enabled);
85362+ atomic64_read_unchecked(&event->child_total_time_enabled);
85363
85364 userpg->time_running = running +
85365- atomic64_read(&event->child_total_time_running);
85366+ atomic64_read_unchecked(&event->child_total_time_running);
85367
85368 arch_perf_update_userpage(userpg, now);
85369
85370@@ -4324,7 +4331,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
85371
85372 /* Data. */
85373 sp = perf_user_stack_pointer(regs);
85374- rem = __output_copy_user(handle, (void *) sp, dump_size);
85375+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
85376 dyn_size = dump_size - rem;
85377
85378 perf_output_skip(handle, rem);
85379@@ -4415,11 +4422,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
85380 values[n++] = perf_event_count(event);
85381 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
85382 values[n++] = enabled +
85383- atomic64_read(&event->child_total_time_enabled);
85384+ atomic64_read_unchecked(&event->child_total_time_enabled);
85385 }
85386 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
85387 values[n++] = running +
85388- atomic64_read(&event->child_total_time_running);
85389+ atomic64_read_unchecked(&event->child_total_time_running);
85390 }
85391 if (read_format & PERF_FORMAT_ID)
85392 values[n++] = primary_event_id(event);
85393@@ -6686,7 +6693,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
85394 event->parent = parent_event;
85395
85396 event->ns = get_pid_ns(task_active_pid_ns(current));
85397- event->id = atomic64_inc_return(&perf_event_id);
85398+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
85399
85400 event->state = PERF_EVENT_STATE_INACTIVE;
85401
85402@@ -6985,6 +6992,11 @@ SYSCALL_DEFINE5(perf_event_open,
85403 if (flags & ~PERF_FLAG_ALL)
85404 return -EINVAL;
85405
85406+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85407+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
85408+ return -EACCES;
85409+#endif
85410+
85411 err = perf_copy_attr(attr_uptr, &attr);
85412 if (err)
85413 return err;
85414@@ -7316,10 +7328,10 @@ static void sync_child_event(struct perf_event *child_event,
85415 /*
85416 * Add back the child's count to the parent's count:
85417 */
85418- atomic64_add(child_val, &parent_event->child_count);
85419- atomic64_add(child_event->total_time_enabled,
85420+ atomic64_add_unchecked(child_val, &parent_event->child_count);
85421+ atomic64_add_unchecked(child_event->total_time_enabled,
85422 &parent_event->child_total_time_enabled);
85423- atomic64_add(child_event->total_time_running,
85424+ atomic64_add_unchecked(child_event->total_time_running,
85425 &parent_event->child_total_time_running);
85426
85427 /*
85428diff --git a/kernel/events/internal.h b/kernel/events/internal.h
85429index 569b2187..19940d9 100644
85430--- a/kernel/events/internal.h
85431+++ b/kernel/events/internal.h
85432@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
85433 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
85434 }
85435
85436-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
85437+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
85438 static inline unsigned long \
85439 func_name(struct perf_output_handle *handle, \
85440- const void *buf, unsigned long len) \
85441+ const void user *buf, unsigned long len) \
85442 { \
85443 unsigned long size, written; \
85444 \
85445@@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
85446 return 0;
85447 }
85448
85449-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
85450+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
85451
85452 static inline unsigned long
85453 memcpy_skip(void *dst, const void *src, unsigned long n)
85454@@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
85455 return 0;
85456 }
85457
85458-DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
85459+DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
85460
85461 #ifndef arch_perf_out_copy_user
85462 #define arch_perf_out_copy_user arch_perf_out_copy_user
85463@@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
85464 }
85465 #endif
85466
85467-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
85468+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
85469
85470 /* Callchain handling */
85471 extern struct perf_callchain_entry *
85472diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
85473index 24b7d6c..40cf797 100644
85474--- a/kernel/events/uprobes.c
85475+++ b/kernel/events/uprobes.c
85476@@ -1640,7 +1640,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
85477 {
85478 struct page *page;
85479 uprobe_opcode_t opcode;
85480- int result;
85481+ long result;
85482
85483 pagefault_disable();
85484 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
85485diff --git a/kernel/exit.c b/kernel/exit.c
85486index a949819..a5f127d 100644
85487--- a/kernel/exit.c
85488+++ b/kernel/exit.c
85489@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
85490 struct task_struct *leader;
85491 int zap_leader;
85492 repeat:
85493+#ifdef CONFIG_NET
85494+ gr_del_task_from_ip_table(p);
85495+#endif
85496+
85497 /* don't need to get the RCU readlock here - the process is dead and
85498 * can't be modifying its own credentials. But shut RCU-lockdep up */
85499 rcu_read_lock();
85500@@ -329,7 +333,7 @@ int allow_signal(int sig)
85501 * know it'll be handled, so that they don't get converted to
85502 * SIGKILL or just silently dropped.
85503 */
85504- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
85505+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
85506 recalc_sigpending();
85507 spin_unlock_irq(&current->sighand->siglock);
85508 return 0;
85509@@ -698,6 +702,8 @@ void do_exit(long code)
85510 struct task_struct *tsk = current;
85511 int group_dead;
85512
85513+ set_fs(USER_DS);
85514+
85515 profile_task_exit(tsk);
85516
85517 WARN_ON(blk_needs_flush_plug(tsk));
85518@@ -714,7 +720,6 @@ void do_exit(long code)
85519 * mm_release()->clear_child_tid() from writing to a user-controlled
85520 * kernel address.
85521 */
85522- set_fs(USER_DS);
85523
85524 ptrace_event(PTRACE_EVENT_EXIT, code);
85525
85526@@ -773,6 +778,9 @@ void do_exit(long code)
85527 tsk->exit_code = code;
85528 taskstats_exit(tsk, group_dead);
85529
85530+ gr_acl_handle_psacct(tsk, code);
85531+ gr_acl_handle_exit();
85532+
85533 exit_mm(tsk);
85534
85535 if (group_dead)
85536@@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
85537 * Take down every thread in the group. This is called by fatal signals
85538 * as well as by sys_exit_group (below).
85539 */
85540-void
85541+__noreturn void
85542 do_group_exit(int exit_code)
85543 {
85544 struct signal_struct *sig = current->signal;
85545diff --git a/kernel/fork.c b/kernel/fork.c
85546index dfa736c..d170f9b 100644
85547--- a/kernel/fork.c
85548+++ b/kernel/fork.c
85549@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
85550 *stackend = STACK_END_MAGIC; /* for overflow detection */
85551
85552 #ifdef CONFIG_CC_STACKPROTECTOR
85553- tsk->stack_canary = get_random_int();
85554+ tsk->stack_canary = pax_get_random_long();
85555 #endif
85556
85557 /*
85558@@ -345,12 +345,80 @@ free_tsk:
85559 }
85560
85561 #ifdef CONFIG_MMU
85562-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85563+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
85564+{
85565+ struct vm_area_struct *tmp;
85566+ unsigned long charge;
85567+ struct file *file;
85568+ int retval;
85569+
85570+ charge = 0;
85571+ if (mpnt->vm_flags & VM_ACCOUNT) {
85572+ unsigned long len = vma_pages(mpnt);
85573+
85574+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
85575+ goto fail_nomem;
85576+ charge = len;
85577+ }
85578+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
85579+ if (!tmp)
85580+ goto fail_nomem;
85581+ *tmp = *mpnt;
85582+ tmp->vm_mm = mm;
85583+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
85584+ retval = vma_dup_policy(mpnt, tmp);
85585+ if (retval)
85586+ goto fail_nomem_policy;
85587+ if (anon_vma_fork(tmp, mpnt))
85588+ goto fail_nomem_anon_vma_fork;
85589+ tmp->vm_flags &= ~VM_LOCKED;
85590+ tmp->vm_next = tmp->vm_prev = NULL;
85591+ tmp->vm_mirror = NULL;
85592+ file = tmp->vm_file;
85593+ if (file) {
85594+ struct inode *inode = file_inode(file);
85595+ struct address_space *mapping = file->f_mapping;
85596+
85597+ get_file(file);
85598+ if (tmp->vm_flags & VM_DENYWRITE)
85599+ atomic_dec(&inode->i_writecount);
85600+ mutex_lock(&mapping->i_mmap_mutex);
85601+ if (tmp->vm_flags & VM_SHARED)
85602+ mapping->i_mmap_writable++;
85603+ flush_dcache_mmap_lock(mapping);
85604+ /* insert tmp into the share list, just after mpnt */
85605+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
85606+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
85607+ else
85608+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
85609+ flush_dcache_mmap_unlock(mapping);
85610+ mutex_unlock(&mapping->i_mmap_mutex);
85611+ }
85612+
85613+ /*
85614+ * Clear hugetlb-related page reserves for children. This only
85615+ * affects MAP_PRIVATE mappings. Faults generated by the child
85616+ * are not guaranteed to succeed, even if read-only
85617+ */
85618+ if (is_vm_hugetlb_page(tmp))
85619+ reset_vma_resv_huge_pages(tmp);
85620+
85621+ return tmp;
85622+
85623+fail_nomem_anon_vma_fork:
85624+ mpol_put(vma_policy(tmp));
85625+fail_nomem_policy:
85626+ kmem_cache_free(vm_area_cachep, tmp);
85627+fail_nomem:
85628+ vm_unacct_memory(charge);
85629+ return NULL;
85630+}
85631+
85632+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85633 {
85634 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
85635 struct rb_node **rb_link, *rb_parent;
85636 int retval;
85637- unsigned long charge;
85638
85639 uprobe_start_dup_mmap();
85640 down_write(&oldmm->mmap_sem);
85641@@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85642
85643 prev = NULL;
85644 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
85645- struct file *file;
85646-
85647 if (mpnt->vm_flags & VM_DONTCOPY) {
85648 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
85649 -vma_pages(mpnt));
85650 continue;
85651 }
85652- charge = 0;
85653- if (mpnt->vm_flags & VM_ACCOUNT) {
85654- unsigned long len = vma_pages(mpnt);
85655-
85656- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
85657- goto fail_nomem;
85658- charge = len;
85659- }
85660- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
85661- if (!tmp)
85662- goto fail_nomem;
85663- *tmp = *mpnt;
85664- INIT_LIST_HEAD(&tmp->anon_vma_chain);
85665- retval = vma_dup_policy(mpnt, tmp);
85666- if (retval)
85667- goto fail_nomem_policy;
85668- tmp->vm_mm = mm;
85669- if (anon_vma_fork(tmp, mpnt))
85670- goto fail_nomem_anon_vma_fork;
85671- tmp->vm_flags &= ~VM_LOCKED;
85672- tmp->vm_next = tmp->vm_prev = NULL;
85673- file = tmp->vm_file;
85674- if (file) {
85675- struct inode *inode = file_inode(file);
85676- struct address_space *mapping = file->f_mapping;
85677-
85678- get_file(file);
85679- if (tmp->vm_flags & VM_DENYWRITE)
85680- atomic_dec(&inode->i_writecount);
85681- mutex_lock(&mapping->i_mmap_mutex);
85682- if (tmp->vm_flags & VM_SHARED)
85683- mapping->i_mmap_writable++;
85684- flush_dcache_mmap_lock(mapping);
85685- /* insert tmp into the share list, just after mpnt */
85686- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
85687- vma_nonlinear_insert(tmp,
85688- &mapping->i_mmap_nonlinear);
85689- else
85690- vma_interval_tree_insert_after(tmp, mpnt,
85691- &mapping->i_mmap);
85692- flush_dcache_mmap_unlock(mapping);
85693- mutex_unlock(&mapping->i_mmap_mutex);
85694+ tmp = dup_vma(mm, oldmm, mpnt);
85695+ if (!tmp) {
85696+ retval = -ENOMEM;
85697+ goto out;
85698 }
85699
85700 /*
85701@@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85702 if (retval)
85703 goto out;
85704 }
85705+
85706+#ifdef CONFIG_PAX_SEGMEXEC
85707+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
85708+ struct vm_area_struct *mpnt_m;
85709+
85710+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
85711+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
85712+
85713+ if (!mpnt->vm_mirror)
85714+ continue;
85715+
85716+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
85717+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
85718+ mpnt->vm_mirror = mpnt_m;
85719+ } else {
85720+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
85721+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
85722+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
85723+ mpnt->vm_mirror->vm_mirror = mpnt;
85724+ }
85725+ }
85726+ BUG_ON(mpnt_m);
85727+ }
85728+#endif
85729+
85730 /* a new mm has just been created */
85731 arch_dup_mmap(oldmm, mm);
85732 retval = 0;
85733@@ -468,14 +521,6 @@ out:
85734 up_write(&oldmm->mmap_sem);
85735 uprobe_end_dup_mmap();
85736 return retval;
85737-fail_nomem_anon_vma_fork:
85738- mpol_put(vma_policy(tmp));
85739-fail_nomem_policy:
85740- kmem_cache_free(vm_area_cachep, tmp);
85741-fail_nomem:
85742- retval = -ENOMEM;
85743- vm_unacct_memory(charge);
85744- goto out;
85745 }
85746
85747 static inline int mm_alloc_pgd(struct mm_struct *mm)
85748@@ -689,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
85749 return ERR_PTR(err);
85750
85751 mm = get_task_mm(task);
85752- if (mm && mm != current->mm &&
85753- !ptrace_may_access(task, mode)) {
85754+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
85755+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
85756 mmput(mm);
85757 mm = ERR_PTR(-EACCES);
85758 }
85759@@ -909,13 +954,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
85760 spin_unlock(&fs->lock);
85761 return -EAGAIN;
85762 }
85763- fs->users++;
85764+ atomic_inc(&fs->users);
85765 spin_unlock(&fs->lock);
85766 return 0;
85767 }
85768 tsk->fs = copy_fs_struct(fs);
85769 if (!tsk->fs)
85770 return -ENOMEM;
85771+ /* Carry through gr_chroot_dentry and is_chrooted instead
85772+ of recomputing it here. Already copied when the task struct
85773+ is duplicated. This allows pivot_root to not be treated as
85774+ a chroot
85775+ */
85776+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
85777+
85778 return 0;
85779 }
85780
85781@@ -1126,7 +1178,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
85782 * parts of the process environment (as per the clone
85783 * flags). The actual kick-off is left to the caller.
85784 */
85785-static struct task_struct *copy_process(unsigned long clone_flags,
85786+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
85787 unsigned long stack_start,
85788 unsigned long stack_size,
85789 int __user *child_tidptr,
85790@@ -1198,6 +1250,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
85791 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
85792 #endif
85793 retval = -EAGAIN;
85794+
85795+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
85796+
85797 if (atomic_read(&p->real_cred->user->processes) >=
85798 task_rlimit(p, RLIMIT_NPROC)) {
85799 if (p->real_cred->user != INIT_USER &&
85800@@ -1446,6 +1501,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
85801 goto bad_fork_free_pid;
85802 }
85803
85804+ /* synchronizes with gr_set_acls()
85805+ we need to call this past the point of no return for fork()
85806+ */
85807+ gr_copy_label(p);
85808+
85809 if (likely(p->pid)) {
85810 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
85811
85812@@ -1532,6 +1592,8 @@ bad_fork_cleanup_count:
85813 bad_fork_free:
85814 free_task(p);
85815 fork_out:
85816+ gr_log_forkfail(retval);
85817+
85818 return ERR_PTR(retval);
85819 }
85820
85821@@ -1593,6 +1655,7 @@ long do_fork(unsigned long clone_flags,
85822
85823 p = copy_process(clone_flags, stack_start, stack_size,
85824 child_tidptr, NULL, trace);
85825+ add_latent_entropy();
85826 /*
85827 * Do this prior waking up the new thread - the thread pointer
85828 * might get invalid after that point, if the thread exits quickly.
85829@@ -1607,6 +1670,8 @@ long do_fork(unsigned long clone_flags,
85830 if (clone_flags & CLONE_PARENT_SETTID)
85831 put_user(nr, parent_tidptr);
85832
85833+ gr_handle_brute_check();
85834+
85835 if (clone_flags & CLONE_VFORK) {
85836 p->vfork_done = &vfork;
85837 init_completion(&vfork);
85838@@ -1723,7 +1788,7 @@ void __init proc_caches_init(void)
85839 mm_cachep = kmem_cache_create("mm_struct",
85840 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
85841 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
85842- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
85843+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
85844 mmap_init();
85845 nsproxy_cache_init();
85846 }
85847@@ -1763,7 +1828,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
85848 return 0;
85849
85850 /* don't need lock here; in the worst case we'll do useless copy */
85851- if (fs->users == 1)
85852+ if (atomic_read(&fs->users) == 1)
85853 return 0;
85854
85855 *new_fsp = copy_fs_struct(fs);
85856@@ -1870,7 +1935,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
85857 fs = current->fs;
85858 spin_lock(&fs->lock);
85859 current->fs = new_fs;
85860- if (--fs->users)
85861+ gr_set_chroot_entries(current, &current->fs->root);
85862+ if (atomic_dec_return(&fs->users))
85863 new_fs = NULL;
85864 else
85865 new_fs = fs;
85866diff --git a/kernel/futex.c b/kernel/futex.c
85867index f6ff019..ac53307 100644
85868--- a/kernel/futex.c
85869+++ b/kernel/futex.c
85870@@ -54,6 +54,7 @@
85871 #include <linux/mount.h>
85872 #include <linux/pagemap.h>
85873 #include <linux/syscalls.h>
85874+#include <linux/ptrace.h>
85875 #include <linux/signal.h>
85876 #include <linux/export.h>
85877 #include <linux/magic.h>
85878@@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
85879 struct page *page, *page_head;
85880 int err, ro = 0;
85881
85882+#ifdef CONFIG_PAX_SEGMEXEC
85883+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
85884+ return -EFAULT;
85885+#endif
85886+
85887 /*
85888 * The futex address must be "naturally" aligned.
85889 */
85890@@ -442,7 +448,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
85891
85892 static int get_futex_value_locked(u32 *dest, u32 __user *from)
85893 {
85894- int ret;
85895+ unsigned long ret;
85896
85897 pagefault_disable();
85898 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
85899@@ -2735,6 +2741,7 @@ static int __init futex_init(void)
85900 {
85901 u32 curval;
85902 int i;
85903+ mm_segment_t oldfs;
85904
85905 /*
85906 * This will fail and we want it. Some arch implementations do
85907@@ -2746,8 +2753,11 @@ static int __init futex_init(void)
85908 * implementation, the non-functional ones will return
85909 * -ENOSYS.
85910 */
85911+ oldfs = get_fs();
85912+ set_fs(USER_DS);
85913 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
85914 futex_cmpxchg_enabled = 1;
85915+ set_fs(oldfs);
85916
85917 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
85918 plist_head_init(&futex_queues[i].chain);
85919diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
85920index f9f44fd..29885e4 100644
85921--- a/kernel/futex_compat.c
85922+++ b/kernel/futex_compat.c
85923@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
85924 return 0;
85925 }
85926
85927-static void __user *futex_uaddr(struct robust_list __user *entry,
85928+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
85929 compat_long_t futex_offset)
85930 {
85931 compat_uptr_t base = ptr_to_compat(entry);
85932diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
85933index f45b75b..bfac6d5 100644
85934--- a/kernel/gcov/base.c
85935+++ b/kernel/gcov/base.c
85936@@ -108,11 +108,6 @@ void gcov_enable_events(void)
85937 }
85938
85939 #ifdef CONFIG_MODULES
85940-static inline int within(void *addr, void *start, unsigned long size)
85941-{
85942- return ((addr >= start) && (addr < start + size));
85943-}
85944-
85945 /* Update list and generate events when modules are unloaded. */
85946 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
85947 void *data)
85948@@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
85949
85950 /* Remove entries located in module from linked list. */
85951 while ((info = gcov_info_next(info))) {
85952- if (within(info, mod->module_core, mod->core_size)) {
85953+ if (within_module_core_rw((unsigned long)info, mod)) {
85954 gcov_info_unlink(prev, info);
85955 if (gcov_events_enabled)
85956 gcov_event(GCOV_REMOVE, info);
85957diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
85958index 383319b..56ebb13 100644
85959--- a/kernel/hrtimer.c
85960+++ b/kernel/hrtimer.c
85961@@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
85962 local_irq_restore(flags);
85963 }
85964
85965-static void run_hrtimer_softirq(struct softirq_action *h)
85966+static __latent_entropy void run_hrtimer_softirq(void)
85967 {
85968 hrtimer_peek_ahead_timers();
85969 }
85970diff --git a/kernel/irq_work.c b/kernel/irq_work.c
85971index 55fcce6..0e4cf34 100644
85972--- a/kernel/irq_work.c
85973+++ b/kernel/irq_work.c
85974@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
85975 return NOTIFY_OK;
85976 }
85977
85978-static struct notifier_block cpu_notify;
85979+static struct notifier_block cpu_notify = {
85980+ .notifier_call = irq_work_cpu_notify,
85981+ .priority = 0,
85982+};
85983
85984 static __init int irq_work_init_cpu_notifier(void)
85985 {
85986- cpu_notify.notifier_call = irq_work_cpu_notify;
85987- cpu_notify.priority = 0;
85988 register_cpu_notifier(&cpu_notify);
85989 return 0;
85990 }
85991diff --git a/kernel/jump_label.c b/kernel/jump_label.c
85992index 9019f15..9a3c42e 100644
85993--- a/kernel/jump_label.c
85994+++ b/kernel/jump_label.c
85995@@ -14,6 +14,7 @@
85996 #include <linux/err.h>
85997 #include <linux/static_key.h>
85998 #include <linux/jump_label_ratelimit.h>
85999+#include <linux/mm.h>
86000
86001 #ifdef HAVE_JUMP_LABEL
86002
86003@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
86004
86005 size = (((unsigned long)stop - (unsigned long)start)
86006 / sizeof(struct jump_entry));
86007+ pax_open_kernel();
86008 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
86009+ pax_close_kernel();
86010 }
86011
86012 static void jump_label_update(struct static_key *key, int enable);
86013@@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
86014 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
86015 struct jump_entry *iter;
86016
86017+ pax_open_kernel();
86018 for (iter = iter_start; iter < iter_stop; iter++) {
86019 if (within_module_init(iter->code, mod))
86020 iter->code = 0;
86021 }
86022+ pax_close_kernel();
86023 }
86024
86025 static int
86026diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
86027index 3127ad5..159d880 100644
86028--- a/kernel/kallsyms.c
86029+++ b/kernel/kallsyms.c
86030@@ -11,6 +11,9 @@
86031 * Changed the compression method from stem compression to "table lookup"
86032 * compression (see scripts/kallsyms.c for a more complete description)
86033 */
86034+#ifdef CONFIG_GRKERNSEC_HIDESYM
86035+#define __INCLUDED_BY_HIDESYM 1
86036+#endif
86037 #include <linux/kallsyms.h>
86038 #include <linux/module.h>
86039 #include <linux/init.h>
86040@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
86041
86042 static inline int is_kernel_inittext(unsigned long addr)
86043 {
86044+ if (system_state != SYSTEM_BOOTING)
86045+ return 0;
86046+
86047 if (addr >= (unsigned long)_sinittext
86048 && addr <= (unsigned long)_einittext)
86049 return 1;
86050 return 0;
86051 }
86052
86053+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86054+#ifdef CONFIG_MODULES
86055+static inline int is_module_text(unsigned long addr)
86056+{
86057+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
86058+ return 1;
86059+
86060+ addr = ktla_ktva(addr);
86061+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
86062+}
86063+#else
86064+static inline int is_module_text(unsigned long addr)
86065+{
86066+ return 0;
86067+}
86068+#endif
86069+#endif
86070+
86071 static inline int is_kernel_text(unsigned long addr)
86072 {
86073 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
86074@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
86075
86076 static inline int is_kernel(unsigned long addr)
86077 {
86078+
86079+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86080+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
86081+ return 1;
86082+
86083+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
86084+#else
86085 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
86086+#endif
86087+
86088 return 1;
86089 return in_gate_area_no_mm(addr);
86090 }
86091
86092 static int is_ksym_addr(unsigned long addr)
86093 {
86094+
86095+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86096+ if (is_module_text(addr))
86097+ return 0;
86098+#endif
86099+
86100 if (all_var)
86101 return is_kernel(addr);
86102
86103@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
86104
86105 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
86106 {
86107- iter->name[0] = '\0';
86108 iter->nameoff = get_symbol_offset(new_pos);
86109 iter->pos = new_pos;
86110 }
86111@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
86112 {
86113 struct kallsym_iter *iter = m->private;
86114
86115+#ifdef CONFIG_GRKERNSEC_HIDESYM
86116+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
86117+ return 0;
86118+#endif
86119+
86120 /* Some debugging symbols have no name. Ignore them. */
86121 if (!iter->name[0])
86122 return 0;
86123@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
86124 */
86125 type = iter->exported ? toupper(iter->type) :
86126 tolower(iter->type);
86127+
86128 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
86129 type, iter->name, iter->module_name);
86130 } else
86131@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
86132 struct kallsym_iter *iter;
86133 int ret;
86134
86135- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
86136+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
86137 if (!iter)
86138 return -ENOMEM;
86139 reset_iter(iter, 0);
86140diff --git a/kernel/kcmp.c b/kernel/kcmp.c
86141index e30ac0f..3528cac 100644
86142--- a/kernel/kcmp.c
86143+++ b/kernel/kcmp.c
86144@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
86145 struct task_struct *task1, *task2;
86146 int ret;
86147
86148+#ifdef CONFIG_GRKERNSEC
86149+ return -ENOSYS;
86150+#endif
86151+
86152 rcu_read_lock();
86153
86154 /*
86155diff --git a/kernel/kexec.c b/kernel/kexec.c
86156index 9c97016..df438f8 100644
86157--- a/kernel/kexec.c
86158+++ b/kernel/kexec.c
86159@@ -1044,7 +1044,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
86160 unsigned long flags)
86161 {
86162 struct compat_kexec_segment in;
86163- struct kexec_segment out, __user *ksegments;
86164+ struct kexec_segment out;
86165+ struct kexec_segment __user *ksegments;
86166 unsigned long i, result;
86167
86168 /* Don't allow clients that don't understand the native
86169diff --git a/kernel/kmod.c b/kernel/kmod.c
86170index b086006..b66f630 100644
86171--- a/kernel/kmod.c
86172+++ b/kernel/kmod.c
86173@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
86174 kfree(info->argv);
86175 }
86176
86177-static int call_modprobe(char *module_name, int wait)
86178+static int call_modprobe(char *module_name, char *module_param, int wait)
86179 {
86180 struct subprocess_info *info;
86181 static char *envp[] = {
86182@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
86183 NULL
86184 };
86185
86186- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
86187+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
86188 if (!argv)
86189 goto out;
86190
86191@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
86192 argv[1] = "-q";
86193 argv[2] = "--";
86194 argv[3] = module_name; /* check free_modprobe_argv() */
86195- argv[4] = NULL;
86196+ argv[4] = module_param;
86197+ argv[5] = NULL;
86198
86199 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
86200 NULL, free_modprobe_argv, NULL);
86201@@ -129,9 +130,8 @@ out:
86202 * If module auto-loading support is disabled then this function
86203 * becomes a no-operation.
86204 */
86205-int __request_module(bool wait, const char *fmt, ...)
86206+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
86207 {
86208- va_list args;
86209 char module_name[MODULE_NAME_LEN];
86210 unsigned int max_modprobes;
86211 int ret;
86212@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
86213 if (!modprobe_path[0])
86214 return 0;
86215
86216- va_start(args, fmt);
86217- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
86218- va_end(args);
86219+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
86220 if (ret >= MODULE_NAME_LEN)
86221 return -ENAMETOOLONG;
86222
86223@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
86224 if (ret)
86225 return ret;
86226
86227+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86228+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
86229+ /* hack to workaround consolekit/udisks stupidity */
86230+ read_lock(&tasklist_lock);
86231+ if (!strcmp(current->comm, "mount") &&
86232+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
86233+ read_unlock(&tasklist_lock);
86234+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
86235+ return -EPERM;
86236+ }
86237+ read_unlock(&tasklist_lock);
86238+ }
86239+#endif
86240+
86241 /* If modprobe needs a service that is in a module, we get a recursive
86242 * loop. Limit the number of running kmod threads to max_threads/2 or
86243 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
86244@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
86245
86246 trace_module_request(module_name, wait, _RET_IP_);
86247
86248- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86249+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86250
86251 atomic_dec(&kmod_concurrent);
86252 return ret;
86253 }
86254+
86255+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
86256+{
86257+ va_list args;
86258+ int ret;
86259+
86260+ va_start(args, fmt);
86261+ ret = ____request_module(wait, module_param, fmt, args);
86262+ va_end(args);
86263+
86264+ return ret;
86265+}
86266+
86267+int __request_module(bool wait, const char *fmt, ...)
86268+{
86269+ va_list args;
86270+ int ret;
86271+
86272+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86273+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
86274+ char module_param[MODULE_NAME_LEN];
86275+
86276+ memset(module_param, 0, sizeof(module_param));
86277+
86278+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
86279+
86280+ va_start(args, fmt);
86281+ ret = ____request_module(wait, module_param, fmt, args);
86282+ va_end(args);
86283+
86284+ return ret;
86285+ }
86286+#endif
86287+
86288+ va_start(args, fmt);
86289+ ret = ____request_module(wait, NULL, fmt, args);
86290+ va_end(args);
86291+
86292+ return ret;
86293+}
86294+
86295 EXPORT_SYMBOL(__request_module);
86296 #endif /* CONFIG_MODULES */
86297
86298@@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
86299 */
86300 set_user_nice(current, 0);
86301
86302+#ifdef CONFIG_GRKERNSEC
86303+ /* this is race-free as far as userland is concerned as we copied
86304+ out the path to be used prior to this point and are now operating
86305+ on that copy
86306+ */
86307+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
86308+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
86309+ strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
86310+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
86311+ retval = -EPERM;
86312+ goto fail;
86313+ }
86314+#endif
86315+
86316 retval = -ENOMEM;
86317 new = prepare_kernel_cred(current);
86318 if (!new)
86319@@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
86320 commit_creds(new);
86321
86322 retval = do_execve(sub_info->path,
86323- (const char __user *const __user *)sub_info->argv,
86324- (const char __user *const __user *)sub_info->envp);
86325+ (const char __user *const __force_user *)sub_info->argv,
86326+ (const char __user *const __force_user *)sub_info->envp);
86327 if (!retval)
86328 return 0;
86329
86330@@ -260,6 +327,10 @@ static int call_helper(void *data)
86331
86332 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
86333 {
86334+#ifdef CONFIG_GRKERNSEC
86335+ kfree(info->path);
86336+ info->path = info->origpath;
86337+#endif
86338 if (info->cleanup)
86339 (*info->cleanup)(info);
86340 kfree(info);
86341@@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
86342 *
86343 * Thus the __user pointer cast is valid here.
86344 */
86345- sys_wait4(pid, (int __user *)&ret, 0, NULL);
86346+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
86347
86348 /*
86349 * If ret is 0, either ____call_usermodehelper failed and the
86350@@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
86351 goto out;
86352
86353 INIT_WORK(&sub_info->work, __call_usermodehelper);
86354+#ifdef CONFIG_GRKERNSEC
86355+ sub_info->origpath = path;
86356+ sub_info->path = kstrdup(path, gfp_mask);
86357+#else
86358 sub_info->path = path;
86359+#endif
86360 sub_info->argv = argv;
86361 sub_info->envp = envp;
86362
86363@@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
86364 static int proc_cap_handler(struct ctl_table *table, int write,
86365 void __user *buffer, size_t *lenp, loff_t *ppos)
86366 {
86367- struct ctl_table t;
86368+ ctl_table_no_const t;
86369 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
86370 kernel_cap_t new_cap;
86371 int err, i;
86372diff --git a/kernel/kprobes.c b/kernel/kprobes.c
86373index ceeadfc..11c18b6 100644
86374--- a/kernel/kprobes.c
86375+++ b/kernel/kprobes.c
86376@@ -31,6 +31,9 @@
86377 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
86378 * <prasanna@in.ibm.com> added function-return probes.
86379 */
86380+#ifdef CONFIG_GRKERNSEC_HIDESYM
86381+#define __INCLUDED_BY_HIDESYM 1
86382+#endif
86383 #include <linux/kprobes.h>
86384 #include <linux/hash.h>
86385 #include <linux/init.h>
86386@@ -135,12 +138,12 @@ enum kprobe_slot_state {
86387
86388 static void *alloc_insn_page(void)
86389 {
86390- return module_alloc(PAGE_SIZE);
86391+ return module_alloc_exec(PAGE_SIZE);
86392 }
86393
86394 static void free_insn_page(void *page)
86395 {
86396- module_free(NULL, page);
86397+ module_free_exec(NULL, page);
86398 }
86399
86400 struct kprobe_insn_cache kprobe_insn_slots = {
86401@@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
86402 kprobe_type = "k";
86403
86404 if (sym)
86405- seq_printf(pi, "%p %s %s+0x%x %s ",
86406+ seq_printf(pi, "%pK %s %s+0x%x %s ",
86407 p->addr, kprobe_type, sym, offset,
86408 (modname ? modname : " "));
86409 else
86410- seq_printf(pi, "%p %s %p ",
86411+ seq_printf(pi, "%pK %s %pK ",
86412 p->addr, kprobe_type, p->addr);
86413
86414 if (!pp)
86415diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
86416index 9659d38..bffd520 100644
86417--- a/kernel/ksysfs.c
86418+++ b/kernel/ksysfs.c
86419@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
86420 {
86421 if (count+1 > UEVENT_HELPER_PATH_LEN)
86422 return -ENOENT;
86423+ if (!capable(CAP_SYS_ADMIN))
86424+ return -EPERM;
86425 memcpy(uevent_helper, buf, count);
86426 uevent_helper[count] = '\0';
86427 if (count && uevent_helper[count-1] == '\n')
86428@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
86429 return count;
86430 }
86431
86432-static struct bin_attribute notes_attr = {
86433+static bin_attribute_no_const notes_attr __read_only = {
86434 .attr = {
86435 .name = "notes",
86436 .mode = S_IRUGO,
86437diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
86438index 576ba75..7c256e4 100644
86439--- a/kernel/locking/lockdep.c
86440+++ b/kernel/locking/lockdep.c
86441@@ -596,6 +596,10 @@ static int static_obj(void *obj)
86442 end = (unsigned long) &_end,
86443 addr = (unsigned long) obj;
86444
86445+#ifdef CONFIG_PAX_KERNEXEC
86446+ start = ktla_ktva(start);
86447+#endif
86448+
86449 /*
86450 * static variable?
86451 */
86452@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
86453 if (!static_obj(lock->key)) {
86454 debug_locks_off();
86455 printk("INFO: trying to register non-static key.\n");
86456+ printk("lock:%pS key:%pS.\n", lock, lock->key);
86457 printk("the code is fine but needs lockdep annotation.\n");
86458 printk("turning off the locking correctness validator.\n");
86459 dump_stack();
86460@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
86461 if (!class)
86462 return 0;
86463 }
86464- atomic_inc((atomic_t *)&class->ops);
86465+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
86466 if (very_verbose(class)) {
86467 printk("\nacquire class [%p] %s", class->key, class->name);
86468 if (class->name_version > 1)
86469diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
86470index ef43ac4..2720dfa 100644
86471--- a/kernel/locking/lockdep_proc.c
86472+++ b/kernel/locking/lockdep_proc.c
86473@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
86474 return 0;
86475 }
86476
86477- seq_printf(m, "%p", class->key);
86478+ seq_printf(m, "%pK", class->key);
86479 #ifdef CONFIG_DEBUG_LOCKDEP
86480 seq_printf(m, " OPS:%8ld", class->ops);
86481 #endif
86482@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
86483
86484 list_for_each_entry(entry, &class->locks_after, entry) {
86485 if (entry->distance == 1) {
86486- seq_printf(m, " -> [%p] ", entry->class->key);
86487+ seq_printf(m, " -> [%pK] ", entry->class->key);
86488 print_name(m, entry->class);
86489 seq_puts(m, "\n");
86490 }
86491@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
86492 if (!class->key)
86493 continue;
86494
86495- seq_printf(m, "[%p] ", class->key);
86496+ seq_printf(m, "[%pK] ", class->key);
86497 print_name(m, class);
86498 seq_puts(m, "\n");
86499 }
86500@@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
86501 if (!i)
86502 seq_line(m, '-', 40-namelen, namelen);
86503
86504- snprintf(ip, sizeof(ip), "[<%p>]",
86505+ snprintf(ip, sizeof(ip), "[<%pK>]",
86506 (void *)class->contention_point[i]);
86507 seq_printf(m, "%40s %14lu %29s %pS\n",
86508 name, stats->contention_point[i],
86509@@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
86510 if (!i)
86511 seq_line(m, '-', 40-namelen, namelen);
86512
86513- snprintf(ip, sizeof(ip), "[<%p>]",
86514+ snprintf(ip, sizeof(ip), "[<%pK>]",
86515 (void *)class->contending_point[i]);
86516 seq_printf(m, "%40s %14lu %29s %pS\n",
86517 name, stats->contending_point[i],
86518diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
86519index 7e3443f..b2a1e6b 100644
86520--- a/kernel/locking/mutex-debug.c
86521+++ b/kernel/locking/mutex-debug.c
86522@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
86523 }
86524
86525 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86526- struct thread_info *ti)
86527+ struct task_struct *task)
86528 {
86529 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
86530
86531 /* Mark the current thread as blocked on the lock: */
86532- ti->task->blocked_on = waiter;
86533+ task->blocked_on = waiter;
86534 }
86535
86536 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86537- struct thread_info *ti)
86538+ struct task_struct *task)
86539 {
86540 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
86541- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
86542- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
86543- ti->task->blocked_on = NULL;
86544+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
86545+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
86546+ task->blocked_on = NULL;
86547
86548 list_del_init(&waiter->list);
86549 waiter->task = NULL;
86550diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
86551index 0799fd3..d06ae3b 100644
86552--- a/kernel/locking/mutex-debug.h
86553+++ b/kernel/locking/mutex-debug.h
86554@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
86555 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
86556 extern void debug_mutex_add_waiter(struct mutex *lock,
86557 struct mutex_waiter *waiter,
86558- struct thread_info *ti);
86559+ struct task_struct *task);
86560 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86561- struct thread_info *ti);
86562+ struct task_struct *task);
86563 extern void debug_mutex_unlock(struct mutex *lock);
86564 extern void debug_mutex_init(struct mutex *lock, const char *name,
86565 struct lock_class_key *key);
86566diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
86567index 4dd6e4c..df52693 100644
86568--- a/kernel/locking/mutex.c
86569+++ b/kernel/locking/mutex.c
86570@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
86571 node->locked = 1;
86572 return;
86573 }
86574- ACCESS_ONCE(prev->next) = node;
86575+ ACCESS_ONCE_RW(prev->next) = node;
86576 smp_wmb();
86577 /* Wait until the lock holder passes the lock down */
86578 while (!ACCESS_ONCE(node->locked))
86579@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
86580 while (!(next = ACCESS_ONCE(node->next)))
86581 arch_mutex_cpu_relax();
86582 }
86583- ACCESS_ONCE(next->locked) = 1;
86584+ ACCESS_ONCE_RW(next->locked) = 1;
86585 smp_wmb();
86586 }
86587
86588@@ -520,7 +520,7 @@ slowpath:
86589 goto skip_wait;
86590
86591 debug_mutex_lock_common(lock, &waiter);
86592- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
86593+ debug_mutex_add_waiter(lock, &waiter, task);
86594
86595 /* add waiting tasks to the end of the waitqueue (FIFO): */
86596 list_add_tail(&waiter.list, &lock->wait_list);
86597@@ -564,7 +564,7 @@ slowpath:
86598 schedule_preempt_disabled();
86599 spin_lock_mutex(&lock->wait_lock, flags);
86600 }
86601- mutex_remove_waiter(lock, &waiter, current_thread_info());
86602+ mutex_remove_waiter(lock, &waiter, task);
86603 /* set it to 0 if there are no waiters left: */
86604 if (likely(list_empty(&lock->wait_list)))
86605 atomic_set(&lock->count, 0);
86606@@ -601,7 +601,7 @@ skip_wait:
86607 return 0;
86608
86609 err:
86610- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
86611+ mutex_remove_waiter(lock, &waiter, task);
86612 spin_unlock_mutex(&lock->wait_lock, flags);
86613 debug_mutex_free_waiter(&waiter);
86614 mutex_release(&lock->dep_map, 1, ip);
86615diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
86616index 1d96dd0..994ff19 100644
86617--- a/kernel/locking/rtmutex-tester.c
86618+++ b/kernel/locking/rtmutex-tester.c
86619@@ -22,7 +22,7 @@
86620 #define MAX_RT_TEST_MUTEXES 8
86621
86622 static spinlock_t rttest_lock;
86623-static atomic_t rttest_event;
86624+static atomic_unchecked_t rttest_event;
86625
86626 struct test_thread_data {
86627 int opcode;
86628@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86629
86630 case RTTEST_LOCKCONT:
86631 td->mutexes[td->opdata] = 1;
86632- td->event = atomic_add_return(1, &rttest_event);
86633+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86634 return 0;
86635
86636 case RTTEST_RESET:
86637@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86638 return 0;
86639
86640 case RTTEST_RESETEVENT:
86641- atomic_set(&rttest_event, 0);
86642+ atomic_set_unchecked(&rttest_event, 0);
86643 return 0;
86644
86645 default:
86646@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86647 return ret;
86648
86649 td->mutexes[id] = 1;
86650- td->event = atomic_add_return(1, &rttest_event);
86651+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86652 rt_mutex_lock(&mutexes[id]);
86653- td->event = atomic_add_return(1, &rttest_event);
86654+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86655 td->mutexes[id] = 4;
86656 return 0;
86657
86658@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86659 return ret;
86660
86661 td->mutexes[id] = 1;
86662- td->event = atomic_add_return(1, &rttest_event);
86663+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86664 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
86665- td->event = atomic_add_return(1, &rttest_event);
86666+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86667 td->mutexes[id] = ret ? 0 : 4;
86668 return ret ? -EINTR : 0;
86669
86670@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86671 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
86672 return ret;
86673
86674- td->event = atomic_add_return(1, &rttest_event);
86675+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86676 rt_mutex_unlock(&mutexes[id]);
86677- td->event = atomic_add_return(1, &rttest_event);
86678+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86679 td->mutexes[id] = 0;
86680 return 0;
86681
86682@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86683 break;
86684
86685 td->mutexes[dat] = 2;
86686- td->event = atomic_add_return(1, &rttest_event);
86687+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86688 break;
86689
86690 default:
86691@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86692 return;
86693
86694 td->mutexes[dat] = 3;
86695- td->event = atomic_add_return(1, &rttest_event);
86696+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86697 break;
86698
86699 case RTTEST_LOCKNOWAIT:
86700@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86701 return;
86702
86703 td->mutexes[dat] = 1;
86704- td->event = atomic_add_return(1, &rttest_event);
86705+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86706 return;
86707
86708 default:
86709diff --git a/kernel/module.c b/kernel/module.c
86710index f5a3b1e..97ebb15 100644
86711--- a/kernel/module.c
86712+++ b/kernel/module.c
86713@@ -61,6 +61,7 @@
86714 #include <linux/pfn.h>
86715 #include <linux/bsearch.h>
86716 #include <linux/fips.h>
86717+#include <linux/grsecurity.h>
86718 #include <uapi/linux/module.h>
86719 #include "module-internal.h"
86720
86721@@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
86722
86723 /* Bounds of module allocation, for speeding __module_address.
86724 * Protected by module_mutex. */
86725-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
86726+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
86727+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
86728
86729 int register_module_notifier(struct notifier_block * nb)
86730 {
86731@@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
86732 return true;
86733
86734 list_for_each_entry_rcu(mod, &modules, list) {
86735- struct symsearch arr[] = {
86736+ struct symsearch modarr[] = {
86737 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
86738 NOT_GPL_ONLY, false },
86739 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
86740@@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
86741 if (mod->state == MODULE_STATE_UNFORMED)
86742 continue;
86743
86744- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
86745+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
86746 return true;
86747 }
86748 return false;
86749@@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
86750 if (!pcpusec->sh_size)
86751 return 0;
86752
86753- if (align > PAGE_SIZE) {
86754+ if (align-1 >= PAGE_SIZE) {
86755 pr_warn("%s: per-cpu alignment %li > %li\n",
86756 mod->name, align, PAGE_SIZE);
86757 align = PAGE_SIZE;
86758@@ -1064,7 +1066,7 @@ struct module_attribute module_uevent =
86759 static ssize_t show_coresize(struct module_attribute *mattr,
86760 struct module_kobject *mk, char *buffer)
86761 {
86762- return sprintf(buffer, "%u\n", mk->mod->core_size);
86763+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
86764 }
86765
86766 static struct module_attribute modinfo_coresize =
86767@@ -1073,7 +1075,7 @@ static struct module_attribute modinfo_coresize =
86768 static ssize_t show_initsize(struct module_attribute *mattr,
86769 struct module_kobject *mk, char *buffer)
86770 {
86771- return sprintf(buffer, "%u\n", mk->mod->init_size);
86772+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
86773 }
86774
86775 static struct module_attribute modinfo_initsize =
86776@@ -1165,12 +1167,29 @@ static int check_version(Elf_Shdr *sechdrs,
86777 goto bad_version;
86778 }
86779
86780+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
86781+ /*
86782+ * avoid potentially printing jibberish on attempted load
86783+ * of a module randomized with a different seed
86784+ */
86785+ pr_warn("no symbol version for %s\n", symname);
86786+#else
86787 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
86788+#endif
86789 return 0;
86790
86791 bad_version:
86792+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
86793+ /*
86794+ * avoid potentially printing jibberish on attempted load
86795+ * of a module randomized with a different seed
86796+ */
86797+ printk("attempted module disagrees about version of symbol %s\n",
86798+ symname);
86799+#else
86800 printk("%s: disagrees about version of symbol %s\n",
86801 mod->name, symname);
86802+#endif
86803 return 0;
86804 }
86805
86806@@ -1286,7 +1305,7 @@ resolve_symbol_wait(struct module *mod,
86807 */
86808 #ifdef CONFIG_SYSFS
86809
86810-#ifdef CONFIG_KALLSYMS
86811+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
86812 static inline bool sect_empty(const Elf_Shdr *sect)
86813 {
86814 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
86815@@ -1426,7 +1445,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
86816 {
86817 unsigned int notes, loaded, i;
86818 struct module_notes_attrs *notes_attrs;
86819- struct bin_attribute *nattr;
86820+ bin_attribute_no_const *nattr;
86821
86822 /* failed to create section attributes, so can't create notes */
86823 if (!mod->sect_attrs)
86824@@ -1538,7 +1557,7 @@ static void del_usage_links(struct module *mod)
86825 static int module_add_modinfo_attrs(struct module *mod)
86826 {
86827 struct module_attribute *attr;
86828- struct module_attribute *temp_attr;
86829+ module_attribute_no_const *temp_attr;
86830 int error = 0;
86831 int i;
86832
86833@@ -1759,21 +1778,21 @@ static void set_section_ro_nx(void *base,
86834
86835 static void unset_module_core_ro_nx(struct module *mod)
86836 {
86837- set_page_attributes(mod->module_core + mod->core_text_size,
86838- mod->module_core + mod->core_size,
86839+ set_page_attributes(mod->module_core_rw,
86840+ mod->module_core_rw + mod->core_size_rw,
86841 set_memory_x);
86842- set_page_attributes(mod->module_core,
86843- mod->module_core + mod->core_ro_size,
86844+ set_page_attributes(mod->module_core_rx,
86845+ mod->module_core_rx + mod->core_size_rx,
86846 set_memory_rw);
86847 }
86848
86849 static void unset_module_init_ro_nx(struct module *mod)
86850 {
86851- set_page_attributes(mod->module_init + mod->init_text_size,
86852- mod->module_init + mod->init_size,
86853+ set_page_attributes(mod->module_init_rw,
86854+ mod->module_init_rw + mod->init_size_rw,
86855 set_memory_x);
86856- set_page_attributes(mod->module_init,
86857- mod->module_init + mod->init_ro_size,
86858+ set_page_attributes(mod->module_init_rx,
86859+ mod->module_init_rx + mod->init_size_rx,
86860 set_memory_rw);
86861 }
86862
86863@@ -1786,14 +1805,14 @@ void set_all_modules_text_rw(void)
86864 list_for_each_entry_rcu(mod, &modules, list) {
86865 if (mod->state == MODULE_STATE_UNFORMED)
86866 continue;
86867- if ((mod->module_core) && (mod->core_text_size)) {
86868- set_page_attributes(mod->module_core,
86869- mod->module_core + mod->core_text_size,
86870+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
86871+ set_page_attributes(mod->module_core_rx,
86872+ mod->module_core_rx + mod->core_size_rx,
86873 set_memory_rw);
86874 }
86875- if ((mod->module_init) && (mod->init_text_size)) {
86876- set_page_attributes(mod->module_init,
86877- mod->module_init + mod->init_text_size,
86878+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
86879+ set_page_attributes(mod->module_init_rx,
86880+ mod->module_init_rx + mod->init_size_rx,
86881 set_memory_rw);
86882 }
86883 }
86884@@ -1809,14 +1828,14 @@ void set_all_modules_text_ro(void)
86885 list_for_each_entry_rcu(mod, &modules, list) {
86886 if (mod->state == MODULE_STATE_UNFORMED)
86887 continue;
86888- if ((mod->module_core) && (mod->core_text_size)) {
86889- set_page_attributes(mod->module_core,
86890- mod->module_core + mod->core_text_size,
86891+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
86892+ set_page_attributes(mod->module_core_rx,
86893+ mod->module_core_rx + mod->core_size_rx,
86894 set_memory_ro);
86895 }
86896- if ((mod->module_init) && (mod->init_text_size)) {
86897- set_page_attributes(mod->module_init,
86898- mod->module_init + mod->init_text_size,
86899+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
86900+ set_page_attributes(mod->module_init_rx,
86901+ mod->module_init_rx + mod->init_size_rx,
86902 set_memory_ro);
86903 }
86904 }
86905@@ -1867,16 +1886,19 @@ static void free_module(struct module *mod)
86906
86907 /* This may be NULL, but that's OK */
86908 unset_module_init_ro_nx(mod);
86909- module_free(mod, mod->module_init);
86910+ module_free(mod, mod->module_init_rw);
86911+ module_free_exec(mod, mod->module_init_rx);
86912 kfree(mod->args);
86913 percpu_modfree(mod);
86914
86915 /* Free lock-classes: */
86916- lockdep_free_key_range(mod->module_core, mod->core_size);
86917+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
86918+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
86919
86920 /* Finally, free the core (containing the module structure) */
86921 unset_module_core_ro_nx(mod);
86922- module_free(mod, mod->module_core);
86923+ module_free_exec(mod, mod->module_core_rx);
86924+ module_free(mod, mod->module_core_rw);
86925
86926 #ifdef CONFIG_MPU
86927 update_protections(current->mm);
86928@@ -1945,9 +1967,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
86929 int ret = 0;
86930 const struct kernel_symbol *ksym;
86931
86932+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86933+ int is_fs_load = 0;
86934+ int register_filesystem_found = 0;
86935+ char *p;
86936+
86937+ p = strstr(mod->args, "grsec_modharden_fs");
86938+ if (p) {
86939+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
86940+ /* copy \0 as well */
86941+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
86942+ is_fs_load = 1;
86943+ }
86944+#endif
86945+
86946 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
86947 const char *name = info->strtab + sym[i].st_name;
86948
86949+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86950+ /* it's a real shame this will never get ripped and copied
86951+ upstream! ;(
86952+ */
86953+ if (is_fs_load && !strcmp(name, "register_filesystem"))
86954+ register_filesystem_found = 1;
86955+#endif
86956+
86957 switch (sym[i].st_shndx) {
86958 case SHN_COMMON:
86959 /* We compiled with -fno-common. These are not
86960@@ -1968,7 +2012,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
86961 ksym = resolve_symbol_wait(mod, info, name);
86962 /* Ok if resolved. */
86963 if (ksym && !IS_ERR(ksym)) {
86964+ pax_open_kernel();
86965 sym[i].st_value = ksym->value;
86966+ pax_close_kernel();
86967 break;
86968 }
86969
86970@@ -1987,11 +2033,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
86971 secbase = (unsigned long)mod_percpu(mod);
86972 else
86973 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
86974+ pax_open_kernel();
86975 sym[i].st_value += secbase;
86976+ pax_close_kernel();
86977 break;
86978 }
86979 }
86980
86981+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86982+ if (is_fs_load && !register_filesystem_found) {
86983+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
86984+ ret = -EPERM;
86985+ }
86986+#endif
86987+
86988 return ret;
86989 }
86990
86991@@ -2075,22 +2130,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
86992 || s->sh_entsize != ~0UL
86993 || strstarts(sname, ".init"))
86994 continue;
86995- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
86996+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
86997+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
86998+ else
86999+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
87000 pr_debug("\t%s\n", sname);
87001 }
87002- switch (m) {
87003- case 0: /* executable */
87004- mod->core_size = debug_align(mod->core_size);
87005- mod->core_text_size = mod->core_size;
87006- break;
87007- case 1: /* RO: text and ro-data */
87008- mod->core_size = debug_align(mod->core_size);
87009- mod->core_ro_size = mod->core_size;
87010- break;
87011- case 3: /* whole core */
87012- mod->core_size = debug_align(mod->core_size);
87013- break;
87014- }
87015 }
87016
87017 pr_debug("Init section allocation order:\n");
87018@@ -2104,23 +2149,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
87019 || s->sh_entsize != ~0UL
87020 || !strstarts(sname, ".init"))
87021 continue;
87022- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
87023- | INIT_OFFSET_MASK);
87024+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87025+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
87026+ else
87027+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
87028+ s->sh_entsize |= INIT_OFFSET_MASK;
87029 pr_debug("\t%s\n", sname);
87030 }
87031- switch (m) {
87032- case 0: /* executable */
87033- mod->init_size = debug_align(mod->init_size);
87034- mod->init_text_size = mod->init_size;
87035- break;
87036- case 1: /* RO: text and ro-data */
87037- mod->init_size = debug_align(mod->init_size);
87038- mod->init_ro_size = mod->init_size;
87039- break;
87040- case 3: /* whole init */
87041- mod->init_size = debug_align(mod->init_size);
87042- break;
87043- }
87044 }
87045 }
87046
87047@@ -2293,7 +2328,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87048
87049 /* Put symbol section at end of init part of module. */
87050 symsect->sh_flags |= SHF_ALLOC;
87051- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
87052+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
87053 info->index.sym) | INIT_OFFSET_MASK;
87054 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
87055
87056@@ -2310,13 +2345,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87057 }
87058
87059 /* Append room for core symbols at end of core part. */
87060- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
87061- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
87062- mod->core_size += strtab_size;
87063+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
87064+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
87065+ mod->core_size_rx += strtab_size;
87066
87067 /* Put string table section at end of init part of module. */
87068 strsect->sh_flags |= SHF_ALLOC;
87069- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
87070+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
87071 info->index.str) | INIT_OFFSET_MASK;
87072 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
87073 }
87074@@ -2334,12 +2369,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87075 /* Make sure we get permanent strtab: don't use info->strtab. */
87076 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
87077
87078+ pax_open_kernel();
87079+
87080 /* Set types up while we still have access to sections. */
87081 for (i = 0; i < mod->num_symtab; i++)
87082 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
87083
87084- mod->core_symtab = dst = mod->module_core + info->symoffs;
87085- mod->core_strtab = s = mod->module_core + info->stroffs;
87086+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
87087+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
87088 src = mod->symtab;
87089 for (ndst = i = 0; i < mod->num_symtab; i++) {
87090 if (i == 0 ||
87091@@ -2351,6 +2388,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87092 }
87093 }
87094 mod->core_num_syms = ndst;
87095+
87096+ pax_close_kernel();
87097 }
87098 #else
87099 static inline void layout_symtab(struct module *mod, struct load_info *info)
87100@@ -2384,17 +2423,33 @@ void * __weak module_alloc(unsigned long size)
87101 return vmalloc_exec(size);
87102 }
87103
87104-static void *module_alloc_update_bounds(unsigned long size)
87105+static void *module_alloc_update_bounds_rw(unsigned long size)
87106 {
87107 void *ret = module_alloc(size);
87108
87109 if (ret) {
87110 mutex_lock(&module_mutex);
87111 /* Update module bounds. */
87112- if ((unsigned long)ret < module_addr_min)
87113- module_addr_min = (unsigned long)ret;
87114- if ((unsigned long)ret + size > module_addr_max)
87115- module_addr_max = (unsigned long)ret + size;
87116+ if ((unsigned long)ret < module_addr_min_rw)
87117+ module_addr_min_rw = (unsigned long)ret;
87118+ if ((unsigned long)ret + size > module_addr_max_rw)
87119+ module_addr_max_rw = (unsigned long)ret + size;
87120+ mutex_unlock(&module_mutex);
87121+ }
87122+ return ret;
87123+}
87124+
87125+static void *module_alloc_update_bounds_rx(unsigned long size)
87126+{
87127+ void *ret = module_alloc_exec(size);
87128+
87129+ if (ret) {
87130+ mutex_lock(&module_mutex);
87131+ /* Update module bounds. */
87132+ if ((unsigned long)ret < module_addr_min_rx)
87133+ module_addr_min_rx = (unsigned long)ret;
87134+ if ((unsigned long)ret + size > module_addr_max_rx)
87135+ module_addr_max_rx = (unsigned long)ret + size;
87136 mutex_unlock(&module_mutex);
87137 }
87138 return ret;
87139@@ -2651,7 +2706,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87140 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
87141
87142 if (info->index.sym == 0) {
87143+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87144+ /*
87145+ * avoid potentially printing jibberish on attempted load
87146+ * of a module randomized with a different seed
87147+ */
87148+ pr_warn("module has no symbols (stripped?)\n");
87149+#else
87150 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
87151+#endif
87152 return ERR_PTR(-ENOEXEC);
87153 }
87154
87155@@ -2667,8 +2730,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87156 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87157 {
87158 const char *modmagic = get_modinfo(info, "vermagic");
87159+ const char *license = get_modinfo(info, "license");
87160 int err;
87161
87162+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
87163+ if (!license || !license_is_gpl_compatible(license))
87164+ return -ENOEXEC;
87165+#endif
87166+
87167 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
87168 modmagic = NULL;
87169
87170@@ -2693,7 +2762,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87171 }
87172
87173 /* Set up license info based on the info section */
87174- set_license(mod, get_modinfo(info, "license"));
87175+ set_license(mod, license);
87176
87177 return 0;
87178 }
87179@@ -2787,7 +2856,7 @@ static int move_module(struct module *mod, struct load_info *info)
87180 void *ptr;
87181
87182 /* Do the allocs. */
87183- ptr = module_alloc_update_bounds(mod->core_size);
87184+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
87185 /*
87186 * The pointer to this block is stored in the module structure
87187 * which is inside the block. Just mark it as not being a
87188@@ -2797,11 +2866,11 @@ static int move_module(struct module *mod, struct load_info *info)
87189 if (!ptr)
87190 return -ENOMEM;
87191
87192- memset(ptr, 0, mod->core_size);
87193- mod->module_core = ptr;
87194+ memset(ptr, 0, mod->core_size_rw);
87195+ mod->module_core_rw = ptr;
87196
87197- if (mod->init_size) {
87198- ptr = module_alloc_update_bounds(mod->init_size);
87199+ if (mod->init_size_rw) {
87200+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
87201 /*
87202 * The pointer to this block is stored in the module structure
87203 * which is inside the block. This block doesn't need to be
87204@@ -2810,13 +2879,45 @@ static int move_module(struct module *mod, struct load_info *info)
87205 */
87206 kmemleak_ignore(ptr);
87207 if (!ptr) {
87208- module_free(mod, mod->module_core);
87209+ module_free(mod, mod->module_core_rw);
87210 return -ENOMEM;
87211 }
87212- memset(ptr, 0, mod->init_size);
87213- mod->module_init = ptr;
87214+ memset(ptr, 0, mod->init_size_rw);
87215+ mod->module_init_rw = ptr;
87216 } else
87217- mod->module_init = NULL;
87218+ mod->module_init_rw = NULL;
87219+
87220+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
87221+ kmemleak_not_leak(ptr);
87222+ if (!ptr) {
87223+ if (mod->module_init_rw)
87224+ module_free(mod, mod->module_init_rw);
87225+ module_free(mod, mod->module_core_rw);
87226+ return -ENOMEM;
87227+ }
87228+
87229+ pax_open_kernel();
87230+ memset(ptr, 0, mod->core_size_rx);
87231+ pax_close_kernel();
87232+ mod->module_core_rx = ptr;
87233+
87234+ if (mod->init_size_rx) {
87235+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
87236+ kmemleak_ignore(ptr);
87237+ if (!ptr && mod->init_size_rx) {
87238+ module_free_exec(mod, mod->module_core_rx);
87239+ if (mod->module_init_rw)
87240+ module_free(mod, mod->module_init_rw);
87241+ module_free(mod, mod->module_core_rw);
87242+ return -ENOMEM;
87243+ }
87244+
87245+ pax_open_kernel();
87246+ memset(ptr, 0, mod->init_size_rx);
87247+ pax_close_kernel();
87248+ mod->module_init_rx = ptr;
87249+ } else
87250+ mod->module_init_rx = NULL;
87251
87252 /* Transfer each section which specifies SHF_ALLOC */
87253 pr_debug("final section addresses:\n");
87254@@ -2827,16 +2928,45 @@ static int move_module(struct module *mod, struct load_info *info)
87255 if (!(shdr->sh_flags & SHF_ALLOC))
87256 continue;
87257
87258- if (shdr->sh_entsize & INIT_OFFSET_MASK)
87259- dest = mod->module_init
87260- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87261- else
87262- dest = mod->module_core + shdr->sh_entsize;
87263+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
87264+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
87265+ dest = mod->module_init_rw
87266+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87267+ else
87268+ dest = mod->module_init_rx
87269+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87270+ } else {
87271+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
87272+ dest = mod->module_core_rw + shdr->sh_entsize;
87273+ else
87274+ dest = mod->module_core_rx + shdr->sh_entsize;
87275+ }
87276+
87277+ if (shdr->sh_type != SHT_NOBITS) {
87278+
87279+#ifdef CONFIG_PAX_KERNEXEC
87280+#ifdef CONFIG_X86_64
87281+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
87282+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
87283+#endif
87284+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
87285+ pax_open_kernel();
87286+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
87287+ pax_close_kernel();
87288+ } else
87289+#endif
87290
87291- if (shdr->sh_type != SHT_NOBITS)
87292 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
87293+ }
87294 /* Update sh_addr to point to copy in image. */
87295- shdr->sh_addr = (unsigned long)dest;
87296+
87297+#ifdef CONFIG_PAX_KERNEXEC
87298+ if (shdr->sh_flags & SHF_EXECINSTR)
87299+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
87300+ else
87301+#endif
87302+
87303+ shdr->sh_addr = (unsigned long)dest;
87304 pr_debug("\t0x%lx %s\n",
87305 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
87306 }
87307@@ -2893,12 +3023,12 @@ static void flush_module_icache(const struct module *mod)
87308 * Do it before processing of module parameters, so the module
87309 * can provide parameter accessor functions of its own.
87310 */
87311- if (mod->module_init)
87312- flush_icache_range((unsigned long)mod->module_init,
87313- (unsigned long)mod->module_init
87314- + mod->init_size);
87315- flush_icache_range((unsigned long)mod->module_core,
87316- (unsigned long)mod->module_core + mod->core_size);
87317+ if (mod->module_init_rx)
87318+ flush_icache_range((unsigned long)mod->module_init_rx,
87319+ (unsigned long)mod->module_init_rx
87320+ + mod->init_size_rx);
87321+ flush_icache_range((unsigned long)mod->module_core_rx,
87322+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
87323
87324 set_fs(old_fs);
87325 }
87326@@ -2955,8 +3085,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
87327 static void module_deallocate(struct module *mod, struct load_info *info)
87328 {
87329 percpu_modfree(mod);
87330- module_free(mod, mod->module_init);
87331- module_free(mod, mod->module_core);
87332+ module_free_exec(mod, mod->module_init_rx);
87333+ module_free_exec(mod, mod->module_core_rx);
87334+ module_free(mod, mod->module_init_rw);
87335+ module_free(mod, mod->module_core_rw);
87336 }
87337
87338 int __weak module_finalize(const Elf_Ehdr *hdr,
87339@@ -2969,7 +3101,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
87340 static int post_relocation(struct module *mod, const struct load_info *info)
87341 {
87342 /* Sort exception table now relocations are done. */
87343+ pax_open_kernel();
87344 sort_extable(mod->extable, mod->extable + mod->num_exentries);
87345+ pax_close_kernel();
87346
87347 /* Copy relocated percpu area over. */
87348 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
87349@@ -3023,16 +3157,16 @@ static int do_init_module(struct module *mod)
87350 MODULE_STATE_COMING, mod);
87351
87352 /* Set RO and NX regions for core */
87353- set_section_ro_nx(mod->module_core,
87354- mod->core_text_size,
87355- mod->core_ro_size,
87356- mod->core_size);
87357+ set_section_ro_nx(mod->module_core_rx,
87358+ mod->core_size_rx,
87359+ mod->core_size_rx,
87360+ mod->core_size_rx);
87361
87362 /* Set RO and NX regions for init */
87363- set_section_ro_nx(mod->module_init,
87364- mod->init_text_size,
87365- mod->init_ro_size,
87366- mod->init_size);
87367+ set_section_ro_nx(mod->module_init_rx,
87368+ mod->init_size_rx,
87369+ mod->init_size_rx,
87370+ mod->init_size_rx);
87371
87372 do_mod_ctors(mod);
87373 /* Start the module */
87374@@ -3093,11 +3227,12 @@ static int do_init_module(struct module *mod)
87375 mod->strtab = mod->core_strtab;
87376 #endif
87377 unset_module_init_ro_nx(mod);
87378- module_free(mod, mod->module_init);
87379- mod->module_init = NULL;
87380- mod->init_size = 0;
87381- mod->init_ro_size = 0;
87382- mod->init_text_size = 0;
87383+ module_free(mod, mod->module_init_rw);
87384+ module_free_exec(mod, mod->module_init_rx);
87385+ mod->module_init_rw = NULL;
87386+ mod->module_init_rx = NULL;
87387+ mod->init_size_rw = 0;
87388+ mod->init_size_rx = 0;
87389 mutex_unlock(&module_mutex);
87390 wake_up_all(&module_wq);
87391
87392@@ -3240,9 +3375,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
87393 if (err)
87394 goto free_unload;
87395
87396+ /* Now copy in args */
87397+ mod->args = strndup_user(uargs, ~0UL >> 1);
87398+ if (IS_ERR(mod->args)) {
87399+ err = PTR_ERR(mod->args);
87400+ goto free_unload;
87401+ }
87402+
87403 /* Set up MODINFO_ATTR fields */
87404 setup_modinfo(mod, info);
87405
87406+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87407+ {
87408+ char *p, *p2;
87409+
87410+ if (strstr(mod->args, "grsec_modharden_netdev")) {
87411+ 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);
87412+ err = -EPERM;
87413+ goto free_modinfo;
87414+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
87415+ p += sizeof("grsec_modharden_normal") - 1;
87416+ p2 = strstr(p, "_");
87417+ if (p2) {
87418+ *p2 = '\0';
87419+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
87420+ *p2 = '_';
87421+ }
87422+ err = -EPERM;
87423+ goto free_modinfo;
87424+ }
87425+ }
87426+#endif
87427+
87428 /* Fix up syms, so that st_value is a pointer to location. */
87429 err = simplify_symbols(mod, info);
87430 if (err < 0)
87431@@ -3258,13 +3422,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
87432
87433 flush_module_icache(mod);
87434
87435- /* Now copy in args */
87436- mod->args = strndup_user(uargs, ~0UL >> 1);
87437- if (IS_ERR(mod->args)) {
87438- err = PTR_ERR(mod->args);
87439- goto free_arch_cleanup;
87440- }
87441-
87442 dynamic_debug_setup(info->debug, info->num_debug);
87443
87444 /* Finally it's fully formed, ready to start executing. */
87445@@ -3299,11 +3456,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
87446 ddebug_cleanup:
87447 dynamic_debug_remove(info->debug);
87448 synchronize_sched();
87449- kfree(mod->args);
87450- free_arch_cleanup:
87451 module_arch_cleanup(mod);
87452 free_modinfo:
87453 free_modinfo(mod);
87454+ kfree(mod->args);
87455 free_unload:
87456 module_unload_free(mod);
87457 unlink_mod:
87458@@ -3386,10 +3542,16 @@ static const char *get_ksymbol(struct module *mod,
87459 unsigned long nextval;
87460
87461 /* At worse, next value is at end of module */
87462- if (within_module_init(addr, mod))
87463- nextval = (unsigned long)mod->module_init+mod->init_text_size;
87464+ if (within_module_init_rx(addr, mod))
87465+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
87466+ else if (within_module_init_rw(addr, mod))
87467+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
87468+ else if (within_module_core_rx(addr, mod))
87469+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
87470+ else if (within_module_core_rw(addr, mod))
87471+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
87472 else
87473- nextval = (unsigned long)mod->module_core+mod->core_text_size;
87474+ return NULL;
87475
87476 /* Scan for closest preceding symbol, and next symbol. (ELF
87477 starts real symbols at 1). */
87478@@ -3640,7 +3802,7 @@ static int m_show(struct seq_file *m, void *p)
87479 return 0;
87480
87481 seq_printf(m, "%s %u",
87482- mod->name, mod->init_size + mod->core_size);
87483+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
87484 print_unload_info(m, mod);
87485
87486 /* Informative for users. */
87487@@ -3649,7 +3811,7 @@ static int m_show(struct seq_file *m, void *p)
87488 mod->state == MODULE_STATE_COMING ? "Loading":
87489 "Live");
87490 /* Used by oprofile and other similar tools. */
87491- seq_printf(m, " 0x%pK", mod->module_core);
87492+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
87493
87494 /* Taints info */
87495 if (mod->taints)
87496@@ -3685,7 +3847,17 @@ static const struct file_operations proc_modules_operations = {
87497
87498 static int __init proc_modules_init(void)
87499 {
87500+#ifndef CONFIG_GRKERNSEC_HIDESYM
87501+#ifdef CONFIG_GRKERNSEC_PROC_USER
87502+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
87503+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
87504+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
87505+#else
87506 proc_create("modules", 0, NULL, &proc_modules_operations);
87507+#endif
87508+#else
87509+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
87510+#endif
87511 return 0;
87512 }
87513 module_init(proc_modules_init);
87514@@ -3746,14 +3918,14 @@ struct module *__module_address(unsigned long addr)
87515 {
87516 struct module *mod;
87517
87518- if (addr < module_addr_min || addr > module_addr_max)
87519+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
87520+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
87521 return NULL;
87522
87523 list_for_each_entry_rcu(mod, &modules, list) {
87524 if (mod->state == MODULE_STATE_UNFORMED)
87525 continue;
87526- if (within_module_core(addr, mod)
87527- || within_module_init(addr, mod))
87528+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
87529 return mod;
87530 }
87531 return NULL;
87532@@ -3788,11 +3960,20 @@ bool is_module_text_address(unsigned long addr)
87533 */
87534 struct module *__module_text_address(unsigned long addr)
87535 {
87536- struct module *mod = __module_address(addr);
87537+ struct module *mod;
87538+
87539+#ifdef CONFIG_X86_32
87540+ addr = ktla_ktva(addr);
87541+#endif
87542+
87543+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
87544+ return NULL;
87545+
87546+ mod = __module_address(addr);
87547+
87548 if (mod) {
87549 /* Make sure it's within the text section. */
87550- if (!within(addr, mod->module_init, mod->init_text_size)
87551- && !within(addr, mod->module_core, mod->core_text_size))
87552+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
87553 mod = NULL;
87554 }
87555 return mod;
87556diff --git a/kernel/notifier.c b/kernel/notifier.c
87557index 2d5cc4c..d9ea600 100644
87558--- a/kernel/notifier.c
87559+++ b/kernel/notifier.c
87560@@ -5,6 +5,7 @@
87561 #include <linux/rcupdate.h>
87562 #include <linux/vmalloc.h>
87563 #include <linux/reboot.h>
87564+#include <linux/mm.h>
87565
87566 /*
87567 * Notifier list for kernel code which wants to be called
87568@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
87569 while ((*nl) != NULL) {
87570 if (n->priority > (*nl)->priority)
87571 break;
87572- nl = &((*nl)->next);
87573+ nl = (struct notifier_block **)&((*nl)->next);
87574 }
87575- n->next = *nl;
87576+ pax_open_kernel();
87577+ *(const void **)&n->next = *nl;
87578 rcu_assign_pointer(*nl, n);
87579+ pax_close_kernel();
87580 return 0;
87581 }
87582
87583@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
87584 return 0;
87585 if (n->priority > (*nl)->priority)
87586 break;
87587- nl = &((*nl)->next);
87588+ nl = (struct notifier_block **)&((*nl)->next);
87589 }
87590- n->next = *nl;
87591+ pax_open_kernel();
87592+ *(const void **)&n->next = *nl;
87593 rcu_assign_pointer(*nl, n);
87594+ pax_close_kernel();
87595 return 0;
87596 }
87597
87598@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
87599 {
87600 while ((*nl) != NULL) {
87601 if ((*nl) == n) {
87602+ pax_open_kernel();
87603 rcu_assign_pointer(*nl, n->next);
87604+ pax_close_kernel();
87605 return 0;
87606 }
87607- nl = &((*nl)->next);
87608+ nl = (struct notifier_block **)&((*nl)->next);
87609 }
87610 return -ENOENT;
87611 }
87612diff --git a/kernel/padata.c b/kernel/padata.c
87613index 2abd25d..02c4faa 100644
87614--- a/kernel/padata.c
87615+++ b/kernel/padata.c
87616@@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
87617 * seq_nr mod. number of cpus in use.
87618 */
87619
87620- seq_nr = atomic_inc_return(&pd->seq_nr);
87621+ seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
87622 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
87623
87624 return padata_index_to_cpu(pd, cpu_index);
87625@@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
87626 padata_init_pqueues(pd);
87627 padata_init_squeues(pd);
87628 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
87629- atomic_set(&pd->seq_nr, -1);
87630+ atomic_set_unchecked(&pd->seq_nr, -1);
87631 atomic_set(&pd->reorder_objects, 0);
87632 atomic_set(&pd->refcnt, 0);
87633 pd->pinst = pinst;
87634diff --git a/kernel/panic.c b/kernel/panic.c
87635index c00b4ce..98c7d1a 100644
87636--- a/kernel/panic.c
87637+++ b/kernel/panic.c
87638@@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
87639 /*
87640 * Stop ourself in panic -- architecture code may override this
87641 */
87642-void __weak panic_smp_self_stop(void)
87643+void __weak __noreturn panic_smp_self_stop(void)
87644 {
87645 while (1)
87646 cpu_relax();
87647@@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
87648 disable_trace_on_warning();
87649
87650 pr_warn("------------[ cut here ]------------\n");
87651- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
87652+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
87653 raw_smp_processor_id(), current->pid, file, line, caller);
87654
87655 if (args)
87656@@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
87657 */
87658 void __stack_chk_fail(void)
87659 {
87660- panic("stack-protector: Kernel stack is corrupted in: %p\n",
87661+ dump_stack();
87662+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
87663 __builtin_return_address(0));
87664 }
87665 EXPORT_SYMBOL(__stack_chk_fail);
87666diff --git a/kernel/pid.c b/kernel/pid.c
87667index 9b9a266..c20ef80 100644
87668--- a/kernel/pid.c
87669+++ b/kernel/pid.c
87670@@ -33,6 +33,7 @@
87671 #include <linux/rculist.h>
87672 #include <linux/bootmem.h>
87673 #include <linux/hash.h>
87674+#include <linux/security.h>
87675 #include <linux/pid_namespace.h>
87676 #include <linux/init_task.h>
87677 #include <linux/syscalls.h>
87678@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
87679
87680 int pid_max = PID_MAX_DEFAULT;
87681
87682-#define RESERVED_PIDS 300
87683+#define RESERVED_PIDS 500
87684
87685 int pid_max_min = RESERVED_PIDS + 1;
87686 int pid_max_max = PID_MAX_LIMIT;
87687@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
87688 */
87689 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
87690 {
87691+ struct task_struct *task;
87692+
87693 rcu_lockdep_assert(rcu_read_lock_held(),
87694 "find_task_by_pid_ns() needs rcu_read_lock()"
87695 " protection");
87696- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
87697+
87698+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
87699+
87700+ if (gr_pid_is_chrooted(task))
87701+ return NULL;
87702+
87703+ return task;
87704 }
87705
87706 struct task_struct *find_task_by_vpid(pid_t vnr)
87707@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
87708 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
87709 }
87710
87711+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
87712+{
87713+ rcu_lockdep_assert(rcu_read_lock_held(),
87714+ "find_task_by_pid_ns() needs rcu_read_lock()"
87715+ " protection");
87716+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
87717+}
87718+
87719 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
87720 {
87721 struct pid *pid;
87722diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
87723index 06c62de..a0ca23f 100644
87724--- a/kernel/pid_namespace.c
87725+++ b/kernel/pid_namespace.c
87726@@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
87727 void __user *buffer, size_t *lenp, loff_t *ppos)
87728 {
87729 struct pid_namespace *pid_ns = task_active_pid_ns(current);
87730- struct ctl_table tmp = *table;
87731+ ctl_table_no_const tmp = *table;
87732
87733 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
87734 return -EPERM;
87735@@ -318,7 +318,9 @@ static void *pidns_get(struct task_struct *task)
87736 struct pid_namespace *ns;
87737
87738 rcu_read_lock();
87739- ns = get_pid_ns(task_active_pid_ns(task));
87740+ ns = task_active_pid_ns(task);
87741+ if (ns)
87742+ get_pid_ns(ns);
87743 rcu_read_unlock();
87744
87745 return ns;
87746diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
87747index c7f31aa..2b44977 100644
87748--- a/kernel/posix-cpu-timers.c
87749+++ b/kernel/posix-cpu-timers.c
87750@@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
87751
87752 static __init int init_posix_cpu_timers(void)
87753 {
87754- struct k_clock process = {
87755+ static struct k_clock process = {
87756 .clock_getres = process_cpu_clock_getres,
87757 .clock_get = process_cpu_clock_get,
87758 .timer_create = process_cpu_timer_create,
87759 .nsleep = process_cpu_nsleep,
87760 .nsleep_restart = process_cpu_nsleep_restart,
87761 };
87762- struct k_clock thread = {
87763+ static struct k_clock thread = {
87764 .clock_getres = thread_cpu_clock_getres,
87765 .clock_get = thread_cpu_clock_get,
87766 .timer_create = thread_cpu_timer_create,
87767diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
87768index 424c2d4..679242f 100644
87769--- a/kernel/posix-timers.c
87770+++ b/kernel/posix-timers.c
87771@@ -43,6 +43,7 @@
87772 #include <linux/hash.h>
87773 #include <linux/posix-clock.h>
87774 #include <linux/posix-timers.h>
87775+#include <linux/grsecurity.h>
87776 #include <linux/syscalls.h>
87777 #include <linux/wait.h>
87778 #include <linux/workqueue.h>
87779@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
87780 * which we beg off on and pass to do_sys_settimeofday().
87781 */
87782
87783-static struct k_clock posix_clocks[MAX_CLOCKS];
87784+static struct k_clock *posix_clocks[MAX_CLOCKS];
87785
87786 /*
87787 * These ones are defined below.
87788@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
87789 */
87790 static __init int init_posix_timers(void)
87791 {
87792- struct k_clock clock_realtime = {
87793+ static struct k_clock clock_realtime = {
87794 .clock_getres = hrtimer_get_res,
87795 .clock_get = posix_clock_realtime_get,
87796 .clock_set = posix_clock_realtime_set,
87797@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
87798 .timer_get = common_timer_get,
87799 .timer_del = common_timer_del,
87800 };
87801- struct k_clock clock_monotonic = {
87802+ static struct k_clock clock_monotonic = {
87803 .clock_getres = hrtimer_get_res,
87804 .clock_get = posix_ktime_get_ts,
87805 .nsleep = common_nsleep,
87806@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
87807 .timer_get = common_timer_get,
87808 .timer_del = common_timer_del,
87809 };
87810- struct k_clock clock_monotonic_raw = {
87811+ static struct k_clock clock_monotonic_raw = {
87812 .clock_getres = hrtimer_get_res,
87813 .clock_get = posix_get_monotonic_raw,
87814 };
87815- struct k_clock clock_realtime_coarse = {
87816+ static struct k_clock clock_realtime_coarse = {
87817 .clock_getres = posix_get_coarse_res,
87818 .clock_get = posix_get_realtime_coarse,
87819 };
87820- struct k_clock clock_monotonic_coarse = {
87821+ static struct k_clock clock_monotonic_coarse = {
87822 .clock_getres = posix_get_coarse_res,
87823 .clock_get = posix_get_monotonic_coarse,
87824 };
87825- struct k_clock clock_tai = {
87826+ static struct k_clock clock_tai = {
87827 .clock_getres = hrtimer_get_res,
87828 .clock_get = posix_get_tai,
87829 .nsleep = common_nsleep,
87830@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
87831 .timer_get = common_timer_get,
87832 .timer_del = common_timer_del,
87833 };
87834- struct k_clock clock_boottime = {
87835+ static struct k_clock clock_boottime = {
87836 .clock_getres = hrtimer_get_res,
87837 .clock_get = posix_get_boottime,
87838 .nsleep = common_nsleep,
87839@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
87840 return;
87841 }
87842
87843- posix_clocks[clock_id] = *new_clock;
87844+ posix_clocks[clock_id] = new_clock;
87845 }
87846 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
87847
87848@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
87849 return (id & CLOCKFD_MASK) == CLOCKFD ?
87850 &clock_posix_dynamic : &clock_posix_cpu;
87851
87852- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
87853+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
87854 return NULL;
87855- return &posix_clocks[id];
87856+ return posix_clocks[id];
87857 }
87858
87859 static int common_timer_create(struct k_itimer *new_timer)
87860@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
87861 struct k_clock *kc = clockid_to_kclock(which_clock);
87862 struct k_itimer *new_timer;
87863 int error, new_timer_id;
87864- sigevent_t event;
87865+ sigevent_t event = { };
87866 int it_id_set = IT_ID_NOT_SET;
87867
87868 if (!kc)
87869@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
87870 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
87871 return -EFAULT;
87872
87873+ /* only the CLOCK_REALTIME clock can be set, all other clocks
87874+ have their clock_set fptr set to a nosettime dummy function
87875+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
87876+ call common_clock_set, which calls do_sys_settimeofday, which
87877+ we hook
87878+ */
87879+
87880 return kc->clock_set(which_clock, &new_tp);
87881 }
87882
87883diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
87884index 2fac9cc..56fef29 100644
87885--- a/kernel/power/Kconfig
87886+++ b/kernel/power/Kconfig
87887@@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
87888 config HIBERNATION
87889 bool "Hibernation (aka 'suspend to disk')"
87890 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
87891+ depends on !GRKERNSEC_KMEM
87892+ depends on !PAX_MEMORY_SANITIZE
87893 select HIBERNATE_CALLBACKS
87894 select LZO_COMPRESS
87895 select LZO_DECOMPRESS
87896diff --git a/kernel/power/process.c b/kernel/power/process.c
87897index 06ec886..9dba35e 100644
87898--- a/kernel/power/process.c
87899+++ b/kernel/power/process.c
87900@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
87901 unsigned int elapsed_msecs;
87902 bool wakeup = false;
87903 int sleep_usecs = USEC_PER_MSEC;
87904+ bool timedout = false;
87905
87906 do_gettimeofday(&start);
87907
87908@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
87909
87910 while (true) {
87911 todo = 0;
87912+ if (time_after(jiffies, end_time))
87913+ timedout = true;
87914 read_lock(&tasklist_lock);
87915 do_each_thread(g, p) {
87916 if (p == current || !freeze_task(p))
87917 continue;
87918
87919- if (!freezer_should_skip(p))
87920+ if (!freezer_should_skip(p)) {
87921 todo++;
87922+ if (timedout) {
87923+ printk(KERN_ERR "Task refusing to freeze:\n");
87924+ sched_show_task(p);
87925+ }
87926+ }
87927 } while_each_thread(g, p);
87928 read_unlock(&tasklist_lock);
87929
87930@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
87931 todo += wq_busy;
87932 }
87933
87934- if (!todo || time_after(jiffies, end_time))
87935+ if (!todo || timedout)
87936 break;
87937
87938 if (pm_wakeup_pending()) {
87939diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
87940index 97fb834..b972b27 100644
87941--- a/kernel/printk/printk.c
87942+++ b/kernel/printk/printk.c
87943@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
87944 if (from_file && type != SYSLOG_ACTION_OPEN)
87945 return 0;
87946
87947+#ifdef CONFIG_GRKERNSEC_DMESG
87948+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
87949+ return -EPERM;
87950+#endif
87951+
87952 if (syslog_action_restricted(type)) {
87953 if (capable(CAP_SYSLOG))
87954 return 0;
87955diff --git a/kernel/profile.c b/kernel/profile.c
87956index 6631e1e..310c266 100644
87957--- a/kernel/profile.c
87958+++ b/kernel/profile.c
87959@@ -37,7 +37,7 @@ struct profile_hit {
87960 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
87961 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
87962
87963-static atomic_t *prof_buffer;
87964+static atomic_unchecked_t *prof_buffer;
87965 static unsigned long prof_len, prof_shift;
87966
87967 int prof_on __read_mostly;
87968@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
87969 hits[i].pc = 0;
87970 continue;
87971 }
87972- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
87973+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
87974 hits[i].hits = hits[i].pc = 0;
87975 }
87976 }
87977@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
87978 * Add the current hit(s) and flush the write-queue out
87979 * to the global buffer:
87980 */
87981- atomic_add(nr_hits, &prof_buffer[pc]);
87982+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
87983 for (i = 0; i < NR_PROFILE_HIT; ++i) {
87984- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
87985+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
87986 hits[i].pc = hits[i].hits = 0;
87987 }
87988 out:
87989@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
87990 {
87991 unsigned long pc;
87992 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
87993- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
87994+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
87995 }
87996 #endif /* !CONFIG_SMP */
87997
87998@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
87999 return -EFAULT;
88000 buf++; p++; count--; read++;
88001 }
88002- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
88003+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
88004 if (copy_to_user(buf, (void *)pnt, count))
88005 return -EFAULT;
88006 read += count;
88007@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
88008 }
88009 #endif
88010 profile_discard_flip_buffers();
88011- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
88012+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
88013 return count;
88014 }
88015
88016diff --git a/kernel/ptrace.c b/kernel/ptrace.c
88017index 1f4bcb3..99cf7ab 100644
88018--- a/kernel/ptrace.c
88019+++ b/kernel/ptrace.c
88020@@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
88021 if (seize)
88022 flags |= PT_SEIZED;
88023 rcu_read_lock();
88024- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88025+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88026 flags |= PT_PTRACE_CAP;
88027 rcu_read_unlock();
88028 task->ptrace = flags;
88029@@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
88030 break;
88031 return -EIO;
88032 }
88033- if (copy_to_user(dst, buf, retval))
88034+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
88035 return -EFAULT;
88036 copied += retval;
88037 src += retval;
88038@@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
88039 bool seized = child->ptrace & PT_SEIZED;
88040 int ret = -EIO;
88041 siginfo_t siginfo, *si;
88042- void __user *datavp = (void __user *) data;
88043+ void __user *datavp = (__force void __user *) data;
88044 unsigned long __user *datalp = datavp;
88045 unsigned long flags;
88046
88047@@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
88048 goto out;
88049 }
88050
88051+ if (gr_handle_ptrace(child, request)) {
88052+ ret = -EPERM;
88053+ goto out_put_task_struct;
88054+ }
88055+
88056 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88057 ret = ptrace_attach(child, request, addr, data);
88058 /*
88059 * Some architectures need to do book-keeping after
88060 * a ptrace attach.
88061 */
88062- if (!ret)
88063+ if (!ret) {
88064 arch_ptrace_attach(child);
88065+ gr_audit_ptrace(child);
88066+ }
88067 goto out_put_task_struct;
88068 }
88069
88070@@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
88071 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
88072 if (copied != sizeof(tmp))
88073 return -EIO;
88074- return put_user(tmp, (unsigned long __user *)data);
88075+ return put_user(tmp, (__force unsigned long __user *)data);
88076 }
88077
88078 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
88079@@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
88080 }
88081
88082 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
88083- compat_long_t addr, compat_long_t data)
88084+ compat_ulong_t addr, compat_ulong_t data)
88085 {
88086 struct task_struct *child;
88087 long ret;
88088@@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
88089 goto out;
88090 }
88091
88092+ if (gr_handle_ptrace(child, request)) {
88093+ ret = -EPERM;
88094+ goto out_put_task_struct;
88095+ }
88096+
88097 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88098 ret = ptrace_attach(child, request, addr, data);
88099 /*
88100 * Some architectures need to do book-keeping after
88101 * a ptrace attach.
88102 */
88103- if (!ret)
88104+ if (!ret) {
88105 arch_ptrace_attach(child);
88106+ gr_audit_ptrace(child);
88107+ }
88108 goto out_put_task_struct;
88109 }
88110
88111diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
88112index 01d5ccb..cdcbee6 100644
88113--- a/kernel/rcu/srcu.c
88114+++ b/kernel/rcu/srcu.c
88115@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
88116
88117 idx = ACCESS_ONCE(sp->completed) & 0x1;
88118 preempt_disable();
88119- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88120+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88121 smp_mb(); /* B */ /* Avoid leaking the critical section. */
88122- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
88123+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
88124 preempt_enable();
88125 return idx;
88126 }
88127diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
88128index 1254f31..16258dc 100644
88129--- a/kernel/rcu/tiny.c
88130+++ b/kernel/rcu/tiny.c
88131@@ -46,7 +46,7 @@
88132 /* Forward declarations for tiny_plugin.h. */
88133 struct rcu_ctrlblk;
88134 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
88135-static void rcu_process_callbacks(struct softirq_action *unused);
88136+static void rcu_process_callbacks(void);
88137 static void __call_rcu(struct rcu_head *head,
88138 void (*func)(struct rcu_head *rcu),
88139 struct rcu_ctrlblk *rcp);
88140@@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
88141 false));
88142 }
88143
88144-static void rcu_process_callbacks(struct softirq_action *unused)
88145+static __latent_entropy void rcu_process_callbacks(void)
88146 {
88147 __rcu_process_callbacks(&rcu_sched_ctrlblk);
88148 __rcu_process_callbacks(&rcu_bh_ctrlblk);
88149diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
88150index 3929cd4..421624d 100644
88151--- a/kernel/rcu/torture.c
88152+++ b/kernel/rcu/torture.c
88153@@ -176,12 +176,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
88154 { 0 };
88155 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
88156 { 0 };
88157-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88158-static atomic_t n_rcu_torture_alloc;
88159-static atomic_t n_rcu_torture_alloc_fail;
88160-static atomic_t n_rcu_torture_free;
88161-static atomic_t n_rcu_torture_mberror;
88162-static atomic_t n_rcu_torture_error;
88163+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88164+static atomic_unchecked_t n_rcu_torture_alloc;
88165+static atomic_unchecked_t n_rcu_torture_alloc_fail;
88166+static atomic_unchecked_t n_rcu_torture_free;
88167+static atomic_unchecked_t n_rcu_torture_mberror;
88168+static atomic_unchecked_t n_rcu_torture_error;
88169 static long n_rcu_torture_barrier_error;
88170 static long n_rcu_torture_boost_ktrerror;
88171 static long n_rcu_torture_boost_rterror;
88172@@ -299,11 +299,11 @@ rcu_torture_alloc(void)
88173
88174 spin_lock_bh(&rcu_torture_lock);
88175 if (list_empty(&rcu_torture_freelist)) {
88176- atomic_inc(&n_rcu_torture_alloc_fail);
88177+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
88178 spin_unlock_bh(&rcu_torture_lock);
88179 return NULL;
88180 }
88181- atomic_inc(&n_rcu_torture_alloc);
88182+ atomic_inc_unchecked(&n_rcu_torture_alloc);
88183 p = rcu_torture_freelist.next;
88184 list_del_init(p);
88185 spin_unlock_bh(&rcu_torture_lock);
88186@@ -316,7 +316,7 @@ rcu_torture_alloc(void)
88187 static void
88188 rcu_torture_free(struct rcu_torture *p)
88189 {
88190- atomic_inc(&n_rcu_torture_free);
88191+ atomic_inc_unchecked(&n_rcu_torture_free);
88192 spin_lock_bh(&rcu_torture_lock);
88193 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
88194 spin_unlock_bh(&rcu_torture_lock);
88195@@ -437,7 +437,7 @@ rcu_torture_cb(struct rcu_head *p)
88196 i = rp->rtort_pipe_count;
88197 if (i > RCU_TORTURE_PIPE_LEN)
88198 i = RCU_TORTURE_PIPE_LEN;
88199- atomic_inc(&rcu_torture_wcount[i]);
88200+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88201 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
88202 rp->rtort_mbtest = 0;
88203 rcu_torture_free(rp);
88204@@ -827,7 +827,7 @@ rcu_torture_writer(void *arg)
88205 i = old_rp->rtort_pipe_count;
88206 if (i > RCU_TORTURE_PIPE_LEN)
88207 i = RCU_TORTURE_PIPE_LEN;
88208- atomic_inc(&rcu_torture_wcount[i]);
88209+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88210 old_rp->rtort_pipe_count++;
88211 if (gp_normal == gp_exp)
88212 exp = !!(rcu_random(&rand) & 0x80);
88213@@ -845,7 +845,7 @@ rcu_torture_writer(void *arg)
88214 i = rp->rtort_pipe_count;
88215 if (i > RCU_TORTURE_PIPE_LEN)
88216 i = RCU_TORTURE_PIPE_LEN;
88217- atomic_inc(&rcu_torture_wcount[i]);
88218+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88219 if (++rp->rtort_pipe_count >=
88220 RCU_TORTURE_PIPE_LEN) {
88221 rp->rtort_mbtest = 0;
88222@@ -944,7 +944,7 @@ static void rcu_torture_timer(unsigned long unused)
88223 return;
88224 }
88225 if (p->rtort_mbtest == 0)
88226- atomic_inc(&n_rcu_torture_mberror);
88227+ atomic_inc_unchecked(&n_rcu_torture_mberror);
88228 spin_lock(&rand_lock);
88229 cur_ops->read_delay(&rand);
88230 n_rcu_torture_timers++;
88231@@ -1014,7 +1014,7 @@ rcu_torture_reader(void *arg)
88232 continue;
88233 }
88234 if (p->rtort_mbtest == 0)
88235- atomic_inc(&n_rcu_torture_mberror);
88236+ atomic_inc_unchecked(&n_rcu_torture_mberror);
88237 cur_ops->read_delay(&rand);
88238 preempt_disable();
88239 pipe_count = p->rtort_pipe_count;
88240@@ -1077,11 +1077,11 @@ rcu_torture_printk(char *page)
88241 rcu_torture_current,
88242 rcu_torture_current_version,
88243 list_empty(&rcu_torture_freelist),
88244- atomic_read(&n_rcu_torture_alloc),
88245- atomic_read(&n_rcu_torture_alloc_fail),
88246- atomic_read(&n_rcu_torture_free));
88247+ atomic_read_unchecked(&n_rcu_torture_alloc),
88248+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
88249+ atomic_read_unchecked(&n_rcu_torture_free));
88250 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
88251- atomic_read(&n_rcu_torture_mberror),
88252+ atomic_read_unchecked(&n_rcu_torture_mberror),
88253 n_rcu_torture_boost_ktrerror,
88254 n_rcu_torture_boost_rterror);
88255 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
88256@@ -1100,14 +1100,14 @@ rcu_torture_printk(char *page)
88257 n_barrier_attempts,
88258 n_rcu_torture_barrier_error);
88259 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
88260- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
88261+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
88262 n_rcu_torture_barrier_error != 0 ||
88263 n_rcu_torture_boost_ktrerror != 0 ||
88264 n_rcu_torture_boost_rterror != 0 ||
88265 n_rcu_torture_boost_failure != 0 ||
88266 i > 1) {
88267 cnt += sprintf(&page[cnt], "!!! ");
88268- atomic_inc(&n_rcu_torture_error);
88269+ atomic_inc_unchecked(&n_rcu_torture_error);
88270 WARN_ON_ONCE(1);
88271 }
88272 cnt += sprintf(&page[cnt], "Reader Pipe: ");
88273@@ -1121,7 +1121,7 @@ rcu_torture_printk(char *page)
88274 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
88275 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
88276 cnt += sprintf(&page[cnt], " %d",
88277- atomic_read(&rcu_torture_wcount[i]));
88278+ atomic_read_unchecked(&rcu_torture_wcount[i]));
88279 }
88280 cnt += sprintf(&page[cnt], "\n");
88281 if (cur_ops->stats)
88282@@ -1836,7 +1836,7 @@ rcu_torture_cleanup(void)
88283
88284 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
88285
88286- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
88287+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
88288 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
88289 else if (n_online_successes != n_online_attempts ||
88290 n_offline_successes != n_offline_attempts)
88291@@ -1958,18 +1958,18 @@ rcu_torture_init(void)
88292
88293 rcu_torture_current = NULL;
88294 rcu_torture_current_version = 0;
88295- atomic_set(&n_rcu_torture_alloc, 0);
88296- atomic_set(&n_rcu_torture_alloc_fail, 0);
88297- atomic_set(&n_rcu_torture_free, 0);
88298- atomic_set(&n_rcu_torture_mberror, 0);
88299- atomic_set(&n_rcu_torture_error, 0);
88300+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
88301+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
88302+ atomic_set_unchecked(&n_rcu_torture_free, 0);
88303+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
88304+ atomic_set_unchecked(&n_rcu_torture_error, 0);
88305 n_rcu_torture_barrier_error = 0;
88306 n_rcu_torture_boost_ktrerror = 0;
88307 n_rcu_torture_boost_rterror = 0;
88308 n_rcu_torture_boost_failure = 0;
88309 n_rcu_torture_boosts = 0;
88310 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
88311- atomic_set(&rcu_torture_wcount[i], 0);
88312+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
88313 for_each_possible_cpu(cpu) {
88314 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
88315 per_cpu(rcu_torture_count, cpu)[i] = 0;
88316diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
88317index dd08198..5ccccbe 100644
88318--- a/kernel/rcu/tree.c
88319+++ b/kernel/rcu/tree.c
88320@@ -383,9 +383,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
88321 rcu_prepare_for_idle(smp_processor_id());
88322 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
88323 smp_mb__before_atomic_inc(); /* See above. */
88324- atomic_inc(&rdtp->dynticks);
88325+ atomic_inc_unchecked(&rdtp->dynticks);
88326 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
88327- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
88328+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
88329
88330 /*
88331 * It is illegal to enter an extended quiescent state while
88332@@ -502,10 +502,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
88333 int user)
88334 {
88335 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
88336- atomic_inc(&rdtp->dynticks);
88337+ atomic_inc_unchecked(&rdtp->dynticks);
88338 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
88339 smp_mb__after_atomic_inc(); /* See above. */
88340- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
88341+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
88342 rcu_cleanup_after_idle(smp_processor_id());
88343 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
88344 if (!user && !is_idle_task(current)) {
88345@@ -625,14 +625,14 @@ void rcu_nmi_enter(void)
88346 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
88347
88348 if (rdtp->dynticks_nmi_nesting == 0 &&
88349- (atomic_read(&rdtp->dynticks) & 0x1))
88350+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
88351 return;
88352 rdtp->dynticks_nmi_nesting++;
88353 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
88354- atomic_inc(&rdtp->dynticks);
88355+ atomic_inc_unchecked(&rdtp->dynticks);
88356 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
88357 smp_mb__after_atomic_inc(); /* See above. */
88358- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
88359+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
88360 }
88361
88362 /**
88363@@ -651,9 +651,9 @@ void rcu_nmi_exit(void)
88364 return;
88365 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
88366 smp_mb__before_atomic_inc(); /* See above. */
88367- atomic_inc(&rdtp->dynticks);
88368+ atomic_inc_unchecked(&rdtp->dynticks);
88369 smp_mb__after_atomic_inc(); /* Force delay to next write. */
88370- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
88371+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
88372 }
88373
88374 /**
88375@@ -666,7 +666,7 @@ void rcu_nmi_exit(void)
88376 */
88377 bool notrace __rcu_is_watching(void)
88378 {
88379- return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
88380+ return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
88381 }
88382
88383 /**
88384@@ -749,7 +749,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
88385 static int dyntick_save_progress_counter(struct rcu_data *rdp,
88386 bool *isidle, unsigned long *maxj)
88387 {
88388- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
88389+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
88390 rcu_sysidle_check_cpu(rdp, isidle, maxj);
88391 return (rdp->dynticks_snap & 0x1) == 0;
88392 }
88393@@ -766,7 +766,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
88394 unsigned int curr;
88395 unsigned int snap;
88396
88397- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
88398+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
88399 snap = (unsigned int)rdp->dynticks_snap;
88400
88401 /*
88402@@ -1412,9 +1412,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
88403 rdp = this_cpu_ptr(rsp->rda);
88404 rcu_preempt_check_blocked_tasks(rnp);
88405 rnp->qsmask = rnp->qsmaskinit;
88406- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
88407+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
88408 WARN_ON_ONCE(rnp->completed != rsp->completed);
88409- ACCESS_ONCE(rnp->completed) = rsp->completed;
88410+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
88411 if (rnp == rdp->mynode)
88412 __note_gp_changes(rsp, rnp, rdp);
88413 rcu_preempt_boost_start_gp(rnp);
88414@@ -1505,7 +1505,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
88415 */
88416 rcu_for_each_node_breadth_first(rsp, rnp) {
88417 raw_spin_lock_irq(&rnp->lock);
88418- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
88419+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
88420 rdp = this_cpu_ptr(rsp->rda);
88421 if (rnp == rdp->mynode)
88422 __note_gp_changes(rsp, rnp, rdp);
88423@@ -1865,7 +1865,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
88424 rsp->qlen += rdp->qlen;
88425 rdp->n_cbs_orphaned += rdp->qlen;
88426 rdp->qlen_lazy = 0;
88427- ACCESS_ONCE(rdp->qlen) = 0;
88428+ ACCESS_ONCE_RW(rdp->qlen) = 0;
88429 }
88430
88431 /*
88432@@ -2111,7 +2111,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
88433 }
88434 smp_mb(); /* List handling before counting for rcu_barrier(). */
88435 rdp->qlen_lazy -= count_lazy;
88436- ACCESS_ONCE(rdp->qlen) -= count;
88437+ ACCESS_ONCE_RW(rdp->qlen) -= count;
88438 rdp->n_cbs_invoked += count;
88439
88440 /* Reinstate batch limit if we have worked down the excess. */
88441@@ -2308,7 +2308,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
88442 /*
88443 * Do RCU core processing for the current CPU.
88444 */
88445-static void rcu_process_callbacks(struct softirq_action *unused)
88446+static void rcu_process_callbacks(void)
88447 {
88448 struct rcu_state *rsp;
88449
88450@@ -2415,7 +2415,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
88451 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
88452 if (debug_rcu_head_queue(head)) {
88453 /* Probable double call_rcu(), so leak the callback. */
88454- ACCESS_ONCE(head->func) = rcu_leak_callback;
88455+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
88456 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
88457 return;
88458 }
88459@@ -2443,7 +2443,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
88460 local_irq_restore(flags);
88461 return;
88462 }
88463- ACCESS_ONCE(rdp->qlen)++;
88464+ ACCESS_ONCE_RW(rdp->qlen)++;
88465 if (lazy)
88466 rdp->qlen_lazy++;
88467 else
88468@@ -2652,11 +2652,11 @@ void synchronize_sched_expedited(void)
88469 * counter wrap on a 32-bit system. Quite a few more CPUs would of
88470 * course be required on a 64-bit system.
88471 */
88472- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
88473+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
88474 (ulong)atomic_long_read(&rsp->expedited_done) +
88475 ULONG_MAX / 8)) {
88476 synchronize_sched();
88477- atomic_long_inc(&rsp->expedited_wrap);
88478+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
88479 return;
88480 }
88481
88482@@ -2664,7 +2664,7 @@ void synchronize_sched_expedited(void)
88483 * Take a ticket. Note that atomic_inc_return() implies a
88484 * full memory barrier.
88485 */
88486- snap = atomic_long_inc_return(&rsp->expedited_start);
88487+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
88488 firstsnap = snap;
88489 get_online_cpus();
88490 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
88491@@ -2677,14 +2677,14 @@ void synchronize_sched_expedited(void)
88492 synchronize_sched_expedited_cpu_stop,
88493 NULL) == -EAGAIN) {
88494 put_online_cpus();
88495- atomic_long_inc(&rsp->expedited_tryfail);
88496+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
88497
88498 /* Check to see if someone else did our work for us. */
88499 s = atomic_long_read(&rsp->expedited_done);
88500 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
88501 /* ensure test happens before caller kfree */
88502 smp_mb__before_atomic_inc(); /* ^^^ */
88503- atomic_long_inc(&rsp->expedited_workdone1);
88504+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
88505 return;
88506 }
88507
88508@@ -2693,7 +2693,7 @@ void synchronize_sched_expedited(void)
88509 udelay(trycount * num_online_cpus());
88510 } else {
88511 wait_rcu_gp(call_rcu_sched);
88512- atomic_long_inc(&rsp->expedited_normal);
88513+ atomic_long_inc_unchecked(&rsp->expedited_normal);
88514 return;
88515 }
88516
88517@@ -2702,7 +2702,7 @@ void synchronize_sched_expedited(void)
88518 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
88519 /* ensure test happens before caller kfree */
88520 smp_mb__before_atomic_inc(); /* ^^^ */
88521- atomic_long_inc(&rsp->expedited_workdone2);
88522+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
88523 return;
88524 }
88525
88526@@ -2714,10 +2714,10 @@ void synchronize_sched_expedited(void)
88527 * period works for us.
88528 */
88529 get_online_cpus();
88530- snap = atomic_long_read(&rsp->expedited_start);
88531+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
88532 smp_mb(); /* ensure read is before try_stop_cpus(). */
88533 }
88534- atomic_long_inc(&rsp->expedited_stoppedcpus);
88535+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
88536
88537 /*
88538 * Everyone up to our most recent fetch is covered by our grace
88539@@ -2726,16 +2726,16 @@ void synchronize_sched_expedited(void)
88540 * than we did already did their update.
88541 */
88542 do {
88543- atomic_long_inc(&rsp->expedited_done_tries);
88544+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
88545 s = atomic_long_read(&rsp->expedited_done);
88546 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
88547 /* ensure test happens before caller kfree */
88548 smp_mb__before_atomic_inc(); /* ^^^ */
88549- atomic_long_inc(&rsp->expedited_done_lost);
88550+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
88551 break;
88552 }
88553 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
88554- atomic_long_inc(&rsp->expedited_done_exit);
88555+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
88556
88557 put_online_cpus();
88558 }
88559@@ -2931,7 +2931,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
88560 * ACCESS_ONCE() to prevent the compiler from speculating
88561 * the increment to precede the early-exit check.
88562 */
88563- ACCESS_ONCE(rsp->n_barrier_done)++;
88564+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
88565 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
88566 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
88567 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
88568@@ -2981,7 +2981,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
88569
88570 /* Increment ->n_barrier_done to prevent duplicate work. */
88571 smp_mb(); /* Keep increment after above mechanism. */
88572- ACCESS_ONCE(rsp->n_barrier_done)++;
88573+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
88574 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
88575 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
88576 smp_mb(); /* Keep increment before caller's subsequent code. */
88577@@ -3026,10 +3026,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
88578 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
88579 init_callback_list(rdp);
88580 rdp->qlen_lazy = 0;
88581- ACCESS_ONCE(rdp->qlen) = 0;
88582+ ACCESS_ONCE_RW(rdp->qlen) = 0;
88583 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
88584 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
88585- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
88586+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
88587 rdp->cpu = cpu;
88588 rdp->rsp = rsp;
88589 rcu_boot_init_nocb_percpu_data(rdp);
88590@@ -3063,8 +3063,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
88591 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
88592 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
88593 rcu_sysidle_init_percpu_data(rdp->dynticks);
88594- atomic_set(&rdp->dynticks->dynticks,
88595- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
88596+ atomic_set_unchecked(&rdp->dynticks->dynticks,
88597+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
88598 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
88599
88600 /* Add CPU to rcu_node bitmasks. */
88601diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
88602index 52be957..365ded3 100644
88603--- a/kernel/rcu/tree.h
88604+++ b/kernel/rcu/tree.h
88605@@ -87,11 +87,11 @@ struct rcu_dynticks {
88606 long long dynticks_nesting; /* Track irq/process nesting level. */
88607 /* Process level is worth LLONG_MAX/2. */
88608 int dynticks_nmi_nesting; /* Track NMI nesting level. */
88609- atomic_t dynticks; /* Even value for idle, else odd. */
88610+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
88611 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
88612 long long dynticks_idle_nesting;
88613 /* irq/process nesting level from idle. */
88614- atomic_t dynticks_idle; /* Even value for idle, else odd. */
88615+ atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
88616 /* "Idle" excludes userspace execution. */
88617 unsigned long dynticks_idle_jiffies;
88618 /* End of last non-NMI non-idle period. */
88619@@ -429,17 +429,17 @@ struct rcu_state {
88620 /* _rcu_barrier(). */
88621 /* End of fields guarded by barrier_mutex. */
88622
88623- atomic_long_t expedited_start; /* Starting ticket. */
88624- atomic_long_t expedited_done; /* Done ticket. */
88625- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
88626- atomic_long_t expedited_tryfail; /* # acquisition failures. */
88627- atomic_long_t expedited_workdone1; /* # done by others #1. */
88628- atomic_long_t expedited_workdone2; /* # done by others #2. */
88629- atomic_long_t expedited_normal; /* # fallbacks to normal. */
88630- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
88631- atomic_long_t expedited_done_tries; /* # tries to update _done. */
88632- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
88633- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
88634+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
88635+ atomic_long_t expedited_done; /* Done ticket. */
88636+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
88637+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
88638+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
88639+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
88640+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
88641+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
88642+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
88643+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
88644+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
88645
88646 unsigned long jiffies_force_qs; /* Time at which to invoke */
88647 /* force_quiescent_state(). */
88648diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
88649index 08a7652..3598c7e 100644
88650--- a/kernel/rcu/tree_plugin.h
88651+++ b/kernel/rcu/tree_plugin.h
88652@@ -749,7 +749,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
88653 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
88654 {
88655 return !rcu_preempted_readers_exp(rnp) &&
88656- ACCESS_ONCE(rnp->expmask) == 0;
88657+ ACCESS_ONCE_RW(rnp->expmask) == 0;
88658 }
88659
88660 /*
88661@@ -905,7 +905,7 @@ void synchronize_rcu_expedited(void)
88662
88663 /* Clean up and exit. */
88664 smp_mb(); /* ensure expedited GP seen before counter increment. */
88665- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
88666+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
88667 unlock_mb_ret:
88668 mutex_unlock(&sync_rcu_preempt_exp_mutex);
88669 mb_ret:
88670@@ -1479,7 +1479,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
88671 free_cpumask_var(cm);
88672 }
88673
88674-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
88675+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
88676 .store = &rcu_cpu_kthread_task,
88677 .thread_should_run = rcu_cpu_kthread_should_run,
88678 .thread_fn = rcu_cpu_kthread,
88679@@ -1946,7 +1946,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
88680 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
88681 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
88682 cpu, ticks_value, ticks_title,
88683- atomic_read(&rdtp->dynticks) & 0xfff,
88684+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
88685 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
88686 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
88687 fast_no_hz);
88688@@ -2109,7 +2109,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
88689
88690 /* Enqueue the callback on the nocb list and update counts. */
88691 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
88692- ACCESS_ONCE(*old_rhpp) = rhp;
88693+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
88694 atomic_long_add(rhcount, &rdp->nocb_q_count);
88695 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
88696
88697@@ -2272,12 +2272,12 @@ static int rcu_nocb_kthread(void *arg)
88698 * Extract queued callbacks, update counts, and wait
88699 * for a grace period to elapse.
88700 */
88701- ACCESS_ONCE(rdp->nocb_head) = NULL;
88702+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
88703 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
88704 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
88705 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
88706- ACCESS_ONCE(rdp->nocb_p_count) += c;
88707- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
88708+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
88709+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
88710 rcu_nocb_wait_gp(rdp);
88711
88712 /* Each pass through the following loop invokes a callback. */
88713@@ -2303,8 +2303,8 @@ static int rcu_nocb_kthread(void *arg)
88714 list = next;
88715 }
88716 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
88717- ACCESS_ONCE(rdp->nocb_p_count) -= c;
88718- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
88719+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
88720+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
88721 rdp->n_nocbs_invoked += c;
88722 }
88723 return 0;
88724@@ -2331,7 +2331,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
88725 t = kthread_run(rcu_nocb_kthread, rdp,
88726 "rcuo%c/%d", rsp->abbr, cpu);
88727 BUG_ON(IS_ERR(t));
88728- ACCESS_ONCE(rdp->nocb_kthread) = t;
88729+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
88730 }
88731 }
88732
88733@@ -2457,11 +2457,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
88734
88735 /* Record start of fully idle period. */
88736 j = jiffies;
88737- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
88738+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
88739 smp_mb__before_atomic_inc();
88740- atomic_inc(&rdtp->dynticks_idle);
88741+ atomic_inc_unchecked(&rdtp->dynticks_idle);
88742 smp_mb__after_atomic_inc();
88743- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
88744+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
88745 }
88746
88747 /*
88748@@ -2526,9 +2526,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
88749
88750 /* Record end of idle period. */
88751 smp_mb__before_atomic_inc();
88752- atomic_inc(&rdtp->dynticks_idle);
88753+ atomic_inc_unchecked(&rdtp->dynticks_idle);
88754 smp_mb__after_atomic_inc();
88755- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
88756+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
88757
88758 /*
88759 * If we are the timekeeping CPU, we are permitted to be non-idle
88760@@ -2569,7 +2569,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
88761 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
88762
88763 /* Pick up current idle and NMI-nesting counter and check. */
88764- cur = atomic_read(&rdtp->dynticks_idle);
88765+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
88766 if (cur & 0x1) {
88767 *isidle = false; /* We are not idle! */
88768 return;
88769@@ -2632,7 +2632,7 @@ static void rcu_sysidle(unsigned long j)
88770 case RCU_SYSIDLE_NOT:
88771
88772 /* First time all are idle, so note a short idle period. */
88773- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
88774+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
88775 break;
88776
88777 case RCU_SYSIDLE_SHORT:
88778@@ -2669,7 +2669,7 @@ static void rcu_sysidle(unsigned long j)
88779 static void rcu_sysidle_cancel(void)
88780 {
88781 smp_mb();
88782- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
88783+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
88784 }
88785
88786 /*
88787@@ -2717,7 +2717,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
88788 smp_mb(); /* grace period precedes setting inuse. */
88789
88790 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
88791- ACCESS_ONCE(rshp->inuse) = 0;
88792+ ACCESS_ONCE_RW(rshp->inuse) = 0;
88793 }
88794
88795 /*
88796diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
88797index 3596797..f78391c 100644
88798--- a/kernel/rcu/tree_trace.c
88799+++ b/kernel/rcu/tree_trace.c
88800@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
88801 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
88802 rdp->passed_quiesce, rdp->qs_pending);
88803 seq_printf(m, " dt=%d/%llx/%d df=%lu",
88804- atomic_read(&rdp->dynticks->dynticks),
88805+ atomic_read_unchecked(&rdp->dynticks->dynticks),
88806 rdp->dynticks->dynticks_nesting,
88807 rdp->dynticks->dynticks_nmi_nesting,
88808 rdp->dynticks_fqs);
88809@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
88810 struct rcu_state *rsp = (struct rcu_state *)m->private;
88811
88812 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",
88813- atomic_long_read(&rsp->expedited_start),
88814+ atomic_long_read_unchecked(&rsp->expedited_start),
88815 atomic_long_read(&rsp->expedited_done),
88816- atomic_long_read(&rsp->expedited_wrap),
88817- atomic_long_read(&rsp->expedited_tryfail),
88818- atomic_long_read(&rsp->expedited_workdone1),
88819- atomic_long_read(&rsp->expedited_workdone2),
88820- atomic_long_read(&rsp->expedited_normal),
88821- atomic_long_read(&rsp->expedited_stoppedcpus),
88822- atomic_long_read(&rsp->expedited_done_tries),
88823- atomic_long_read(&rsp->expedited_done_lost),
88824- atomic_long_read(&rsp->expedited_done_exit));
88825+ atomic_long_read_unchecked(&rsp->expedited_wrap),
88826+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
88827+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
88828+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
88829+ atomic_long_read_unchecked(&rsp->expedited_normal),
88830+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
88831+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
88832+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
88833+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
88834 return 0;
88835 }
88836
88837diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
88838index 6cb3dff..dc5710f 100644
88839--- a/kernel/rcu/update.c
88840+++ b/kernel/rcu/update.c
88841@@ -318,10 +318,10 @@ int rcu_jiffies_till_stall_check(void)
88842 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
88843 */
88844 if (till_stall_check < 3) {
88845- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
88846+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
88847 till_stall_check = 3;
88848 } else if (till_stall_check > 300) {
88849- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
88850+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
88851 till_stall_check = 300;
88852 }
88853 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
88854diff --git a/kernel/resource.c b/kernel/resource.c
88855index 3f285dc..5755f62 100644
88856--- a/kernel/resource.c
88857+++ b/kernel/resource.c
88858@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
88859
88860 static int __init ioresources_init(void)
88861 {
88862+#ifdef CONFIG_GRKERNSEC_PROC_ADD
88863+#ifdef CONFIG_GRKERNSEC_PROC_USER
88864+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
88865+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
88866+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88867+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
88868+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
88869+#endif
88870+#else
88871 proc_create("ioports", 0, NULL, &proc_ioports_operations);
88872 proc_create("iomem", 0, NULL, &proc_iomem_operations);
88873+#endif
88874 return 0;
88875 }
88876 __initcall(ioresources_init);
88877diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
88878index 4a07353..66b5291 100644
88879--- a/kernel/sched/auto_group.c
88880+++ b/kernel/sched/auto_group.c
88881@@ -11,7 +11,7 @@
88882
88883 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
88884 static struct autogroup autogroup_default;
88885-static atomic_t autogroup_seq_nr;
88886+static atomic_unchecked_t autogroup_seq_nr;
88887
88888 void __init autogroup_init(struct task_struct *init_task)
88889 {
88890@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
88891
88892 kref_init(&ag->kref);
88893 init_rwsem(&ag->lock);
88894- ag->id = atomic_inc_return(&autogroup_seq_nr);
88895+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
88896 ag->tg = tg;
88897 #ifdef CONFIG_RT_GROUP_SCHED
88898 /*
88899diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
88900index a63f4dc..349bbb0 100644
88901--- a/kernel/sched/completion.c
88902+++ b/kernel/sched/completion.c
88903@@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
88904 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
88905 * or number of jiffies left till timeout) if completed.
88906 */
88907-long __sched
88908+long __sched __intentional_overflow(-1)
88909 wait_for_completion_interruptible_timeout(struct completion *x,
88910 unsigned long timeout)
88911 {
88912@@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
88913 *
88914 * Return: -ERESTARTSYS if interrupted, 0 if completed.
88915 */
88916-int __sched wait_for_completion_killable(struct completion *x)
88917+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
88918 {
88919 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
88920 if (t == -ERESTARTSYS)
88921@@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
88922 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
88923 * or number of jiffies left till timeout) if completed.
88924 */
88925-long __sched
88926+long __sched __intentional_overflow(-1)
88927 wait_for_completion_killable_timeout(struct completion *x,
88928 unsigned long timeout)
88929 {
88930diff --git a/kernel/sched/core.c b/kernel/sched/core.c
88931index c677510..132bb14 100644
88932--- a/kernel/sched/core.c
88933+++ b/kernel/sched/core.c
88934@@ -1768,7 +1768,7 @@ void set_numabalancing_state(bool enabled)
88935 int sysctl_numa_balancing(struct ctl_table *table, int write,
88936 void __user *buffer, size_t *lenp, loff_t *ppos)
88937 {
88938- struct ctl_table t;
88939+ ctl_table_no_const t;
88940 int err;
88941 int state = numabalancing_enabled;
88942
88943@@ -2893,6 +2893,8 @@ int can_nice(const struct task_struct *p, const int nice)
88944 /* convert nice value [19,-20] to rlimit style value [1,40] */
88945 int nice_rlim = 20 - nice;
88946
88947+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
88948+
88949 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
88950 capable(CAP_SYS_NICE));
88951 }
88952@@ -2926,7 +2928,8 @@ SYSCALL_DEFINE1(nice, int, increment)
88953 if (nice > 19)
88954 nice = 19;
88955
88956- if (increment < 0 && !can_nice(current, nice))
88957+ if (increment < 0 && (!can_nice(current, nice) ||
88958+ gr_handle_chroot_nice()))
88959 return -EPERM;
88960
88961 retval = security_task_setnice(current, nice);
88962@@ -3088,6 +3091,7 @@ recheck:
88963 unsigned long rlim_rtprio =
88964 task_rlimit(p, RLIMIT_RTPRIO);
88965
88966+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
88967 /* can't set/change the rt policy */
88968 if (policy != p->policy && !rlim_rtprio)
88969 return -EPERM;
88970@@ -4254,7 +4258,7 @@ static void migrate_tasks(unsigned int dead_cpu)
88971
88972 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
88973
88974-static struct ctl_table sd_ctl_dir[] = {
88975+static ctl_table_no_const sd_ctl_dir[] __read_only = {
88976 {
88977 .procname = "sched_domain",
88978 .mode = 0555,
88979@@ -4271,17 +4275,17 @@ static struct ctl_table sd_ctl_root[] = {
88980 {}
88981 };
88982
88983-static struct ctl_table *sd_alloc_ctl_entry(int n)
88984+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
88985 {
88986- struct ctl_table *entry =
88987+ ctl_table_no_const *entry =
88988 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
88989
88990 return entry;
88991 }
88992
88993-static void sd_free_ctl_entry(struct ctl_table **tablep)
88994+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
88995 {
88996- struct ctl_table *entry;
88997+ ctl_table_no_const *entry;
88998
88999 /*
89000 * In the intermediate directories, both the child directory and
89001@@ -4289,22 +4293,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
89002 * will always be set. In the lowest directory the names are
89003 * static strings and all have proc handlers.
89004 */
89005- for (entry = *tablep; entry->mode; entry++) {
89006- if (entry->child)
89007- sd_free_ctl_entry(&entry->child);
89008+ for (entry = tablep; entry->mode; entry++) {
89009+ if (entry->child) {
89010+ sd_free_ctl_entry(entry->child);
89011+ pax_open_kernel();
89012+ entry->child = NULL;
89013+ pax_close_kernel();
89014+ }
89015 if (entry->proc_handler == NULL)
89016 kfree(entry->procname);
89017 }
89018
89019- kfree(*tablep);
89020- *tablep = NULL;
89021+ kfree(tablep);
89022 }
89023
89024 static int min_load_idx = 0;
89025 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
89026
89027 static void
89028-set_table_entry(struct ctl_table *entry,
89029+set_table_entry(ctl_table_no_const *entry,
89030 const char *procname, void *data, int maxlen,
89031 umode_t mode, proc_handler *proc_handler,
89032 bool load_idx)
89033@@ -4324,7 +4331,7 @@ set_table_entry(struct ctl_table *entry,
89034 static struct ctl_table *
89035 sd_alloc_ctl_domain_table(struct sched_domain *sd)
89036 {
89037- struct ctl_table *table = sd_alloc_ctl_entry(13);
89038+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
89039
89040 if (table == NULL)
89041 return NULL;
89042@@ -4359,9 +4366,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
89043 return table;
89044 }
89045
89046-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
89047+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
89048 {
89049- struct ctl_table *entry, *table;
89050+ ctl_table_no_const *entry, *table;
89051 struct sched_domain *sd;
89052 int domain_num = 0, i;
89053 char buf[32];
89054@@ -4388,11 +4395,13 @@ static struct ctl_table_header *sd_sysctl_header;
89055 static void register_sched_domain_sysctl(void)
89056 {
89057 int i, cpu_num = num_possible_cpus();
89058- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
89059+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
89060 char buf[32];
89061
89062 WARN_ON(sd_ctl_dir[0].child);
89063+ pax_open_kernel();
89064 sd_ctl_dir[0].child = entry;
89065+ pax_close_kernel();
89066
89067 if (entry == NULL)
89068 return;
89069@@ -4415,8 +4424,12 @@ static void unregister_sched_domain_sysctl(void)
89070 if (sd_sysctl_header)
89071 unregister_sysctl_table(sd_sysctl_header);
89072 sd_sysctl_header = NULL;
89073- if (sd_ctl_dir[0].child)
89074- sd_free_ctl_entry(&sd_ctl_dir[0].child);
89075+ if (sd_ctl_dir[0].child) {
89076+ sd_free_ctl_entry(sd_ctl_dir[0].child);
89077+ pax_open_kernel();
89078+ sd_ctl_dir[0].child = NULL;
89079+ pax_close_kernel();
89080+ }
89081 }
89082 #else
89083 static void register_sched_domain_sysctl(void)
89084diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
89085index ce501de..1805320 100644
89086--- a/kernel/sched/fair.c
89087+++ b/kernel/sched/fair.c
89088@@ -1652,7 +1652,7 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
89089
89090 static void reset_ptenuma_scan(struct task_struct *p)
89091 {
89092- ACCESS_ONCE(p->mm->numa_scan_seq)++;
89093+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
89094 p->mm->numa_scan_offset = 0;
89095 }
89096
89097@@ -6863,7 +6863,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
89098 * run_rebalance_domains is triggered when needed from the scheduler tick.
89099 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
89100 */
89101-static void run_rebalance_domains(struct softirq_action *h)
89102+static __latent_entropy void run_rebalance_domains(void)
89103 {
89104 int this_cpu = smp_processor_id();
89105 struct rq *this_rq = cpu_rq(this_cpu);
89106diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
89107index 88c85b2..a1dec86 100644
89108--- a/kernel/sched/sched.h
89109+++ b/kernel/sched/sched.h
89110@@ -1035,7 +1035,7 @@ struct sched_class {
89111 #ifdef CONFIG_FAIR_GROUP_SCHED
89112 void (*task_move_group) (struct task_struct *p, int on_rq);
89113 #endif
89114-};
89115+} __do_const;
89116
89117 #define sched_class_highest (&stop_sched_class)
89118 #define for_each_class(class) \
89119diff --git a/kernel/signal.c b/kernel/signal.c
89120index 940b30e..7fd6041 100644
89121--- a/kernel/signal.c
89122+++ b/kernel/signal.c
89123@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
89124
89125 int print_fatal_signals __read_mostly;
89126
89127-static void __user *sig_handler(struct task_struct *t, int sig)
89128+static __sighandler_t sig_handler(struct task_struct *t, int sig)
89129 {
89130 return t->sighand->action[sig - 1].sa.sa_handler;
89131 }
89132
89133-static int sig_handler_ignored(void __user *handler, int sig)
89134+static int sig_handler_ignored(__sighandler_t handler, int sig)
89135 {
89136 /* Is it explicitly or implicitly ignored? */
89137 return handler == SIG_IGN ||
89138@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
89139
89140 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
89141 {
89142- void __user *handler;
89143+ __sighandler_t handler;
89144
89145 handler = sig_handler(t, sig);
89146
89147@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
89148 atomic_inc(&user->sigpending);
89149 rcu_read_unlock();
89150
89151+ if (!override_rlimit)
89152+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
89153+
89154 if (override_rlimit ||
89155 atomic_read(&user->sigpending) <=
89156 task_rlimit(t, RLIMIT_SIGPENDING)) {
89157@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
89158
89159 int unhandled_signal(struct task_struct *tsk, int sig)
89160 {
89161- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
89162+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
89163 if (is_global_init(tsk))
89164 return 1;
89165 if (handler != SIG_IGN && handler != SIG_DFL)
89166@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
89167 }
89168 }
89169
89170+ /* allow glibc communication via tgkill to other threads in our
89171+ thread group */
89172+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
89173+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
89174+ && gr_handle_signal(t, sig))
89175+ return -EPERM;
89176+
89177 return security_task_kill(t, info, sig, 0);
89178 }
89179
89180@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
89181 return send_signal(sig, info, p, 1);
89182 }
89183
89184-static int
89185+int
89186 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89187 {
89188 return send_signal(sig, info, t, 0);
89189@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89190 unsigned long int flags;
89191 int ret, blocked, ignored;
89192 struct k_sigaction *action;
89193+ int is_unhandled = 0;
89194
89195 spin_lock_irqsave(&t->sighand->siglock, flags);
89196 action = &t->sighand->action[sig-1];
89197@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89198 }
89199 if (action->sa.sa_handler == SIG_DFL)
89200 t->signal->flags &= ~SIGNAL_UNKILLABLE;
89201+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
89202+ is_unhandled = 1;
89203 ret = specific_send_sig_info(sig, info, t);
89204 spin_unlock_irqrestore(&t->sighand->siglock, flags);
89205
89206+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
89207+ normal operation */
89208+ if (is_unhandled) {
89209+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
89210+ gr_handle_crash(t, sig);
89211+ }
89212+
89213 return ret;
89214 }
89215
89216@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
89217 ret = check_kill_permission(sig, info, p);
89218 rcu_read_unlock();
89219
89220- if (!ret && sig)
89221+ if (!ret && sig) {
89222 ret = do_send_sig_info(sig, info, p, true);
89223+ if (!ret)
89224+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
89225+ }
89226
89227 return ret;
89228 }
89229@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
89230 int error = -ESRCH;
89231
89232 rcu_read_lock();
89233- p = find_task_by_vpid(pid);
89234+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
89235+ /* allow glibc communication via tgkill to other threads in our
89236+ thread group */
89237+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
89238+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
89239+ p = find_task_by_vpid_unrestricted(pid);
89240+ else
89241+#endif
89242+ p = find_task_by_vpid(pid);
89243 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
89244 error = check_kill_permission(sig, info, p);
89245 /*
89246@@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
89247 }
89248 seg = get_fs();
89249 set_fs(KERNEL_DS);
89250- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
89251- (stack_t __force __user *) &uoss,
89252+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
89253+ (stack_t __force_user *) &uoss,
89254 compat_user_stack_pointer());
89255 set_fs(seg);
89256 if (ret >= 0 && uoss_ptr) {
89257diff --git a/kernel/smpboot.c b/kernel/smpboot.c
89258index eb89e18..a4e6792 100644
89259--- a/kernel/smpboot.c
89260+++ b/kernel/smpboot.c
89261@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
89262 }
89263 smpboot_unpark_thread(plug_thread, cpu);
89264 }
89265- list_add(&plug_thread->list, &hotplug_threads);
89266+ pax_list_add(&plug_thread->list, &hotplug_threads);
89267 out:
89268 mutex_unlock(&smpboot_threads_lock);
89269 return ret;
89270@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
89271 {
89272 get_online_cpus();
89273 mutex_lock(&smpboot_threads_lock);
89274- list_del(&plug_thread->list);
89275+ pax_list_del(&plug_thread->list);
89276 smpboot_destroy_threads(plug_thread);
89277 mutex_unlock(&smpboot_threads_lock);
89278 put_online_cpus();
89279diff --git a/kernel/softirq.c b/kernel/softirq.c
89280index 11025cc..bc0e4dc 100644
89281--- a/kernel/softirq.c
89282+++ b/kernel/softirq.c
89283@@ -50,11 +50,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
89284 EXPORT_SYMBOL(irq_stat);
89285 #endif
89286
89287-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
89288+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
89289
89290 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
89291
89292-char *softirq_to_name[NR_SOFTIRQS] = {
89293+const char * const softirq_to_name[NR_SOFTIRQS] = {
89294 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
89295 "TASKLET", "SCHED", "HRTIMER", "RCU"
89296 };
89297@@ -250,7 +250,7 @@ restart:
89298 kstat_incr_softirqs_this_cpu(vec_nr);
89299
89300 trace_softirq_entry(vec_nr);
89301- h->action(h);
89302+ h->action();
89303 trace_softirq_exit(vec_nr);
89304 if (unlikely(prev_count != preempt_count())) {
89305 printk(KERN_ERR "huh, entered softirq %u %s %p"
89306@@ -419,7 +419,7 @@ void __raise_softirq_irqoff(unsigned int nr)
89307 or_softirq_pending(1UL << nr);
89308 }
89309
89310-void open_softirq(int nr, void (*action)(struct softirq_action *))
89311+void __init open_softirq(int nr, void (*action)(void))
89312 {
89313 softirq_vec[nr].action = action;
89314 }
89315@@ -475,7 +475,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
89316
89317 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
89318
89319-static void tasklet_action(struct softirq_action *a)
89320+static __latent_entropy void tasklet_action(void)
89321 {
89322 struct tasklet_struct *list;
89323
89324@@ -510,7 +510,7 @@ static void tasklet_action(struct softirq_action *a)
89325 }
89326 }
89327
89328-static void tasklet_hi_action(struct softirq_action *a)
89329+static __latent_entropy void tasklet_hi_action(void)
89330 {
89331 struct tasklet_struct *list;
89332
89333@@ -740,7 +740,7 @@ static struct notifier_block cpu_nfb = {
89334 .notifier_call = cpu_callback
89335 };
89336
89337-static struct smp_hotplug_thread softirq_threads = {
89338+static struct smp_hotplug_thread softirq_threads __read_only = {
89339 .store = &ksoftirqd,
89340 .thread_should_run = ksoftirqd_should_run,
89341 .thread_fn = run_ksoftirqd,
89342diff --git a/kernel/sys.c b/kernel/sys.c
89343index c723113..46bf922 100644
89344--- a/kernel/sys.c
89345+++ b/kernel/sys.c
89346@@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
89347 error = -EACCES;
89348 goto out;
89349 }
89350+
89351+ if (gr_handle_chroot_setpriority(p, niceval)) {
89352+ error = -EACCES;
89353+ goto out;
89354+ }
89355+
89356 no_nice = security_task_setnice(p, niceval);
89357 if (no_nice) {
89358 error = no_nice;
89359@@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
89360 goto error;
89361 }
89362
89363+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
89364+ goto error;
89365+
89366 if (rgid != (gid_t) -1 ||
89367 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
89368 new->sgid = new->egid;
89369@@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
89370 old = current_cred();
89371
89372 retval = -EPERM;
89373+
89374+ if (gr_check_group_change(kgid, kgid, kgid))
89375+ goto error;
89376+
89377 if (ns_capable(old->user_ns, CAP_SETGID))
89378 new->gid = new->egid = new->sgid = new->fsgid = kgid;
89379 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
89380@@ -403,7 +416,7 @@ error:
89381 /*
89382 * change the user struct in a credentials set to match the new UID
89383 */
89384-static int set_user(struct cred *new)
89385+int set_user(struct cred *new)
89386 {
89387 struct user_struct *new_user;
89388
89389@@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
89390 goto error;
89391 }
89392
89393+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
89394+ goto error;
89395+
89396 if (!uid_eq(new->uid, old->uid)) {
89397 retval = set_user(new);
89398 if (retval < 0)
89399@@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
89400 old = current_cred();
89401
89402 retval = -EPERM;
89403+
89404+ if (gr_check_crash_uid(kuid))
89405+ goto error;
89406+ if (gr_check_user_change(kuid, kuid, kuid))
89407+ goto error;
89408+
89409 if (ns_capable(old->user_ns, CAP_SETUID)) {
89410 new->suid = new->uid = kuid;
89411 if (!uid_eq(kuid, old->uid)) {
89412@@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
89413 goto error;
89414 }
89415
89416+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
89417+ goto error;
89418+
89419 if (ruid != (uid_t) -1) {
89420 new->uid = kruid;
89421 if (!uid_eq(kruid, old->uid)) {
89422@@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
89423 goto error;
89424 }
89425
89426+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
89427+ goto error;
89428+
89429 if (rgid != (gid_t) -1)
89430 new->gid = krgid;
89431 if (egid != (gid_t) -1)
89432@@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
89433 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
89434 ns_capable(old->user_ns, CAP_SETUID)) {
89435 if (!uid_eq(kuid, old->fsuid)) {
89436+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
89437+ goto error;
89438+
89439 new->fsuid = kuid;
89440 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
89441 goto change_okay;
89442 }
89443 }
89444
89445+error:
89446 abort_creds(new);
89447 return old_fsuid;
89448
89449@@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
89450 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
89451 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
89452 ns_capable(old->user_ns, CAP_SETGID)) {
89453+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
89454+ goto error;
89455+
89456 if (!gid_eq(kgid, old->fsgid)) {
89457 new->fsgid = kgid;
89458 goto change_okay;
89459 }
89460 }
89461
89462+error:
89463 abort_creds(new);
89464 return old_fsgid;
89465
89466@@ -1168,19 +1204,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
89467 return -EFAULT;
89468
89469 down_read(&uts_sem);
89470- error = __copy_to_user(&name->sysname, &utsname()->sysname,
89471+ error = __copy_to_user(name->sysname, &utsname()->sysname,
89472 __OLD_UTS_LEN);
89473 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
89474- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
89475+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
89476 __OLD_UTS_LEN);
89477 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
89478- error |= __copy_to_user(&name->release, &utsname()->release,
89479+ error |= __copy_to_user(name->release, &utsname()->release,
89480 __OLD_UTS_LEN);
89481 error |= __put_user(0, name->release + __OLD_UTS_LEN);
89482- error |= __copy_to_user(&name->version, &utsname()->version,
89483+ error |= __copy_to_user(name->version, &utsname()->version,
89484 __OLD_UTS_LEN);
89485 error |= __put_user(0, name->version + __OLD_UTS_LEN);
89486- error |= __copy_to_user(&name->machine, &utsname()->machine,
89487+ error |= __copy_to_user(name->machine, &utsname()->machine,
89488 __OLD_UTS_LEN);
89489 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
89490 up_read(&uts_sem);
89491@@ -1382,6 +1418,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
89492 */
89493 new_rlim->rlim_cur = 1;
89494 }
89495+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
89496+ is changed to a lower value. Since tasks can be created by the same
89497+ user in between this limit change and an execve by this task, force
89498+ a recheck only for this task by setting PF_NPROC_EXCEEDED
89499+ */
89500+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
89501+ tsk->flags |= PF_NPROC_EXCEEDED;
89502 }
89503 if (!retval) {
89504 if (old_rlim)
89505diff --git a/kernel/sysctl.c b/kernel/sysctl.c
89506index 06962ba..a54d45e 100644
89507--- a/kernel/sysctl.c
89508+++ b/kernel/sysctl.c
89509@@ -93,7 +93,6 @@
89510
89511
89512 #if defined(CONFIG_SYSCTL)
89513-
89514 /* External variables not in a header file. */
89515 extern int sysctl_overcommit_memory;
89516 extern int sysctl_overcommit_ratio;
89517@@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
89518
89519 /* Constants used for minimum and maximum */
89520 #ifdef CONFIG_LOCKUP_DETECTOR
89521-static int sixty = 60;
89522+static int sixty __read_only = 60;
89523 #endif
89524
89525-static int zero;
89526-static int __maybe_unused one = 1;
89527-static int __maybe_unused two = 2;
89528-static int __maybe_unused three = 3;
89529-static unsigned long one_ul = 1;
89530-static int one_hundred = 100;
89531+static int neg_one __read_only = -1;
89532+static int zero __read_only = 0;
89533+static int __maybe_unused one __read_only = 1;
89534+static int __maybe_unused two __read_only = 2;
89535+static int __maybe_unused three __read_only = 3;
89536+static unsigned long one_ul __read_only = 1;
89537+static int one_hundred __read_only = 100;
89538 #ifdef CONFIG_PRINTK
89539-static int ten_thousand = 10000;
89540+static int ten_thousand __read_only = 10000;
89541 #endif
89542
89543 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
89544@@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
89545 void __user *buffer, size_t *lenp, loff_t *ppos);
89546 #endif
89547
89548-#ifdef CONFIG_PRINTK
89549 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89550 void __user *buffer, size_t *lenp, loff_t *ppos);
89551-#endif
89552
89553 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
89554 void __user *buffer, size_t *lenp, loff_t *ppos);
89555@@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
89556
89557 #endif
89558
89559+extern struct ctl_table grsecurity_table[];
89560+
89561 static struct ctl_table kern_table[];
89562 static struct ctl_table vm_table[];
89563 static struct ctl_table fs_table[];
89564@@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
89565 int sysctl_legacy_va_layout;
89566 #endif
89567
89568+#ifdef CONFIG_PAX_SOFTMODE
89569+static ctl_table pax_table[] = {
89570+ {
89571+ .procname = "softmode",
89572+ .data = &pax_softmode,
89573+ .maxlen = sizeof(unsigned int),
89574+ .mode = 0600,
89575+ .proc_handler = &proc_dointvec,
89576+ },
89577+
89578+ { }
89579+};
89580+#endif
89581+
89582 /* The default sysctl tables: */
89583
89584 static struct ctl_table sysctl_base_table[] = {
89585@@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
89586 #endif
89587
89588 static struct ctl_table kern_table[] = {
89589+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
89590+ {
89591+ .procname = "grsecurity",
89592+ .mode = 0500,
89593+ .child = grsecurity_table,
89594+ },
89595+#endif
89596+
89597+#ifdef CONFIG_PAX_SOFTMODE
89598+ {
89599+ .procname = "pax",
89600+ .mode = 0500,
89601+ .child = pax_table,
89602+ },
89603+#endif
89604+
89605 {
89606 .procname = "sched_child_runs_first",
89607 .data = &sysctl_sched_child_runs_first,
89608@@ -629,7 +659,7 @@ static struct ctl_table kern_table[] = {
89609 .data = &modprobe_path,
89610 .maxlen = KMOD_PATH_LEN,
89611 .mode = 0644,
89612- .proc_handler = proc_dostring,
89613+ .proc_handler = proc_dostring_modpriv,
89614 },
89615 {
89616 .procname = "modules_disabled",
89617@@ -796,16 +826,20 @@ static struct ctl_table kern_table[] = {
89618 .extra1 = &zero,
89619 .extra2 = &one,
89620 },
89621+#endif
89622 {
89623 .procname = "kptr_restrict",
89624 .data = &kptr_restrict,
89625 .maxlen = sizeof(int),
89626 .mode = 0644,
89627 .proc_handler = proc_dointvec_minmax_sysadmin,
89628+#ifdef CONFIG_GRKERNSEC_HIDESYM
89629+ .extra1 = &two,
89630+#else
89631 .extra1 = &zero,
89632+#endif
89633 .extra2 = &two,
89634 },
89635-#endif
89636 {
89637 .procname = "ngroups_max",
89638 .data = &ngroups_max,
89639@@ -1048,10 +1082,17 @@ static struct ctl_table kern_table[] = {
89640 */
89641 {
89642 .procname = "perf_event_paranoid",
89643- .data = &sysctl_perf_event_paranoid,
89644- .maxlen = sizeof(sysctl_perf_event_paranoid),
89645+ .data = &sysctl_perf_event_legitimately_concerned,
89646+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
89647 .mode = 0644,
89648- .proc_handler = proc_dointvec,
89649+ /* go ahead, be a hero */
89650+ .proc_handler = proc_dointvec_minmax_sysadmin,
89651+ .extra1 = &neg_one,
89652+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89653+ .extra2 = &three,
89654+#else
89655+ .extra2 = &two,
89656+#endif
89657 },
89658 {
89659 .procname = "perf_event_mlock_kb",
89660@@ -1315,6 +1356,13 @@ static struct ctl_table vm_table[] = {
89661 .proc_handler = proc_dointvec_minmax,
89662 .extra1 = &zero,
89663 },
89664+ {
89665+ .procname = "heap_stack_gap",
89666+ .data = &sysctl_heap_stack_gap,
89667+ .maxlen = sizeof(sysctl_heap_stack_gap),
89668+ .mode = 0644,
89669+ .proc_handler = proc_doulongvec_minmax,
89670+ },
89671 #else
89672 {
89673 .procname = "nr_trim_pages",
89674@@ -1779,6 +1827,16 @@ int proc_dostring(struct ctl_table *table, int write,
89675 buffer, lenp, ppos);
89676 }
89677
89678+int proc_dostring_modpriv(struct ctl_table *table, int write,
89679+ void __user *buffer, size_t *lenp, loff_t *ppos)
89680+{
89681+ if (write && !capable(CAP_SYS_MODULE))
89682+ return -EPERM;
89683+
89684+ return _proc_do_string(table->data, table->maxlen, write,
89685+ buffer, lenp, ppos);
89686+}
89687+
89688 static size_t proc_skip_spaces(char **buf)
89689 {
89690 size_t ret;
89691@@ -1884,6 +1942,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
89692 len = strlen(tmp);
89693 if (len > *size)
89694 len = *size;
89695+ if (len > sizeof(tmp))
89696+ len = sizeof(tmp);
89697 if (copy_to_user(*buf, tmp, len))
89698 return -EFAULT;
89699 *size -= len;
89700@@ -2048,7 +2108,7 @@ int proc_dointvec(struct ctl_table *table, int write,
89701 static int proc_taint(struct ctl_table *table, int write,
89702 void __user *buffer, size_t *lenp, loff_t *ppos)
89703 {
89704- struct ctl_table t;
89705+ ctl_table_no_const t;
89706 unsigned long tmptaint = get_taint();
89707 int err;
89708
89709@@ -2076,7 +2136,6 @@ static int proc_taint(struct ctl_table *table, int write,
89710 return err;
89711 }
89712
89713-#ifdef CONFIG_PRINTK
89714 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89715 void __user *buffer, size_t *lenp, loff_t *ppos)
89716 {
89717@@ -2085,7 +2144,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89718
89719 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
89720 }
89721-#endif
89722
89723 struct do_proc_dointvec_minmax_conv_param {
89724 int *min;
89725@@ -2632,6 +2690,12 @@ int proc_dostring(struct ctl_table *table, int write,
89726 return -ENOSYS;
89727 }
89728
89729+int proc_dostring_modpriv(struct ctl_table *table, int write,
89730+ void __user *buffer, size_t *lenp, loff_t *ppos)
89731+{
89732+ return -ENOSYS;
89733+}
89734+
89735 int proc_dointvec(struct ctl_table *table, int write,
89736 void __user *buffer, size_t *lenp, loff_t *ppos)
89737 {
89738@@ -2688,5 +2752,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
89739 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
89740 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
89741 EXPORT_SYMBOL(proc_dostring);
89742+EXPORT_SYMBOL(proc_dostring_modpriv);
89743 EXPORT_SYMBOL(proc_doulongvec_minmax);
89744 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
89745diff --git a/kernel/taskstats.c b/kernel/taskstats.c
89746index 13d2f7c..c93d0b0 100644
89747--- a/kernel/taskstats.c
89748+++ b/kernel/taskstats.c
89749@@ -28,9 +28,12 @@
89750 #include <linux/fs.h>
89751 #include <linux/file.h>
89752 #include <linux/pid_namespace.h>
89753+#include <linux/grsecurity.h>
89754 #include <net/genetlink.h>
89755 #include <linux/atomic.h>
89756
89757+extern int gr_is_taskstats_denied(int pid);
89758+
89759 /*
89760 * Maximum length of a cpumask that can be specified in
89761 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
89762@@ -576,6 +579,9 @@ err:
89763
89764 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
89765 {
89766+ if (gr_is_taskstats_denied(current->pid))
89767+ return -EACCES;
89768+
89769 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
89770 return cmd_attr_register_cpumask(info);
89771 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
89772diff --git a/kernel/time.c b/kernel/time.c
89773index 7c7964c..2a0d412 100644
89774--- a/kernel/time.c
89775+++ b/kernel/time.c
89776@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
89777 return error;
89778
89779 if (tz) {
89780+ /* we log in do_settimeofday called below, so don't log twice
89781+ */
89782+ if (!tv)
89783+ gr_log_timechange();
89784+
89785 sys_tz = *tz;
89786 update_vsyscall_tz();
89787 if (firsttime) {
89788diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
89789index 88c9c65..7497ebc 100644
89790--- a/kernel/time/alarmtimer.c
89791+++ b/kernel/time/alarmtimer.c
89792@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
89793 struct platform_device *pdev;
89794 int error = 0;
89795 int i;
89796- struct k_clock alarm_clock = {
89797+ static struct k_clock alarm_clock = {
89798 .clock_getres = alarm_clock_getres,
89799 .clock_get = alarm_clock_get,
89800 .timer_create = alarm_timer_create,
89801diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
89802index b415457..c26876d 100644
89803--- a/kernel/time/timekeeping.c
89804+++ b/kernel/time/timekeeping.c
89805@@ -15,6 +15,7 @@
89806 #include <linux/init.h>
89807 #include <linux/mm.h>
89808 #include <linux/sched.h>
89809+#include <linux/grsecurity.h>
89810 #include <linux/syscore_ops.h>
89811 #include <linux/clocksource.h>
89812 #include <linux/jiffies.h>
89813@@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
89814 if (!timespec_valid_strict(tv))
89815 return -EINVAL;
89816
89817+ gr_log_timechange();
89818+
89819 raw_spin_lock_irqsave(&timekeeper_lock, flags);
89820 write_seqcount_begin(&timekeeper_seq);
89821
89822diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
89823index 61ed862..3b52c65 100644
89824--- a/kernel/time/timer_list.c
89825+++ b/kernel/time/timer_list.c
89826@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
89827
89828 static void print_name_offset(struct seq_file *m, void *sym)
89829 {
89830+#ifdef CONFIG_GRKERNSEC_HIDESYM
89831+ SEQ_printf(m, "<%p>", NULL);
89832+#else
89833 char symname[KSYM_NAME_LEN];
89834
89835 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
89836 SEQ_printf(m, "<%pK>", sym);
89837 else
89838 SEQ_printf(m, "%s", symname);
89839+#endif
89840 }
89841
89842 static void
89843@@ -119,7 +123,11 @@ next_one:
89844 static void
89845 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
89846 {
89847+#ifdef CONFIG_GRKERNSEC_HIDESYM
89848+ SEQ_printf(m, " .base: %p\n", NULL);
89849+#else
89850 SEQ_printf(m, " .base: %pK\n", base);
89851+#endif
89852 SEQ_printf(m, " .index: %d\n",
89853 base->index);
89854 SEQ_printf(m, " .resolution: %Lu nsecs\n",
89855@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
89856 {
89857 struct proc_dir_entry *pe;
89858
89859+#ifdef CONFIG_GRKERNSEC_PROC_ADD
89860+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
89861+#else
89862 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
89863+#endif
89864 if (!pe)
89865 return -ENOMEM;
89866 return 0;
89867diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
89868index 1fb08f2..ca4bb1e 100644
89869--- a/kernel/time/timer_stats.c
89870+++ b/kernel/time/timer_stats.c
89871@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
89872 static unsigned long nr_entries;
89873 static struct entry entries[MAX_ENTRIES];
89874
89875-static atomic_t overflow_count;
89876+static atomic_unchecked_t overflow_count;
89877
89878 /*
89879 * The entries are in a hash-table, for fast lookup:
89880@@ -140,7 +140,7 @@ static void reset_entries(void)
89881 nr_entries = 0;
89882 memset(entries, 0, sizeof(entries));
89883 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
89884- atomic_set(&overflow_count, 0);
89885+ atomic_set_unchecked(&overflow_count, 0);
89886 }
89887
89888 static struct entry *alloc_entry(void)
89889@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
89890 if (likely(entry))
89891 entry->count++;
89892 else
89893- atomic_inc(&overflow_count);
89894+ atomic_inc_unchecked(&overflow_count);
89895
89896 out_unlock:
89897 raw_spin_unlock_irqrestore(lock, flags);
89898@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
89899
89900 static void print_name_offset(struct seq_file *m, unsigned long addr)
89901 {
89902+#ifdef CONFIG_GRKERNSEC_HIDESYM
89903+ seq_printf(m, "<%p>", NULL);
89904+#else
89905 char symname[KSYM_NAME_LEN];
89906
89907 if (lookup_symbol_name(addr, symname) < 0)
89908- seq_printf(m, "<%p>", (void *)addr);
89909+ seq_printf(m, "<%pK>", (void *)addr);
89910 else
89911 seq_printf(m, "%s", symname);
89912+#endif
89913 }
89914
89915 static int tstats_show(struct seq_file *m, void *v)
89916@@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
89917
89918 seq_puts(m, "Timer Stats Version: v0.3\n");
89919 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
89920- if (atomic_read(&overflow_count))
89921- seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
89922+ if (atomic_read_unchecked(&overflow_count))
89923+ seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
89924 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
89925
89926 for (i = 0; i < nr_entries; i++) {
89927@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
89928 {
89929 struct proc_dir_entry *pe;
89930
89931+#ifdef CONFIG_GRKERNSEC_PROC_ADD
89932+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
89933+#else
89934 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
89935+#endif
89936 if (!pe)
89937 return -ENOMEM;
89938 return 0;
89939diff --git a/kernel/timer.c b/kernel/timer.c
89940index accfd24..e00f0c0 100644
89941--- a/kernel/timer.c
89942+++ b/kernel/timer.c
89943@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
89944 /*
89945 * This function runs timers and the timer-tq in bottom half context.
89946 */
89947-static void run_timer_softirq(struct softirq_action *h)
89948+static __latent_entropy void run_timer_softirq(void)
89949 {
89950 struct tvec_base *base = __this_cpu_read(tvec_bases);
89951
89952@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
89953 *
89954 * In all cases the return value is guaranteed to be non-negative.
89955 */
89956-signed long __sched schedule_timeout(signed long timeout)
89957+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
89958 {
89959 struct timer_list timer;
89960 unsigned long expire;
89961diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
89962index f785aef..59f1b18 100644
89963--- a/kernel/trace/blktrace.c
89964+++ b/kernel/trace/blktrace.c
89965@@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
89966 struct blk_trace *bt = filp->private_data;
89967 char buf[16];
89968
89969- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
89970+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
89971
89972 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
89973 }
89974@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
89975 return 1;
89976
89977 bt = buf->chan->private_data;
89978- atomic_inc(&bt->dropped);
89979+ atomic_inc_unchecked(&bt->dropped);
89980 return 0;
89981 }
89982
89983@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
89984
89985 bt->dir = dir;
89986 bt->dev = dev;
89987- atomic_set(&bt->dropped, 0);
89988+ atomic_set_unchecked(&bt->dropped, 0);
89989 INIT_LIST_HEAD(&bt->running_list);
89990
89991 ret = -EIO;
89992diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
89993index 38463d2..68abe92 100644
89994--- a/kernel/trace/ftrace.c
89995+++ b/kernel/trace/ftrace.c
89996@@ -1978,12 +1978,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
89997 if (unlikely(ftrace_disabled))
89998 return 0;
89999
90000+ ret = ftrace_arch_code_modify_prepare();
90001+ FTRACE_WARN_ON(ret);
90002+ if (ret)
90003+ return 0;
90004+
90005 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
90006+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
90007 if (ret) {
90008 ftrace_bug(ret, ip);
90009- return 0;
90010 }
90011- return 1;
90012+ return ret ? 0 : 1;
90013 }
90014
90015 /*
90016@@ -4190,8 +4195,10 @@ static int ftrace_process_locs(struct module *mod,
90017 if (!count)
90018 return 0;
90019
90020+ pax_open_kernel();
90021 sort(start, count, sizeof(*start),
90022 ftrace_cmp_ips, ftrace_swap_ips);
90023+ pax_close_kernel();
90024
90025 start_pg = ftrace_allocate_pages(count);
90026 if (!start_pg)
90027@@ -4922,8 +4929,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
90028 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
90029
90030 static int ftrace_graph_active;
90031-static struct notifier_block ftrace_suspend_notifier;
90032-
90033 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
90034 {
90035 return 0;
90036@@ -5099,6 +5104,10 @@ static void update_function_graph_func(void)
90037 ftrace_graph_entry = ftrace_graph_entry_test;
90038 }
90039
90040+static struct notifier_block ftrace_suspend_notifier = {
90041+ .notifier_call = ftrace_suspend_notifier_call
90042+};
90043+
90044 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90045 trace_func_graph_ent_t entryfunc)
90046 {
90047@@ -5112,7 +5121,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90048 goto out;
90049 }
90050
90051- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
90052 register_pm_notifier(&ftrace_suspend_notifier);
90053
90054 ftrace_graph_active++;
90055diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
90056index 0e337ee..3370631 100644
90057--- a/kernel/trace/ring_buffer.c
90058+++ b/kernel/trace/ring_buffer.c
90059@@ -352,9 +352,9 @@ struct buffer_data_page {
90060 */
90061 struct buffer_page {
90062 struct list_head list; /* list of buffer pages */
90063- local_t write; /* index for next write */
90064+ local_unchecked_t write; /* index for next write */
90065 unsigned read; /* index for next read */
90066- local_t entries; /* entries on this page */
90067+ local_unchecked_t entries; /* entries on this page */
90068 unsigned long real_end; /* real end of data */
90069 struct buffer_data_page *page; /* Actual data page */
90070 };
90071@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
90072 unsigned long last_overrun;
90073 local_t entries_bytes;
90074 local_t entries;
90075- local_t overrun;
90076- local_t commit_overrun;
90077+ local_unchecked_t overrun;
90078+ local_unchecked_t commit_overrun;
90079 local_t dropped_events;
90080 local_t committing;
90081 local_t commits;
90082@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90083 *
90084 * We add a counter to the write field to denote this.
90085 */
90086- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
90087- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
90088+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
90089+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
90090
90091 /*
90092 * Just make sure we have seen our old_write and synchronize
90093@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90094 * cmpxchg to only update if an interrupt did not already
90095 * do it for us. If the cmpxchg fails, we don't care.
90096 */
90097- (void)local_cmpxchg(&next_page->write, old_write, val);
90098- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
90099+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
90100+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
90101
90102 /*
90103 * No need to worry about races with clearing out the commit.
90104@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
90105
90106 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
90107 {
90108- return local_read(&bpage->entries) & RB_WRITE_MASK;
90109+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
90110 }
90111
90112 static inline unsigned long rb_page_write(struct buffer_page *bpage)
90113 {
90114- return local_read(&bpage->write) & RB_WRITE_MASK;
90115+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
90116 }
90117
90118 static int
90119@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
90120 * bytes consumed in ring buffer from here.
90121 * Increment overrun to account for the lost events.
90122 */
90123- local_add(page_entries, &cpu_buffer->overrun);
90124+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
90125 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90126 }
90127
90128@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
90129 * it is our responsibility to update
90130 * the counters.
90131 */
90132- local_add(entries, &cpu_buffer->overrun);
90133+ local_add_unchecked(entries, &cpu_buffer->overrun);
90134 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90135
90136 /*
90137@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90138 if (tail == BUF_PAGE_SIZE)
90139 tail_page->real_end = 0;
90140
90141- local_sub(length, &tail_page->write);
90142+ local_sub_unchecked(length, &tail_page->write);
90143 return;
90144 }
90145
90146@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90147 rb_event_set_padding(event);
90148
90149 /* Set the write back to the previous setting */
90150- local_sub(length, &tail_page->write);
90151+ local_sub_unchecked(length, &tail_page->write);
90152 return;
90153 }
90154
90155@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90156
90157 /* Set write to end of buffer */
90158 length = (tail + length) - BUF_PAGE_SIZE;
90159- local_sub(length, &tail_page->write);
90160+ local_sub_unchecked(length, &tail_page->write);
90161 }
90162
90163 /*
90164@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90165 * about it.
90166 */
90167 if (unlikely(next_page == commit_page)) {
90168- local_inc(&cpu_buffer->commit_overrun);
90169+ local_inc_unchecked(&cpu_buffer->commit_overrun);
90170 goto out_reset;
90171 }
90172
90173@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90174 cpu_buffer->tail_page) &&
90175 (cpu_buffer->commit_page ==
90176 cpu_buffer->reader_page))) {
90177- local_inc(&cpu_buffer->commit_overrun);
90178+ local_inc_unchecked(&cpu_buffer->commit_overrun);
90179 goto out_reset;
90180 }
90181 }
90182@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90183 length += RB_LEN_TIME_EXTEND;
90184
90185 tail_page = cpu_buffer->tail_page;
90186- write = local_add_return(length, &tail_page->write);
90187+ write = local_add_return_unchecked(length, &tail_page->write);
90188
90189 /* set write to only the index of the write */
90190 write &= RB_WRITE_MASK;
90191@@ -2415,7 +2415,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90192 kmemcheck_annotate_bitfield(event, bitfield);
90193 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
90194
90195- local_inc(&tail_page->entries);
90196+ local_inc_unchecked(&tail_page->entries);
90197
90198 /*
90199 * If this is the first commit on the page, then update
90200@@ -2448,7 +2448,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
90201
90202 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
90203 unsigned long write_mask =
90204- local_read(&bpage->write) & ~RB_WRITE_MASK;
90205+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
90206 unsigned long event_length = rb_event_length(event);
90207 /*
90208 * This is on the tail page. It is possible that
90209@@ -2458,7 +2458,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
90210 */
90211 old_index += write_mask;
90212 new_index += write_mask;
90213- index = local_cmpxchg(&bpage->write, old_index, new_index);
90214+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
90215 if (index == old_index) {
90216 /* update counters */
90217 local_sub(event_length, &cpu_buffer->entries_bytes);
90218@@ -2850,7 +2850,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
90219
90220 /* Do the likely case first */
90221 if (likely(bpage->page == (void *)addr)) {
90222- local_dec(&bpage->entries);
90223+ local_dec_unchecked(&bpage->entries);
90224 return;
90225 }
90226
90227@@ -2862,7 +2862,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
90228 start = bpage;
90229 do {
90230 if (bpage->page == (void *)addr) {
90231- local_dec(&bpage->entries);
90232+ local_dec_unchecked(&bpage->entries);
90233 return;
90234 }
90235 rb_inc_page(cpu_buffer, &bpage);
90236@@ -3146,7 +3146,7 @@ static inline unsigned long
90237 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
90238 {
90239 return local_read(&cpu_buffer->entries) -
90240- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
90241+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
90242 }
90243
90244 /**
90245@@ -3235,7 +3235,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
90246 return 0;
90247
90248 cpu_buffer = buffer->buffers[cpu];
90249- ret = local_read(&cpu_buffer->overrun);
90250+ ret = local_read_unchecked(&cpu_buffer->overrun);
90251
90252 return ret;
90253 }
90254@@ -3258,7 +3258,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
90255 return 0;
90256
90257 cpu_buffer = buffer->buffers[cpu];
90258- ret = local_read(&cpu_buffer->commit_overrun);
90259+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
90260
90261 return ret;
90262 }
90263@@ -3343,7 +3343,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
90264 /* if you care about this being correct, lock the buffer */
90265 for_each_buffer_cpu(buffer, cpu) {
90266 cpu_buffer = buffer->buffers[cpu];
90267- overruns += local_read(&cpu_buffer->overrun);
90268+ overruns += local_read_unchecked(&cpu_buffer->overrun);
90269 }
90270
90271 return overruns;
90272@@ -3519,8 +3519,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
90273 /*
90274 * Reset the reader page to size zero.
90275 */
90276- local_set(&cpu_buffer->reader_page->write, 0);
90277- local_set(&cpu_buffer->reader_page->entries, 0);
90278+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
90279+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
90280 local_set(&cpu_buffer->reader_page->page->commit, 0);
90281 cpu_buffer->reader_page->real_end = 0;
90282
90283@@ -3554,7 +3554,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
90284 * want to compare with the last_overrun.
90285 */
90286 smp_mb();
90287- overwrite = local_read(&(cpu_buffer->overrun));
90288+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
90289
90290 /*
90291 * Here's the tricky part.
90292@@ -4124,8 +4124,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
90293
90294 cpu_buffer->head_page
90295 = list_entry(cpu_buffer->pages, struct buffer_page, list);
90296- local_set(&cpu_buffer->head_page->write, 0);
90297- local_set(&cpu_buffer->head_page->entries, 0);
90298+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
90299+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
90300 local_set(&cpu_buffer->head_page->page->commit, 0);
90301
90302 cpu_buffer->head_page->read = 0;
90303@@ -4135,14 +4135,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
90304
90305 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
90306 INIT_LIST_HEAD(&cpu_buffer->new_pages);
90307- local_set(&cpu_buffer->reader_page->write, 0);
90308- local_set(&cpu_buffer->reader_page->entries, 0);
90309+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
90310+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
90311 local_set(&cpu_buffer->reader_page->page->commit, 0);
90312 cpu_buffer->reader_page->read = 0;
90313
90314 local_set(&cpu_buffer->entries_bytes, 0);
90315- local_set(&cpu_buffer->overrun, 0);
90316- local_set(&cpu_buffer->commit_overrun, 0);
90317+ local_set_unchecked(&cpu_buffer->overrun, 0);
90318+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
90319 local_set(&cpu_buffer->dropped_events, 0);
90320 local_set(&cpu_buffer->entries, 0);
90321 local_set(&cpu_buffer->committing, 0);
90322@@ -4547,8 +4547,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
90323 rb_init_page(bpage);
90324 bpage = reader->page;
90325 reader->page = *data_page;
90326- local_set(&reader->write, 0);
90327- local_set(&reader->entries, 0);
90328+ local_set_unchecked(&reader->write, 0);
90329+ local_set_unchecked(&reader->entries, 0);
90330 reader->read = 0;
90331 *data_page = bpage;
90332
90333diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
90334index 0a360ce..7bd800e 100644
90335--- a/kernel/trace/trace.c
90336+++ b/kernel/trace/trace.c
90337@@ -3352,7 +3352,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
90338 return 0;
90339 }
90340
90341-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
90342+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
90343 {
90344 /* do nothing if flag is already set */
90345 if (!!(trace_flags & mask) == !!enabled)
90346diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
90347index ea189e0..a5b48c4 100644
90348--- a/kernel/trace/trace.h
90349+++ b/kernel/trace/trace.h
90350@@ -1040,7 +1040,7 @@ extern const char *__stop___tracepoint_str[];
90351 void trace_printk_init_buffers(void);
90352 void trace_printk_start_comm(void);
90353 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
90354-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
90355+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
90356
90357 /*
90358 * Normal trace_printk() and friends allocates special buffers
90359diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
90360index 26dc348..8708ca7 100644
90361--- a/kernel/trace/trace_clock.c
90362+++ b/kernel/trace/trace_clock.c
90363@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
90364 return now;
90365 }
90366
90367-static atomic64_t trace_counter;
90368+static atomic64_unchecked_t trace_counter;
90369
90370 /*
90371 * trace_clock_counter(): simply an atomic counter.
90372@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
90373 */
90374 u64 notrace trace_clock_counter(void)
90375 {
90376- return atomic64_add_return(1, &trace_counter);
90377+ return atomic64_inc_return_unchecked(&trace_counter);
90378 }
90379diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
90380index ba983dc..911aaf9 100644
90381--- a/kernel/trace/trace_events.c
90382+++ b/kernel/trace/trace_events.c
90383@@ -1675,7 +1675,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
90384 return 0;
90385 }
90386
90387-struct ftrace_module_file_ops;
90388 static void __add_event_to_tracers(struct ftrace_event_call *call);
90389
90390 /* Add an additional event_call dynamically */
90391diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
90392index 0abd9b8..6a663a2 100644
90393--- a/kernel/trace/trace_mmiotrace.c
90394+++ b/kernel/trace/trace_mmiotrace.c
90395@@ -24,7 +24,7 @@ struct header_iter {
90396 static struct trace_array *mmio_trace_array;
90397 static bool overrun_detected;
90398 static unsigned long prev_overruns;
90399-static atomic_t dropped_count;
90400+static atomic_unchecked_t dropped_count;
90401
90402 static void mmio_reset_data(struct trace_array *tr)
90403 {
90404@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
90405
90406 static unsigned long count_overruns(struct trace_iterator *iter)
90407 {
90408- unsigned long cnt = atomic_xchg(&dropped_count, 0);
90409+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
90410 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
90411
90412 if (over > prev_overruns)
90413@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
90414 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
90415 sizeof(*entry), 0, pc);
90416 if (!event) {
90417- atomic_inc(&dropped_count);
90418+ atomic_inc_unchecked(&dropped_count);
90419 return;
90420 }
90421 entry = ring_buffer_event_data(event);
90422@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
90423 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
90424 sizeof(*entry), 0, pc);
90425 if (!event) {
90426- atomic_inc(&dropped_count);
90427+ atomic_inc_unchecked(&dropped_count);
90428 return;
90429 }
90430 entry = ring_buffer_event_data(event);
90431diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
90432index ed32284..884d6c3 100644
90433--- a/kernel/trace/trace_output.c
90434+++ b/kernel/trace/trace_output.c
90435@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
90436
90437 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
90438 if (!IS_ERR(p)) {
90439- p = mangle_path(s->buffer + s->len, p, "\n");
90440+ p = mangle_path(s->buffer + s->len, p, "\n\\");
90441 if (p) {
90442 s->len = p - s->buffer;
90443 return 1;
90444@@ -908,14 +908,16 @@ int register_ftrace_event(struct trace_event *event)
90445 goto out;
90446 }
90447
90448+ pax_open_kernel();
90449 if (event->funcs->trace == NULL)
90450- event->funcs->trace = trace_nop_print;
90451+ *(void **)&event->funcs->trace = trace_nop_print;
90452 if (event->funcs->raw == NULL)
90453- event->funcs->raw = trace_nop_print;
90454+ *(void **)&event->funcs->raw = trace_nop_print;
90455 if (event->funcs->hex == NULL)
90456- event->funcs->hex = trace_nop_print;
90457+ *(void **)&event->funcs->hex = trace_nop_print;
90458 if (event->funcs->binary == NULL)
90459- event->funcs->binary = trace_nop_print;
90460+ *(void **)&event->funcs->binary = trace_nop_print;
90461+ pax_close_kernel();
90462
90463 key = event->type & (EVENT_HASHSIZE - 1);
90464
90465diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
90466index b20428c..4845a10 100644
90467--- a/kernel/trace/trace_stack.c
90468+++ b/kernel/trace/trace_stack.c
90469@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
90470 return;
90471
90472 /* we do not handle interrupt stacks yet */
90473- if (!object_is_on_stack(stack))
90474+ if (!object_starts_on_stack(stack))
90475 return;
90476
90477 local_irq_save(flags);
90478diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
90479index 240fb62..583473e 100644
90480--- a/kernel/user_namespace.c
90481+++ b/kernel/user_namespace.c
90482@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
90483 !kgid_has_mapping(parent_ns, group))
90484 return -EPERM;
90485
90486+#ifdef CONFIG_GRKERNSEC
90487+ /*
90488+ * This doesn't really inspire confidence:
90489+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
90490+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
90491+ * Increases kernel attack surface in areas developers
90492+ * previously cared little about ("low importance due
90493+ * to requiring "root" capability")
90494+ * To be removed when this code receives *proper* review
90495+ */
90496+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
90497+ !capable(CAP_SETGID))
90498+ return -EPERM;
90499+#endif
90500+
90501 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
90502 if (!ns)
90503 return -ENOMEM;
90504@@ -866,7 +881,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
90505 if (atomic_read(&current->mm->mm_users) > 1)
90506 return -EINVAL;
90507
90508- if (current->fs->users != 1)
90509+ if (atomic_read(&current->fs->users) != 1)
90510 return -EINVAL;
90511
90512 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
90513diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
90514index 4f69f9a..7c6f8f8 100644
90515--- a/kernel/utsname_sysctl.c
90516+++ b/kernel/utsname_sysctl.c
90517@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
90518 static int proc_do_uts_string(ctl_table *table, int write,
90519 void __user *buffer, size_t *lenp, loff_t *ppos)
90520 {
90521- struct ctl_table uts_table;
90522+ ctl_table_no_const uts_table;
90523 int r;
90524 memcpy(&uts_table, table, sizeof(uts_table));
90525 uts_table.data = get_uts(table, write);
90526diff --git a/kernel/watchdog.c b/kernel/watchdog.c
90527index 4431610..4265616 100644
90528--- a/kernel/watchdog.c
90529+++ b/kernel/watchdog.c
90530@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
90531 static void watchdog_nmi_disable(unsigned int cpu) { return; }
90532 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
90533
90534-static struct smp_hotplug_thread watchdog_threads = {
90535+static struct smp_hotplug_thread watchdog_threads __read_only = {
90536 .store = &softlockup_watchdog,
90537 .thread_should_run = watchdog_should_run,
90538 .thread_fn = watchdog,
90539diff --git a/kernel/workqueue.c b/kernel/workqueue.c
90540index a8381cf..1ce1331 100644
90541--- a/kernel/workqueue.c
90542+++ b/kernel/workqueue.c
90543@@ -4678,7 +4678,7 @@ static void rebind_workers(struct worker_pool *pool)
90544 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
90545 worker_flags |= WORKER_REBOUND;
90546 worker_flags &= ~WORKER_UNBOUND;
90547- ACCESS_ONCE(worker->flags) = worker_flags;
90548+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
90549 }
90550
90551 spin_unlock_irq(&pool->lock);
90552diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
90553index db25707..8b16430 100644
90554--- a/lib/Kconfig.debug
90555+++ b/lib/Kconfig.debug
90556@@ -845,7 +845,7 @@ config DEBUG_MUTEXES
90557
90558 config DEBUG_WW_MUTEX_SLOWPATH
90559 bool "Wait/wound mutex debugging: Slowpath testing"
90560- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90561+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90562 select DEBUG_LOCK_ALLOC
90563 select DEBUG_SPINLOCK
90564 select DEBUG_MUTEXES
90565@@ -858,7 +858,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
90566
90567 config DEBUG_LOCK_ALLOC
90568 bool "Lock debugging: detect incorrect freeing of live locks"
90569- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90570+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90571 select DEBUG_SPINLOCK
90572 select DEBUG_MUTEXES
90573 select LOCKDEP
90574@@ -872,7 +872,7 @@ config DEBUG_LOCK_ALLOC
90575
90576 config PROVE_LOCKING
90577 bool "Lock debugging: prove locking correctness"
90578- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90579+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90580 select LOCKDEP
90581 select DEBUG_SPINLOCK
90582 select DEBUG_MUTEXES
90583@@ -923,7 +923,7 @@ config LOCKDEP
90584
90585 config LOCK_STAT
90586 bool "Lock usage statistics"
90587- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90588+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90589 select LOCKDEP
90590 select DEBUG_SPINLOCK
90591 select DEBUG_MUTEXES
90592@@ -1385,6 +1385,7 @@ config LATENCYTOP
90593 depends on DEBUG_KERNEL
90594 depends on STACKTRACE_SUPPORT
90595 depends on PROC_FS
90596+ depends on !GRKERNSEC_HIDESYM
90597 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
90598 select KALLSYMS
90599 select KALLSYMS_ALL
90600@@ -1401,7 +1402,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
90601 config DEBUG_STRICT_USER_COPY_CHECKS
90602 bool "Strict user copy size checks"
90603 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
90604- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
90605+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
90606 help
90607 Enabling this option turns a certain set of sanity checks for user
90608 copy operations into compile time failures.
90609@@ -1520,7 +1521,7 @@ endmenu # runtime tests
90610
90611 config PROVIDE_OHCI1394_DMA_INIT
90612 bool "Remote debugging over FireWire early on boot"
90613- depends on PCI && X86
90614+ depends on PCI && X86 && !GRKERNSEC
90615 help
90616 If you want to debug problems which hang or crash the kernel early
90617 on boot and the crashing machine has a FireWire port, you can use
90618@@ -1549,7 +1550,7 @@ config PROVIDE_OHCI1394_DMA_INIT
90619
90620 config FIREWIRE_OHCI_REMOTE_DMA
90621 bool "Remote debugging over FireWire with firewire-ohci"
90622- depends on FIREWIRE_OHCI
90623+ depends on FIREWIRE_OHCI && !GRKERNSEC
90624 help
90625 This option lets you use the FireWire bus for remote debugging
90626 with help of the firewire-ohci driver. It enables unfiltered
90627diff --git a/lib/Makefile b/lib/Makefile
90628index 04944e9..f43eabe 100644
90629--- a/lib/Makefile
90630+++ b/lib/Makefile
90631@@ -50,7 +50,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
90632 obj-$(CONFIG_BTREE) += btree.o
90633 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
90634 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
90635-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
90636+obj-y += list_debug.o
90637 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
90638
90639 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
90640diff --git a/lib/bitmap.c b/lib/bitmap.c
90641index 06f7e4f..f3cf2b0 100644
90642--- a/lib/bitmap.c
90643+++ b/lib/bitmap.c
90644@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
90645 {
90646 int c, old_c, totaldigits, ndigits, nchunks, nbits;
90647 u32 chunk;
90648- const char __user __force *ubuf = (const char __user __force *)buf;
90649+ const char __user *ubuf = (const char __force_user *)buf;
90650
90651 bitmap_zero(maskp, nmaskbits);
90652
90653@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
90654 {
90655 if (!access_ok(VERIFY_READ, ubuf, ulen))
90656 return -EFAULT;
90657- return __bitmap_parse((const char __force *)ubuf,
90658+ return __bitmap_parse((const char __force_kernel *)ubuf,
90659 ulen, 1, maskp, nmaskbits);
90660
90661 }
90662@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
90663 {
90664 unsigned a, b;
90665 int c, old_c, totaldigits;
90666- const char __user __force *ubuf = (const char __user __force *)buf;
90667+ const char __user *ubuf = (const char __force_user *)buf;
90668 int exp_digit, in_range;
90669
90670 totaldigits = c = 0;
90671@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
90672 {
90673 if (!access_ok(VERIFY_READ, ubuf, ulen))
90674 return -EFAULT;
90675- return __bitmap_parselist((const char __force *)ubuf,
90676+ return __bitmap_parselist((const char __force_kernel *)ubuf,
90677 ulen, 1, maskp, nmaskbits);
90678 }
90679 EXPORT_SYMBOL(bitmap_parselist_user);
90680diff --git a/lib/bug.c b/lib/bug.c
90681index 1686034..a9c00c8 100644
90682--- a/lib/bug.c
90683+++ b/lib/bug.c
90684@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
90685 return BUG_TRAP_TYPE_NONE;
90686
90687 bug = find_bug(bugaddr);
90688+ if (!bug)
90689+ return BUG_TRAP_TYPE_NONE;
90690
90691 file = NULL;
90692 line = 0;
90693diff --git a/lib/debugobjects.c b/lib/debugobjects.c
90694index e0731c3..ad66444 100644
90695--- a/lib/debugobjects.c
90696+++ b/lib/debugobjects.c
90697@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
90698 if (limit > 4)
90699 return;
90700
90701- is_on_stack = object_is_on_stack(addr);
90702+ is_on_stack = object_starts_on_stack(addr);
90703 if (is_on_stack == onstack)
90704 return;
90705
90706diff --git a/lib/devres.c b/lib/devres.c
90707index 8235331..5881053 100644
90708--- a/lib/devres.c
90709+++ b/lib/devres.c
90710@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
90711 void devm_iounmap(struct device *dev, void __iomem *addr)
90712 {
90713 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
90714- (void *)addr));
90715+ (void __force *)addr));
90716 iounmap(addr);
90717 }
90718 EXPORT_SYMBOL(devm_iounmap);
90719@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
90720 {
90721 ioport_unmap(addr);
90722 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
90723- devm_ioport_map_match, (void *)addr));
90724+ devm_ioport_map_match, (void __force *)addr));
90725 }
90726 EXPORT_SYMBOL(devm_ioport_unmap);
90727 #endif /* CONFIG_HAS_IOPORT */
90728diff --git a/lib/div64.c b/lib/div64.c
90729index 4382ad7..08aa558 100644
90730--- a/lib/div64.c
90731+++ b/lib/div64.c
90732@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
90733 EXPORT_SYMBOL(__div64_32);
90734
90735 #ifndef div_s64_rem
90736-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
90737+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
90738 {
90739 u64 quotient;
90740
90741@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
90742 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
90743 */
90744 #ifndef div64_u64
90745-u64 div64_u64(u64 dividend, u64 divisor)
90746+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
90747 {
90748 u32 high = divisor >> 32;
90749 u64 quot;
90750diff --git a/lib/dma-debug.c b/lib/dma-debug.c
90751index d87a17a..ac0d79a 100644
90752--- a/lib/dma-debug.c
90753+++ b/lib/dma-debug.c
90754@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
90755
90756 void dma_debug_add_bus(struct bus_type *bus)
90757 {
90758- struct notifier_block *nb;
90759+ notifier_block_no_const *nb;
90760
90761 if (global_disable)
90762 return;
90763@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
90764
90765 static void check_for_stack(struct device *dev, void *addr)
90766 {
90767- if (object_is_on_stack(addr))
90768+ if (object_starts_on_stack(addr))
90769 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
90770 "stack [addr=%p]\n", addr);
90771 }
90772diff --git a/lib/inflate.c b/lib/inflate.c
90773index 013a761..c28f3fc 100644
90774--- a/lib/inflate.c
90775+++ b/lib/inflate.c
90776@@ -269,7 +269,7 @@ static void free(void *where)
90777 malloc_ptr = free_mem_ptr;
90778 }
90779 #else
90780-#define malloc(a) kmalloc(a, GFP_KERNEL)
90781+#define malloc(a) kmalloc((a), GFP_KERNEL)
90782 #define free(a) kfree(a)
90783 #endif
90784
90785diff --git a/lib/ioremap.c b/lib/ioremap.c
90786index 0c9216c..863bd89 100644
90787--- a/lib/ioremap.c
90788+++ b/lib/ioremap.c
90789@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
90790 unsigned long next;
90791
90792 phys_addr -= addr;
90793- pmd = pmd_alloc(&init_mm, pud, addr);
90794+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
90795 if (!pmd)
90796 return -ENOMEM;
90797 do {
90798@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
90799 unsigned long next;
90800
90801 phys_addr -= addr;
90802- pud = pud_alloc(&init_mm, pgd, addr);
90803+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
90804 if (!pud)
90805 return -ENOMEM;
90806 do {
90807diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
90808index bd2bea9..6b3c95e 100644
90809--- a/lib/is_single_threaded.c
90810+++ b/lib/is_single_threaded.c
90811@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
90812 struct task_struct *p, *t;
90813 bool ret;
90814
90815+ if (!mm)
90816+ return true;
90817+
90818 if (atomic_read(&task->signal->live) != 1)
90819 return false;
90820
90821diff --git a/lib/kobject.c b/lib/kobject.c
90822index 5b4b888..c2950f7 100644
90823--- a/lib/kobject.c
90824+++ b/lib/kobject.c
90825@@ -957,9 +957,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
90826
90827
90828 static DEFINE_SPINLOCK(kobj_ns_type_lock);
90829-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
90830+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
90831
90832-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
90833+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
90834 {
90835 enum kobj_ns_type type = ops->type;
90836 int error;
90837diff --git a/lib/list_debug.c b/lib/list_debug.c
90838index c24c2f7..f0296f4 100644
90839--- a/lib/list_debug.c
90840+++ b/lib/list_debug.c
90841@@ -11,7 +11,9 @@
90842 #include <linux/bug.h>
90843 #include <linux/kernel.h>
90844 #include <linux/rculist.h>
90845+#include <linux/mm.h>
90846
90847+#ifdef CONFIG_DEBUG_LIST
90848 /*
90849 * Insert a new entry between two known consecutive entries.
90850 *
90851@@ -19,21 +21,40 @@
90852 * the prev/next entries already!
90853 */
90854
90855+static bool __list_add_debug(struct list_head *new,
90856+ struct list_head *prev,
90857+ struct list_head *next)
90858+{
90859+ if (unlikely(next->prev != prev)) {
90860+ printk(KERN_ERR "list_add corruption. next->prev should be "
90861+ "prev (%p), but was %p. (next=%p).\n",
90862+ prev, next->prev, next);
90863+ BUG();
90864+ return false;
90865+ }
90866+ if (unlikely(prev->next != next)) {
90867+ printk(KERN_ERR "list_add corruption. prev->next should be "
90868+ "next (%p), but was %p. (prev=%p).\n",
90869+ next, prev->next, prev);
90870+ BUG();
90871+ return false;
90872+ }
90873+ if (unlikely(new == prev || new == next)) {
90874+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
90875+ new, prev, next);
90876+ BUG();
90877+ return false;
90878+ }
90879+ return true;
90880+}
90881+
90882 void __list_add(struct list_head *new,
90883- struct list_head *prev,
90884- struct list_head *next)
90885+ struct list_head *prev,
90886+ struct list_head *next)
90887 {
90888- WARN(next->prev != prev,
90889- "list_add corruption. next->prev should be "
90890- "prev (%p), but was %p. (next=%p).\n",
90891- prev, next->prev, next);
90892- WARN(prev->next != next,
90893- "list_add corruption. prev->next should be "
90894- "next (%p), but was %p. (prev=%p).\n",
90895- next, prev->next, prev);
90896- WARN(new == prev || new == next,
90897- "list_add double add: new=%p, prev=%p, next=%p.\n",
90898- new, prev, next);
90899+ if (!__list_add_debug(new, prev, next))
90900+ return;
90901+
90902 next->prev = new;
90903 new->next = next;
90904 new->prev = prev;
90905@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
90906 }
90907 EXPORT_SYMBOL(__list_add);
90908
90909-void __list_del_entry(struct list_head *entry)
90910+static bool __list_del_entry_debug(struct list_head *entry)
90911 {
90912 struct list_head *prev, *next;
90913
90914 prev = entry->prev;
90915 next = entry->next;
90916
90917- if (WARN(next == LIST_POISON1,
90918- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
90919- entry, LIST_POISON1) ||
90920- WARN(prev == LIST_POISON2,
90921- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
90922- entry, LIST_POISON2) ||
90923- WARN(prev->next != entry,
90924- "list_del corruption. prev->next should be %p, "
90925- "but was %p\n", entry, prev->next) ||
90926- WARN(next->prev != entry,
90927- "list_del corruption. next->prev should be %p, "
90928- "but was %p\n", entry, next->prev))
90929+ if (unlikely(next == LIST_POISON1)) {
90930+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
90931+ entry, LIST_POISON1);
90932+ BUG();
90933+ return false;
90934+ }
90935+ if (unlikely(prev == LIST_POISON2)) {
90936+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
90937+ entry, LIST_POISON2);
90938+ BUG();
90939+ return false;
90940+ }
90941+ if (unlikely(entry->prev->next != entry)) {
90942+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
90943+ "but was %p\n", entry, prev->next);
90944+ BUG();
90945+ return false;
90946+ }
90947+ if (unlikely(entry->next->prev != entry)) {
90948+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
90949+ "but was %p\n", entry, next->prev);
90950+ BUG();
90951+ return false;
90952+ }
90953+ return true;
90954+}
90955+
90956+void __list_del_entry(struct list_head *entry)
90957+{
90958+ if (!__list_del_entry_debug(entry))
90959 return;
90960
90961- __list_del(prev, next);
90962+ __list_del(entry->prev, entry->next);
90963 }
90964 EXPORT_SYMBOL(__list_del_entry);
90965
90966@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
90967 void __list_add_rcu(struct list_head *new,
90968 struct list_head *prev, struct list_head *next)
90969 {
90970- WARN(next->prev != prev,
90971- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
90972- prev, next->prev, next);
90973- WARN(prev->next != next,
90974- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
90975- next, prev->next, prev);
90976+ if (!__list_add_debug(new, prev, next))
90977+ return;
90978+
90979 new->next = next;
90980 new->prev = prev;
90981 rcu_assign_pointer(list_next_rcu(prev), new);
90982 next->prev = new;
90983 }
90984 EXPORT_SYMBOL(__list_add_rcu);
90985+#endif
90986+
90987+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
90988+{
90989+#ifdef CONFIG_DEBUG_LIST
90990+ if (!__list_add_debug(new, prev, next))
90991+ return;
90992+#endif
90993+
90994+ pax_open_kernel();
90995+ next->prev = new;
90996+ new->next = next;
90997+ new->prev = prev;
90998+ prev->next = new;
90999+ pax_close_kernel();
91000+}
91001+EXPORT_SYMBOL(__pax_list_add);
91002+
91003+void pax_list_del(struct list_head *entry)
91004+{
91005+#ifdef CONFIG_DEBUG_LIST
91006+ if (!__list_del_entry_debug(entry))
91007+ return;
91008+#endif
91009+
91010+ pax_open_kernel();
91011+ __list_del(entry->prev, entry->next);
91012+ entry->next = LIST_POISON1;
91013+ entry->prev = LIST_POISON2;
91014+ pax_close_kernel();
91015+}
91016+EXPORT_SYMBOL(pax_list_del);
91017+
91018+void pax_list_del_init(struct list_head *entry)
91019+{
91020+ pax_open_kernel();
91021+ __list_del(entry->prev, entry->next);
91022+ INIT_LIST_HEAD(entry);
91023+ pax_close_kernel();
91024+}
91025+EXPORT_SYMBOL(pax_list_del_init);
91026+
91027+void __pax_list_add_rcu(struct list_head *new,
91028+ struct list_head *prev, struct list_head *next)
91029+{
91030+#ifdef CONFIG_DEBUG_LIST
91031+ if (!__list_add_debug(new, prev, next))
91032+ return;
91033+#endif
91034+
91035+ pax_open_kernel();
91036+ new->next = next;
91037+ new->prev = prev;
91038+ rcu_assign_pointer(list_next_rcu(prev), new);
91039+ next->prev = new;
91040+ pax_close_kernel();
91041+}
91042+EXPORT_SYMBOL(__pax_list_add_rcu);
91043+
91044+void pax_list_del_rcu(struct list_head *entry)
91045+{
91046+#ifdef CONFIG_DEBUG_LIST
91047+ if (!__list_del_entry_debug(entry))
91048+ return;
91049+#endif
91050+
91051+ pax_open_kernel();
91052+ __list_del(entry->prev, entry->next);
91053+ entry->next = LIST_POISON1;
91054+ entry->prev = LIST_POISON2;
91055+ pax_close_kernel();
91056+}
91057+EXPORT_SYMBOL(pax_list_del_rcu);
91058diff --git a/lib/nlattr.c b/lib/nlattr.c
91059index 18eca78..fc67547 100644
91060--- a/lib/nlattr.c
91061+++ b/lib/nlattr.c
91062@@ -303,9 +303,15 @@ int nla_memcmp(const struct nlattr *nla, const void *data,
91063 */
91064 int nla_strcmp(const struct nlattr *nla, const char *str)
91065 {
91066- int len = strlen(str) + 1;
91067- int d = nla_len(nla) - len;
91068+ int len = strlen(str);
91069+ char *buf = nla_data(nla);
91070+ int attrlen = nla_len(nla);
91071+ int d;
91072
91073+ if (attrlen > 0 && buf[attrlen - 1] == '\0')
91074+ attrlen--;
91075+
91076+ d = attrlen - len;
91077 if (d == 0)
91078 d = memcmp(nla_data(nla), str, len);
91079
91080diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
91081index 1a53d49..ace934c 100644
91082--- a/lib/percpu-refcount.c
91083+++ b/lib/percpu-refcount.c
91084@@ -29,7 +29,7 @@
91085 * can't hit 0 before we've added up all the percpu refs.
91086 */
91087
91088-#define PCPU_COUNT_BIAS (1U << 31)
91089+#define PCPU_COUNT_BIAS (1U << 30)
91090
91091 /**
91092 * percpu_ref_init - initialize a percpu refcount
91093diff --git a/lib/radix-tree.c b/lib/radix-tree.c
91094index 7811ed3..f80ca19 100644
91095--- a/lib/radix-tree.c
91096+++ b/lib/radix-tree.c
91097@@ -93,7 +93,7 @@ struct radix_tree_preload {
91098 int nr;
91099 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
91100 };
91101-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
91102+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
91103
91104 static inline void *ptr_to_indirect(void *ptr)
91105 {
91106diff --git a/lib/random32.c b/lib/random32.c
91107index 6148967..009bfe8 100644
91108--- a/lib/random32.c
91109+++ b/lib/random32.c
91110@@ -44,7 +44,7 @@
91111 static void __init prandom_state_selftest(void);
91112 #endif
91113
91114-static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
91115+static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
91116
91117 /**
91118 * prandom_u32_state - seeded pseudo-random number generator.
91119diff --git a/lib/rbtree.c b/lib/rbtree.c
91120index 65f4eff..2cfa167 100644
91121--- a/lib/rbtree.c
91122+++ b/lib/rbtree.c
91123@@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
91124 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
91125
91126 static const struct rb_augment_callbacks dummy_callbacks = {
91127- dummy_propagate, dummy_copy, dummy_rotate
91128+ .propagate = dummy_propagate,
91129+ .copy = dummy_copy,
91130+ .rotate = dummy_rotate
91131 };
91132
91133 void rb_insert_color(struct rb_node *node, struct rb_root *root)
91134diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
91135index bb2b201..46abaf9 100644
91136--- a/lib/strncpy_from_user.c
91137+++ b/lib/strncpy_from_user.c
91138@@ -21,7 +21,7 @@
91139 */
91140 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
91141 {
91142- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91143+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91144 long res = 0;
91145
91146 /*
91147diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
91148index a28df52..3d55877 100644
91149--- a/lib/strnlen_user.c
91150+++ b/lib/strnlen_user.c
91151@@ -26,7 +26,7 @@
91152 */
91153 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
91154 {
91155- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91156+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91157 long align, res = 0;
91158 unsigned long c;
91159
91160diff --git a/lib/swiotlb.c b/lib/swiotlb.c
91161index e4399fa..5e8b214 100644
91162--- a/lib/swiotlb.c
91163+++ b/lib/swiotlb.c
91164@@ -668,7 +668,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
91165
91166 void
91167 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
91168- dma_addr_t dev_addr)
91169+ dma_addr_t dev_addr, struct dma_attrs *attrs)
91170 {
91171 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
91172
91173diff --git a/lib/usercopy.c b/lib/usercopy.c
91174index 4f5b1dd..7cab418 100644
91175--- a/lib/usercopy.c
91176+++ b/lib/usercopy.c
91177@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
91178 WARN(1, "Buffer overflow detected!\n");
91179 }
91180 EXPORT_SYMBOL(copy_from_user_overflow);
91181+
91182+void copy_to_user_overflow(void)
91183+{
91184+ WARN(1, "Buffer overflow detected!\n");
91185+}
91186+EXPORT_SYMBOL(copy_to_user_overflow);
91187diff --git a/lib/vsprintf.c b/lib/vsprintf.c
91188index 10909c5..653e1b8 100644
91189--- a/lib/vsprintf.c
91190+++ b/lib/vsprintf.c
91191@@ -16,6 +16,9 @@
91192 * - scnprintf and vscnprintf
91193 */
91194
91195+#ifdef CONFIG_GRKERNSEC_HIDESYM
91196+#define __INCLUDED_BY_HIDESYM 1
91197+#endif
91198 #include <stdarg.h>
91199 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
91200 #include <linux/types.h>
91201@@ -1155,7 +1158,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
91202 return number(buf, end, *(const netdev_features_t *)addr, spec);
91203 }
91204
91205+#ifdef CONFIG_GRKERNSEC_HIDESYM
91206+int kptr_restrict __read_mostly = 2;
91207+#else
91208 int kptr_restrict __read_mostly;
91209+#endif
91210
91211 /*
91212 * Show a '%p' thing. A kernel extension is that the '%p' is followed
91213@@ -1168,6 +1175,7 @@ int kptr_restrict __read_mostly;
91214 * - 'f' For simple symbolic function names without offset
91215 * - 'S' For symbolic direct pointers with offset
91216 * - 's' For symbolic direct pointers without offset
91217+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
91218 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
91219 * - 'B' For backtraced symbolic direct pointers with offset
91220 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
91221@@ -1234,12 +1242,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91222
91223 if (!ptr && *fmt != 'K') {
91224 /*
91225- * Print (null) with the same width as a pointer so it makes
91226+ * Print (nil) with the same width as a pointer so it makes
91227 * tabular output look nice.
91228 */
91229 if (spec.field_width == -1)
91230 spec.field_width = default_width;
91231- return string(buf, end, "(null)", spec);
91232+ return string(buf, end, "(nil)", spec);
91233 }
91234
91235 switch (*fmt) {
91236@@ -1249,6 +1257,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91237 /* Fallthrough */
91238 case 'S':
91239 case 's':
91240+#ifdef CONFIG_GRKERNSEC_HIDESYM
91241+ break;
91242+#else
91243+ return symbol_string(buf, end, ptr, spec, fmt);
91244+#endif
91245+ case 'A':
91246 case 'B':
91247 return symbol_string(buf, end, ptr, spec, fmt);
91248 case 'R':
91249@@ -1304,6 +1318,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91250 va_end(va);
91251 return buf;
91252 }
91253+ case 'P':
91254+ break;
91255 case 'K':
91256 /*
91257 * %pK cannot be used in IRQ context because its test
91258@@ -1365,6 +1381,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91259 ((const struct file *)ptr)->f_path.dentry,
91260 spec, fmt);
91261 }
91262+
91263+#ifdef CONFIG_GRKERNSEC_HIDESYM
91264+ /* 'P' = approved pointers to copy to userland,
91265+ as in the /proc/kallsyms case, as we make it display nothing
91266+ for non-root users, and the real contents for root users
91267+ Also ignore 'K' pointers, since we force their NULLing for non-root users
91268+ above
91269+ */
91270+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
91271+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
91272+ dump_stack();
91273+ ptr = NULL;
91274+ }
91275+#endif
91276+
91277 spec.flags |= SMALL;
91278 if (spec.field_width == -1) {
91279 spec.field_width = default_width;
91280@@ -2086,11 +2117,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
91281 typeof(type) value; \
91282 if (sizeof(type) == 8) { \
91283 args = PTR_ALIGN(args, sizeof(u32)); \
91284- *(u32 *)&value = *(u32 *)args; \
91285- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
91286+ *(u32 *)&value = *(const u32 *)args; \
91287+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
91288 } else { \
91289 args = PTR_ALIGN(args, sizeof(type)); \
91290- value = *(typeof(type) *)args; \
91291+ value = *(const typeof(type) *)args; \
91292 } \
91293 args += sizeof(type); \
91294 value; \
91295@@ -2153,7 +2184,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
91296 case FORMAT_TYPE_STR: {
91297 const char *str_arg = args;
91298 args += strlen(str_arg) + 1;
91299- str = string(str, end, (char *)str_arg, spec);
91300+ str = string(str, end, str_arg, spec);
91301 break;
91302 }
91303
91304diff --git a/localversion-grsec b/localversion-grsec
91305new file mode 100644
91306index 0000000..7cd6065
91307--- /dev/null
91308+++ b/localversion-grsec
91309@@ -0,0 +1 @@
91310+-grsec
91311diff --git a/mm/Kconfig b/mm/Kconfig
91312index 723bbe0..ea624b1 100644
91313--- a/mm/Kconfig
91314+++ b/mm/Kconfig
91315@@ -326,10 +326,11 @@ config KSM
91316 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
91317
91318 config DEFAULT_MMAP_MIN_ADDR
91319- int "Low address space to protect from user allocation"
91320+ int "Low address space to protect from user allocation"
91321 depends on MMU
91322- default 4096
91323- help
91324+ default 32768 if ALPHA || ARM || PARISC || SPARC32
91325+ default 65536
91326+ help
91327 This is the portion of low virtual memory which should be protected
91328 from userspace allocation. Keeping a user from writing to low pages
91329 can help reduce the impact of kernel NULL pointer bugs.
91330@@ -360,7 +361,7 @@ config MEMORY_FAILURE
91331
91332 config HWPOISON_INJECT
91333 tristate "HWPoison pages injector"
91334- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
91335+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
91336 select PROC_PAGE_MONITOR
91337
91338 config NOMMU_INITIAL_TRIM_EXCESS
91339diff --git a/mm/backing-dev.c b/mm/backing-dev.c
91340index ce682f7..1fb54f9 100644
91341--- a/mm/backing-dev.c
91342+++ b/mm/backing-dev.c
91343@@ -12,7 +12,7 @@
91344 #include <linux/device.h>
91345 #include <trace/events/writeback.h>
91346
91347-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
91348+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
91349
91350 struct backing_dev_info default_backing_dev_info = {
91351 .name = "default",
91352@@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
91353 return err;
91354
91355 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
91356- atomic_long_inc_return(&bdi_seq));
91357+ atomic_long_inc_return_unchecked(&bdi_seq));
91358 if (err) {
91359 bdi_destroy(bdi);
91360 return err;
91361diff --git a/mm/filemap.c b/mm/filemap.c
91362index b7749a9..50d1123 100644
91363--- a/mm/filemap.c
91364+++ b/mm/filemap.c
91365@@ -1768,7 +1768,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
91366 struct address_space *mapping = file->f_mapping;
91367
91368 if (!mapping->a_ops->readpage)
91369- return -ENOEXEC;
91370+ return -ENODEV;
91371 file_accessed(file);
91372 vma->vm_ops = &generic_file_vm_ops;
91373 return 0;
91374@@ -1950,7 +1950,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
91375
91376 while (bytes) {
91377 char __user *buf = iov->iov_base + base;
91378- int copy = min(bytes, iov->iov_len - base);
91379+ size_t copy = min(bytes, iov->iov_len - base);
91380
91381 base = 0;
91382 left = __copy_from_user_inatomic(vaddr, buf, copy);
91383@@ -1979,7 +1979,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
91384 BUG_ON(!in_atomic());
91385 kaddr = kmap_atomic(page);
91386 if (likely(i->nr_segs == 1)) {
91387- int left;
91388+ size_t left;
91389 char __user *buf = i->iov->iov_base + i->iov_offset;
91390 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
91391 copied = bytes - left;
91392@@ -2007,7 +2007,7 @@ size_t iov_iter_copy_from_user(struct page *page,
91393
91394 kaddr = kmap(page);
91395 if (likely(i->nr_segs == 1)) {
91396- int left;
91397+ size_t left;
91398 char __user *buf = i->iov->iov_base + i->iov_offset;
91399 left = __copy_from_user(kaddr + offset, buf, bytes);
91400 copied = bytes - left;
91401@@ -2037,7 +2037,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
91402 * zero-length segments (without overruning the iovec).
91403 */
91404 while (bytes || unlikely(i->count && !iov->iov_len)) {
91405- int copy;
91406+ size_t copy;
91407
91408 copy = min(bytes, iov->iov_len - base);
91409 BUG_ON(!i->count || i->count < copy);
91410@@ -2108,6 +2108,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
91411 *pos = i_size_read(inode);
91412
91413 if (limit != RLIM_INFINITY) {
91414+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
91415 if (*pos >= limit) {
91416 send_sig(SIGXFSZ, current, 0);
91417 return -EFBIG;
91418diff --git a/mm/fremap.c b/mm/fremap.c
91419index bbc4d66..117b798 100644
91420--- a/mm/fremap.c
91421+++ b/mm/fremap.c
91422@@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
91423 retry:
91424 vma = find_vma(mm, start);
91425
91426+#ifdef CONFIG_PAX_SEGMEXEC
91427+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
91428+ goto out;
91429+#endif
91430+
91431 /*
91432 * Make sure the vma is shared, that it supports prefaulting,
91433 * and that the remapped range is valid and fully within
91434diff --git a/mm/highmem.c b/mm/highmem.c
91435index b32b70c..e512eb0 100644
91436--- a/mm/highmem.c
91437+++ b/mm/highmem.c
91438@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
91439 * So no dangers, even with speculative execution.
91440 */
91441 page = pte_page(pkmap_page_table[i]);
91442+ pax_open_kernel();
91443 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
91444-
91445+ pax_close_kernel();
91446 set_page_address(page, NULL);
91447 need_flush = 1;
91448 }
91449@@ -198,9 +199,11 @@ start:
91450 }
91451 }
91452 vaddr = PKMAP_ADDR(last_pkmap_nr);
91453+
91454+ pax_open_kernel();
91455 set_pte_at(&init_mm, vaddr,
91456 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
91457-
91458+ pax_close_kernel();
91459 pkmap_count[last_pkmap_nr] = 1;
91460 set_page_address(page, (void *)vaddr);
91461
91462diff --git a/mm/hugetlb.c b/mm/hugetlb.c
91463index dee6cf4..52b94f7 100644
91464--- a/mm/hugetlb.c
91465+++ b/mm/hugetlb.c
91466@@ -2077,15 +2077,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
91467 struct hstate *h = &default_hstate;
91468 unsigned long tmp;
91469 int ret;
91470+ ctl_table_no_const hugetlb_table;
91471
91472 tmp = h->max_huge_pages;
91473
91474 if (write && h->order >= MAX_ORDER)
91475 return -EINVAL;
91476
91477- table->data = &tmp;
91478- table->maxlen = sizeof(unsigned long);
91479- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
91480+ hugetlb_table = *table;
91481+ hugetlb_table.data = &tmp;
91482+ hugetlb_table.maxlen = sizeof(unsigned long);
91483+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
91484 if (ret)
91485 goto out;
91486
91487@@ -2130,15 +2132,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
91488 struct hstate *h = &default_hstate;
91489 unsigned long tmp;
91490 int ret;
91491+ ctl_table_no_const hugetlb_table;
91492
91493 tmp = h->nr_overcommit_huge_pages;
91494
91495 if (write && h->order >= MAX_ORDER)
91496 return -EINVAL;
91497
91498- table->data = &tmp;
91499- table->maxlen = sizeof(unsigned long);
91500- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
91501+ hugetlb_table = *table;
91502+ hugetlb_table.data = &tmp;
91503+ hugetlb_table.maxlen = sizeof(unsigned long);
91504+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
91505 if (ret)
91506 goto out;
91507
91508@@ -2596,6 +2600,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
91509 return 1;
91510 }
91511
91512+#ifdef CONFIG_PAX_SEGMEXEC
91513+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
91514+{
91515+ struct mm_struct *mm = vma->vm_mm;
91516+ struct vm_area_struct *vma_m;
91517+ unsigned long address_m;
91518+ pte_t *ptep_m;
91519+
91520+ vma_m = pax_find_mirror_vma(vma);
91521+ if (!vma_m)
91522+ return;
91523+
91524+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
91525+ address_m = address + SEGMEXEC_TASK_SIZE;
91526+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
91527+ get_page(page_m);
91528+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
91529+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
91530+}
91531+#endif
91532+
91533 /*
91534 * Hugetlb_cow() should be called with page lock of the original hugepage held.
91535 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
91536@@ -2712,6 +2737,11 @@ retry_avoidcopy:
91537 make_huge_pte(vma, new_page, 1));
91538 page_remove_rmap(old_page);
91539 hugepage_add_new_anon_rmap(new_page, vma, address);
91540+
91541+#ifdef CONFIG_PAX_SEGMEXEC
91542+ pax_mirror_huge_pte(vma, address, new_page);
91543+#endif
91544+
91545 /* Make the old page be freed below */
91546 new_page = old_page;
91547 }
91548@@ -2876,6 +2906,10 @@ retry:
91549 && (vma->vm_flags & VM_SHARED)));
91550 set_huge_pte_at(mm, address, ptep, new_pte);
91551
91552+#ifdef CONFIG_PAX_SEGMEXEC
91553+ pax_mirror_huge_pte(vma, address, page);
91554+#endif
91555+
91556 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
91557 /* Optimization, do the COW without a second fault */
91558 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
91559@@ -2906,6 +2940,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91560 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
91561 struct hstate *h = hstate_vma(vma);
91562
91563+#ifdef CONFIG_PAX_SEGMEXEC
91564+ struct vm_area_struct *vma_m;
91565+#endif
91566+
91567 address &= huge_page_mask(h);
91568
91569 ptep = huge_pte_offset(mm, address);
91570@@ -2919,6 +2957,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91571 VM_FAULT_SET_HINDEX(hstate_index(h));
91572 }
91573
91574+#ifdef CONFIG_PAX_SEGMEXEC
91575+ vma_m = pax_find_mirror_vma(vma);
91576+ if (vma_m) {
91577+ unsigned long address_m;
91578+
91579+ if (vma->vm_start > vma_m->vm_start) {
91580+ address_m = address;
91581+ address -= SEGMEXEC_TASK_SIZE;
91582+ vma = vma_m;
91583+ h = hstate_vma(vma);
91584+ } else
91585+ address_m = address + SEGMEXEC_TASK_SIZE;
91586+
91587+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
91588+ return VM_FAULT_OOM;
91589+ address_m &= HPAGE_MASK;
91590+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
91591+ }
91592+#endif
91593+
91594 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
91595 if (!ptep)
91596 return VM_FAULT_OOM;
91597diff --git a/mm/internal.h b/mm/internal.h
91598index 8b6cfd6..ec809a6 100644
91599--- a/mm/internal.h
91600+++ b/mm/internal.h
91601@@ -96,6 +96,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
91602 * in mm/page_alloc.c
91603 */
91604 extern void __free_pages_bootmem(struct page *page, unsigned int order);
91605+extern void free_compound_page(struct page *page);
91606 extern void prep_compound_page(struct page *page, unsigned long order);
91607 #ifdef CONFIG_MEMORY_FAILURE
91608 extern bool is_free_buddy_page(struct page *page);
91609@@ -351,7 +352,7 @@ extern u32 hwpoison_filter_enable;
91610
91611 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
91612 unsigned long, unsigned long,
91613- unsigned long, unsigned long);
91614+ unsigned long, unsigned long) __intentional_overflow(-1);
91615
91616 extern void set_pageblock_order(void);
91617 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
91618diff --git a/mm/kmemleak.c b/mm/kmemleak.c
91619index 31f01c5..7015178 100644
91620--- a/mm/kmemleak.c
91621+++ b/mm/kmemleak.c
91622@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
91623
91624 for (i = 0; i < object->trace_len; i++) {
91625 void *ptr = (void *)object->trace[i];
91626- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
91627+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
91628 }
91629 }
91630
91631@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
91632 return -ENOMEM;
91633 }
91634
91635- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
91636+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
91637 &kmemleak_fops);
91638 if (!dentry)
91639 pr_warning("Failed to create the debugfs kmemleak file\n");
91640diff --git a/mm/maccess.c b/mm/maccess.c
91641index d53adf9..03a24bf 100644
91642--- a/mm/maccess.c
91643+++ b/mm/maccess.c
91644@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
91645 set_fs(KERNEL_DS);
91646 pagefault_disable();
91647 ret = __copy_from_user_inatomic(dst,
91648- (__force const void __user *)src, size);
91649+ (const void __force_user *)src, size);
91650 pagefault_enable();
91651 set_fs(old_fs);
91652
91653@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
91654
91655 set_fs(KERNEL_DS);
91656 pagefault_disable();
91657- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
91658+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
91659 pagefault_enable();
91660 set_fs(old_fs);
91661
91662diff --git a/mm/madvise.c b/mm/madvise.c
91663index 539eeb9..e24a987 100644
91664--- a/mm/madvise.c
91665+++ b/mm/madvise.c
91666@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
91667 pgoff_t pgoff;
91668 unsigned long new_flags = vma->vm_flags;
91669
91670+#ifdef CONFIG_PAX_SEGMEXEC
91671+ struct vm_area_struct *vma_m;
91672+#endif
91673+
91674 switch (behavior) {
91675 case MADV_NORMAL:
91676 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
91677@@ -126,6 +130,13 @@ success:
91678 /*
91679 * vm_flags is protected by the mmap_sem held in write mode.
91680 */
91681+
91682+#ifdef CONFIG_PAX_SEGMEXEC
91683+ vma_m = pax_find_mirror_vma(vma);
91684+ if (vma_m)
91685+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
91686+#endif
91687+
91688 vma->vm_flags = new_flags;
91689
91690 out:
91691@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
91692 struct vm_area_struct **prev,
91693 unsigned long start, unsigned long end)
91694 {
91695+
91696+#ifdef CONFIG_PAX_SEGMEXEC
91697+ struct vm_area_struct *vma_m;
91698+#endif
91699+
91700 *prev = vma;
91701 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
91702 return -EINVAL;
91703@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
91704 zap_page_range(vma, start, end - start, &details);
91705 } else
91706 zap_page_range(vma, start, end - start, NULL);
91707+
91708+#ifdef CONFIG_PAX_SEGMEXEC
91709+ vma_m = pax_find_mirror_vma(vma);
91710+ if (vma_m) {
91711+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
91712+ struct zap_details details = {
91713+ .nonlinear_vma = vma_m,
91714+ .last_index = ULONG_MAX,
91715+ };
91716+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
91717+ } else
91718+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
91719+ }
91720+#endif
91721+
91722 return 0;
91723 }
91724
91725@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
91726 if (end < start)
91727 return error;
91728
91729+#ifdef CONFIG_PAX_SEGMEXEC
91730+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
91731+ if (end > SEGMEXEC_TASK_SIZE)
91732+ return error;
91733+ } else
91734+#endif
91735+
91736+ if (end > TASK_SIZE)
91737+ return error;
91738+
91739 error = 0;
91740 if (end == start)
91741 return error;
91742diff --git a/mm/memory-failure.c b/mm/memory-failure.c
91743index 4566e8f..46be98c 100644
91744--- a/mm/memory-failure.c
91745+++ b/mm/memory-failure.c
91746@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
91747
91748 int sysctl_memory_failure_recovery __read_mostly = 1;
91749
91750-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
91751+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
91752
91753 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
91754
91755@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
91756 pfn, t->comm, t->pid);
91757 si.si_signo = SIGBUS;
91758 si.si_errno = 0;
91759- si.si_addr = (void *)addr;
91760+ si.si_addr = (void __user *)addr;
91761 #ifdef __ARCH_SI_TRAPNO
91762 si.si_trapno = trapno;
91763 #endif
91764@@ -762,7 +762,7 @@ static struct page_state {
91765 unsigned long res;
91766 char *msg;
91767 int (*action)(struct page *p, unsigned long pfn);
91768-} error_states[] = {
91769+} __do_const error_states[] = {
91770 { reserved, reserved, "reserved kernel", me_kernel },
91771 /*
91772 * free pages are specially detected outside this table:
91773@@ -1062,7 +1062,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91774 nr_pages = 1 << compound_order(hpage);
91775 else /* normal page or thp */
91776 nr_pages = 1;
91777- atomic_long_add(nr_pages, &num_poisoned_pages);
91778+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
91779
91780 /*
91781 * We need/can do nothing about count=0 pages.
91782@@ -1092,7 +1092,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91783 if (!PageHWPoison(hpage)
91784 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
91785 || (p != hpage && TestSetPageHWPoison(hpage))) {
91786- atomic_long_sub(nr_pages, &num_poisoned_pages);
91787+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91788 return 0;
91789 }
91790 set_page_hwpoison_huge_page(hpage);
91791@@ -1161,7 +1161,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91792 }
91793 if (hwpoison_filter(p)) {
91794 if (TestClearPageHWPoison(p))
91795- atomic_long_sub(nr_pages, &num_poisoned_pages);
91796+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91797 unlock_page(hpage);
91798 put_page(hpage);
91799 return 0;
91800@@ -1383,7 +1383,7 @@ int unpoison_memory(unsigned long pfn)
91801 return 0;
91802 }
91803 if (TestClearPageHWPoison(p))
91804- atomic_long_dec(&num_poisoned_pages);
91805+ atomic_long_dec_unchecked(&num_poisoned_pages);
91806 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
91807 return 0;
91808 }
91809@@ -1397,7 +1397,7 @@ int unpoison_memory(unsigned long pfn)
91810 */
91811 if (TestClearPageHWPoison(page)) {
91812 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
91813- atomic_long_sub(nr_pages, &num_poisoned_pages);
91814+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91815 freeit = 1;
91816 if (PageHuge(page))
91817 clear_page_hwpoison_huge_page(page);
91818@@ -1522,11 +1522,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
91819 if (PageHuge(page)) {
91820 set_page_hwpoison_huge_page(hpage);
91821 dequeue_hwpoisoned_huge_page(hpage);
91822- atomic_long_add(1 << compound_order(hpage),
91823+ atomic_long_add_unchecked(1 << compound_order(hpage),
91824 &num_poisoned_pages);
91825 } else {
91826 SetPageHWPoison(page);
91827- atomic_long_inc(&num_poisoned_pages);
91828+ atomic_long_inc_unchecked(&num_poisoned_pages);
91829 }
91830 }
91831 return ret;
91832@@ -1565,7 +1565,7 @@ static int __soft_offline_page(struct page *page, int flags)
91833 put_page(page);
91834 pr_info("soft_offline: %#lx: invalidated\n", pfn);
91835 SetPageHWPoison(page);
91836- atomic_long_inc(&num_poisoned_pages);
91837+ atomic_long_inc_unchecked(&num_poisoned_pages);
91838 return 0;
91839 }
91840
91841@@ -1610,7 +1610,7 @@ static int __soft_offline_page(struct page *page, int flags)
91842 if (!is_free_buddy_page(page))
91843 pr_info("soft offline: %#lx: page leaked\n",
91844 pfn);
91845- atomic_long_inc(&num_poisoned_pages);
91846+ atomic_long_inc_unchecked(&num_poisoned_pages);
91847 }
91848 } else {
91849 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
91850@@ -1684,11 +1684,11 @@ int soft_offline_page(struct page *page, int flags)
91851 if (PageHuge(page)) {
91852 set_page_hwpoison_huge_page(hpage);
91853 dequeue_hwpoisoned_huge_page(hpage);
91854- atomic_long_add(1 << compound_order(hpage),
91855+ atomic_long_add_unchecked(1 << compound_order(hpage),
91856 &num_poisoned_pages);
91857 } else {
91858 SetPageHWPoison(page);
91859- atomic_long_inc(&num_poisoned_pages);
91860+ atomic_long_inc_unchecked(&num_poisoned_pages);
91861 }
91862 }
91863 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
91864diff --git a/mm/memory.c b/mm/memory.c
91865index dda27b9..c56b9d6 100644
91866--- a/mm/memory.c
91867+++ b/mm/memory.c
91868@@ -402,6 +402,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
91869 free_pte_range(tlb, pmd, addr);
91870 } while (pmd++, addr = next, addr != end);
91871
91872+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
91873 start &= PUD_MASK;
91874 if (start < floor)
91875 return;
91876@@ -416,6 +417,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
91877 pmd = pmd_offset(pud, start);
91878 pud_clear(pud);
91879 pmd_free_tlb(tlb, pmd, start);
91880+#endif
91881+
91882 }
91883
91884 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
91885@@ -435,6 +438,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
91886 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
91887 } while (pud++, addr = next, addr != end);
91888
91889+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
91890 start &= PGDIR_MASK;
91891 if (start < floor)
91892 return;
91893@@ -449,6 +453,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
91894 pud = pud_offset(pgd, start);
91895 pgd_clear(pgd);
91896 pud_free_tlb(tlb, pud, start);
91897+#endif
91898+
91899 }
91900
91901 /*
91902@@ -1635,12 +1641,6 @@ no_page_table:
91903 return page;
91904 }
91905
91906-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
91907-{
91908- return stack_guard_page_start(vma, addr) ||
91909- stack_guard_page_end(vma, addr+PAGE_SIZE);
91910-}
91911-
91912 /**
91913 * __get_user_pages() - pin user pages in memory
91914 * @tsk: task_struct of target task
91915@@ -1727,10 +1727,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
91916
91917 i = 0;
91918
91919- do {
91920+ while (nr_pages) {
91921 struct vm_area_struct *vma;
91922
91923- vma = find_extend_vma(mm, start);
91924+ vma = find_vma(mm, start);
91925 if (!vma && in_gate_area(mm, start)) {
91926 unsigned long pg = start & PAGE_MASK;
91927 pgd_t *pgd;
91928@@ -1779,7 +1779,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
91929 goto next_page;
91930 }
91931
91932- if (!vma ||
91933+ if (!vma || start < vma->vm_start ||
91934 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
91935 !(vm_flags & vma->vm_flags))
91936 return i ? : -EFAULT;
91937@@ -1808,11 +1808,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
91938 int ret;
91939 unsigned int fault_flags = 0;
91940
91941- /* For mlock, just skip the stack guard page. */
91942- if (foll_flags & FOLL_MLOCK) {
91943- if (stack_guard_page(vma, start))
91944- goto next_page;
91945- }
91946 if (foll_flags & FOLL_WRITE)
91947 fault_flags |= FAULT_FLAG_WRITE;
91948 if (nonblocking)
91949@@ -1892,7 +1887,7 @@ next_page:
91950 start += page_increm * PAGE_SIZE;
91951 nr_pages -= page_increm;
91952 } while (nr_pages && start < vma->vm_end);
91953- } while (nr_pages);
91954+ }
91955 return i;
91956 }
91957 EXPORT_SYMBOL(__get_user_pages);
91958@@ -2099,6 +2094,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
91959 page_add_file_rmap(page);
91960 set_pte_at(mm, addr, pte, mk_pte(page, prot));
91961
91962+#ifdef CONFIG_PAX_SEGMEXEC
91963+ pax_mirror_file_pte(vma, addr, page, ptl);
91964+#endif
91965+
91966 retval = 0;
91967 pte_unmap_unlock(pte, ptl);
91968 return retval;
91969@@ -2143,9 +2142,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
91970 if (!page_count(page))
91971 return -EINVAL;
91972 if (!(vma->vm_flags & VM_MIXEDMAP)) {
91973+
91974+#ifdef CONFIG_PAX_SEGMEXEC
91975+ struct vm_area_struct *vma_m;
91976+#endif
91977+
91978 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
91979 BUG_ON(vma->vm_flags & VM_PFNMAP);
91980 vma->vm_flags |= VM_MIXEDMAP;
91981+
91982+#ifdef CONFIG_PAX_SEGMEXEC
91983+ vma_m = pax_find_mirror_vma(vma);
91984+ if (vma_m)
91985+ vma_m->vm_flags |= VM_MIXEDMAP;
91986+#endif
91987+
91988 }
91989 return insert_page(vma, addr, page, vma->vm_page_prot);
91990 }
91991@@ -2228,6 +2239,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
91992 unsigned long pfn)
91993 {
91994 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
91995+ BUG_ON(vma->vm_mirror);
91996
91997 if (addr < vma->vm_start || addr >= vma->vm_end)
91998 return -EFAULT;
91999@@ -2475,7 +2487,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
92000
92001 BUG_ON(pud_huge(*pud));
92002
92003- pmd = pmd_alloc(mm, pud, addr);
92004+ pmd = (mm == &init_mm) ?
92005+ pmd_alloc_kernel(mm, pud, addr) :
92006+ pmd_alloc(mm, pud, addr);
92007 if (!pmd)
92008 return -ENOMEM;
92009 do {
92010@@ -2495,7 +2509,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
92011 unsigned long next;
92012 int err;
92013
92014- pud = pud_alloc(mm, pgd, addr);
92015+ pud = (mm == &init_mm) ?
92016+ pud_alloc_kernel(mm, pgd, addr) :
92017+ pud_alloc(mm, pgd, addr);
92018 if (!pud)
92019 return -ENOMEM;
92020 do {
92021@@ -2583,6 +2599,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
92022 copy_user_highpage(dst, src, va, vma);
92023 }
92024
92025+#ifdef CONFIG_PAX_SEGMEXEC
92026+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
92027+{
92028+ struct mm_struct *mm = vma->vm_mm;
92029+ spinlock_t *ptl;
92030+ pte_t *pte, entry;
92031+
92032+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
92033+ entry = *pte;
92034+ if (!pte_present(entry)) {
92035+ if (!pte_none(entry)) {
92036+ BUG_ON(pte_file(entry));
92037+ free_swap_and_cache(pte_to_swp_entry(entry));
92038+ pte_clear_not_present_full(mm, address, pte, 0);
92039+ }
92040+ } else {
92041+ struct page *page;
92042+
92043+ flush_cache_page(vma, address, pte_pfn(entry));
92044+ entry = ptep_clear_flush(vma, address, pte);
92045+ BUG_ON(pte_dirty(entry));
92046+ page = vm_normal_page(vma, address, entry);
92047+ if (page) {
92048+ update_hiwater_rss(mm);
92049+ if (PageAnon(page))
92050+ dec_mm_counter_fast(mm, MM_ANONPAGES);
92051+ else
92052+ dec_mm_counter_fast(mm, MM_FILEPAGES);
92053+ page_remove_rmap(page);
92054+ page_cache_release(page);
92055+ }
92056+ }
92057+ pte_unmap_unlock(pte, ptl);
92058+}
92059+
92060+/* PaX: if vma is mirrored, synchronize the mirror's PTE
92061+ *
92062+ * the ptl of the lower mapped page is held on entry and is not released on exit
92063+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
92064+ */
92065+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
92066+{
92067+ struct mm_struct *mm = vma->vm_mm;
92068+ unsigned long address_m;
92069+ spinlock_t *ptl_m;
92070+ struct vm_area_struct *vma_m;
92071+ pmd_t *pmd_m;
92072+ pte_t *pte_m, entry_m;
92073+
92074+ BUG_ON(!page_m || !PageAnon(page_m));
92075+
92076+ vma_m = pax_find_mirror_vma(vma);
92077+ if (!vma_m)
92078+ return;
92079+
92080+ BUG_ON(!PageLocked(page_m));
92081+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92082+ address_m = address + SEGMEXEC_TASK_SIZE;
92083+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92084+ pte_m = pte_offset_map(pmd_m, address_m);
92085+ ptl_m = pte_lockptr(mm, pmd_m);
92086+ if (ptl != ptl_m) {
92087+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92088+ if (!pte_none(*pte_m))
92089+ goto out;
92090+ }
92091+
92092+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92093+ page_cache_get(page_m);
92094+ page_add_anon_rmap(page_m, vma_m, address_m);
92095+ inc_mm_counter_fast(mm, MM_ANONPAGES);
92096+ set_pte_at(mm, address_m, pte_m, entry_m);
92097+ update_mmu_cache(vma_m, address_m, pte_m);
92098+out:
92099+ if (ptl != ptl_m)
92100+ spin_unlock(ptl_m);
92101+ pte_unmap(pte_m);
92102+ unlock_page(page_m);
92103+}
92104+
92105+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
92106+{
92107+ struct mm_struct *mm = vma->vm_mm;
92108+ unsigned long address_m;
92109+ spinlock_t *ptl_m;
92110+ struct vm_area_struct *vma_m;
92111+ pmd_t *pmd_m;
92112+ pte_t *pte_m, entry_m;
92113+
92114+ BUG_ON(!page_m || PageAnon(page_m));
92115+
92116+ vma_m = pax_find_mirror_vma(vma);
92117+ if (!vma_m)
92118+ return;
92119+
92120+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92121+ address_m = address + SEGMEXEC_TASK_SIZE;
92122+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92123+ pte_m = pte_offset_map(pmd_m, address_m);
92124+ ptl_m = pte_lockptr(mm, pmd_m);
92125+ if (ptl != ptl_m) {
92126+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92127+ if (!pte_none(*pte_m))
92128+ goto out;
92129+ }
92130+
92131+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92132+ page_cache_get(page_m);
92133+ page_add_file_rmap(page_m);
92134+ inc_mm_counter_fast(mm, MM_FILEPAGES);
92135+ set_pte_at(mm, address_m, pte_m, entry_m);
92136+ update_mmu_cache(vma_m, address_m, pte_m);
92137+out:
92138+ if (ptl != ptl_m)
92139+ spin_unlock(ptl_m);
92140+ pte_unmap(pte_m);
92141+}
92142+
92143+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
92144+{
92145+ struct mm_struct *mm = vma->vm_mm;
92146+ unsigned long address_m;
92147+ spinlock_t *ptl_m;
92148+ struct vm_area_struct *vma_m;
92149+ pmd_t *pmd_m;
92150+ pte_t *pte_m, entry_m;
92151+
92152+ vma_m = pax_find_mirror_vma(vma);
92153+ if (!vma_m)
92154+ return;
92155+
92156+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92157+ address_m = address + SEGMEXEC_TASK_SIZE;
92158+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92159+ pte_m = pte_offset_map(pmd_m, address_m);
92160+ ptl_m = pte_lockptr(mm, pmd_m);
92161+ if (ptl != ptl_m) {
92162+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92163+ if (!pte_none(*pte_m))
92164+ goto out;
92165+ }
92166+
92167+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
92168+ set_pte_at(mm, address_m, pte_m, entry_m);
92169+out:
92170+ if (ptl != ptl_m)
92171+ spin_unlock(ptl_m);
92172+ pte_unmap(pte_m);
92173+}
92174+
92175+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
92176+{
92177+ struct page *page_m;
92178+ pte_t entry;
92179+
92180+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
92181+ goto out;
92182+
92183+ entry = *pte;
92184+ page_m = vm_normal_page(vma, address, entry);
92185+ if (!page_m)
92186+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
92187+ else if (PageAnon(page_m)) {
92188+ if (pax_find_mirror_vma(vma)) {
92189+ pte_unmap_unlock(pte, ptl);
92190+ lock_page(page_m);
92191+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
92192+ if (pte_same(entry, *pte))
92193+ pax_mirror_anon_pte(vma, address, page_m, ptl);
92194+ else
92195+ unlock_page(page_m);
92196+ }
92197+ } else
92198+ pax_mirror_file_pte(vma, address, page_m, ptl);
92199+
92200+out:
92201+ pte_unmap_unlock(pte, ptl);
92202+}
92203+#endif
92204+
92205 /*
92206 * This routine handles present pages, when users try to write
92207 * to a shared page. It is done by copying the page to a new address
92208@@ -2807,6 +3003,12 @@ gotten:
92209 */
92210 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
92211 if (likely(pte_same(*page_table, orig_pte))) {
92212+
92213+#ifdef CONFIG_PAX_SEGMEXEC
92214+ if (pax_find_mirror_vma(vma))
92215+ BUG_ON(!trylock_page(new_page));
92216+#endif
92217+
92218 if (old_page) {
92219 if (!PageAnon(old_page)) {
92220 dec_mm_counter_fast(mm, MM_FILEPAGES);
92221@@ -2858,6 +3060,10 @@ gotten:
92222 page_remove_rmap(old_page);
92223 }
92224
92225+#ifdef CONFIG_PAX_SEGMEXEC
92226+ pax_mirror_anon_pte(vma, address, new_page, ptl);
92227+#endif
92228+
92229 /* Free the old page.. */
92230 new_page = old_page;
92231 ret |= VM_FAULT_WRITE;
92232@@ -3135,6 +3341,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
92233 swap_free(entry);
92234 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
92235 try_to_free_swap(page);
92236+
92237+#ifdef CONFIG_PAX_SEGMEXEC
92238+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
92239+#endif
92240+
92241 unlock_page(page);
92242 if (page != swapcache) {
92243 /*
92244@@ -3158,6 +3369,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
92245
92246 /* No need to invalidate - it was non-present before */
92247 update_mmu_cache(vma, address, page_table);
92248+
92249+#ifdef CONFIG_PAX_SEGMEXEC
92250+ pax_mirror_anon_pte(vma, address, page, ptl);
92251+#endif
92252+
92253 unlock:
92254 pte_unmap_unlock(page_table, ptl);
92255 out:
92256@@ -3177,40 +3393,6 @@ out_release:
92257 }
92258
92259 /*
92260- * This is like a special single-page "expand_{down|up}wards()",
92261- * except we must first make sure that 'address{-|+}PAGE_SIZE'
92262- * doesn't hit another vma.
92263- */
92264-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
92265-{
92266- address &= PAGE_MASK;
92267- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
92268- struct vm_area_struct *prev = vma->vm_prev;
92269-
92270- /*
92271- * Is there a mapping abutting this one below?
92272- *
92273- * That's only ok if it's the same stack mapping
92274- * that has gotten split..
92275- */
92276- if (prev && prev->vm_end == address)
92277- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
92278-
92279- expand_downwards(vma, address - PAGE_SIZE);
92280- }
92281- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
92282- struct vm_area_struct *next = vma->vm_next;
92283-
92284- /* As VM_GROWSDOWN but s/below/above/ */
92285- if (next && next->vm_start == address + PAGE_SIZE)
92286- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
92287-
92288- expand_upwards(vma, address + PAGE_SIZE);
92289- }
92290- return 0;
92291-}
92292-
92293-/*
92294 * We enter with non-exclusive mmap_sem (to exclude vma changes,
92295 * but allow concurrent faults), and pte mapped but not yet locked.
92296 * We return with mmap_sem still held, but pte unmapped and unlocked.
92297@@ -3219,27 +3401,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
92298 unsigned long address, pte_t *page_table, pmd_t *pmd,
92299 unsigned int flags)
92300 {
92301- struct page *page;
92302+ struct page *page = NULL;
92303 spinlock_t *ptl;
92304 pte_t entry;
92305
92306- pte_unmap(page_table);
92307-
92308- /* Check if we need to add a guard page to the stack */
92309- if (check_stack_guard_page(vma, address) < 0)
92310- return VM_FAULT_SIGBUS;
92311-
92312- /* Use the zero-page for reads */
92313 if (!(flags & FAULT_FLAG_WRITE)) {
92314 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
92315 vma->vm_page_prot));
92316- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
92317+ ptl = pte_lockptr(mm, pmd);
92318+ spin_lock(ptl);
92319 if (!pte_none(*page_table))
92320 goto unlock;
92321 goto setpte;
92322 }
92323
92324 /* Allocate our own private page. */
92325+ pte_unmap(page_table);
92326+
92327 if (unlikely(anon_vma_prepare(vma)))
92328 goto oom;
92329 page = alloc_zeroed_user_highpage_movable(vma, address);
92330@@ -3263,6 +3441,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
92331 if (!pte_none(*page_table))
92332 goto release;
92333
92334+#ifdef CONFIG_PAX_SEGMEXEC
92335+ if (pax_find_mirror_vma(vma))
92336+ BUG_ON(!trylock_page(page));
92337+#endif
92338+
92339 inc_mm_counter_fast(mm, MM_ANONPAGES);
92340 page_add_new_anon_rmap(page, vma, address);
92341 setpte:
92342@@ -3270,6 +3453,12 @@ setpte:
92343
92344 /* No need to invalidate - it was non-present before */
92345 update_mmu_cache(vma, address, page_table);
92346+
92347+#ifdef CONFIG_PAX_SEGMEXEC
92348+ if (page)
92349+ pax_mirror_anon_pte(vma, address, page, ptl);
92350+#endif
92351+
92352 unlock:
92353 pte_unmap_unlock(page_table, ptl);
92354 return 0;
92355@@ -3413,6 +3602,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92356 */
92357 /* Only go through if we didn't race with anybody else... */
92358 if (likely(pte_same(*page_table, orig_pte))) {
92359+
92360+#ifdef CONFIG_PAX_SEGMEXEC
92361+ if (anon && pax_find_mirror_vma(vma))
92362+ BUG_ON(!trylock_page(page));
92363+#endif
92364+
92365 flush_icache_page(vma, page);
92366 entry = mk_pte(page, vma->vm_page_prot);
92367 if (flags & FAULT_FLAG_WRITE)
92368@@ -3434,6 +3629,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92369
92370 /* no need to invalidate: a not-present page won't be cached */
92371 update_mmu_cache(vma, address, page_table);
92372+
92373+#ifdef CONFIG_PAX_SEGMEXEC
92374+ if (anon)
92375+ pax_mirror_anon_pte(vma, address, page, ptl);
92376+ else
92377+ pax_mirror_file_pte(vma, address, page, ptl);
92378+#endif
92379+
92380 } else {
92381 if (cow_page)
92382 mem_cgroup_uncharge_page(cow_page);
92383@@ -3681,6 +3884,12 @@ static int handle_pte_fault(struct mm_struct *mm,
92384 if (flags & FAULT_FLAG_WRITE)
92385 flush_tlb_fix_spurious_fault(vma, address);
92386 }
92387+
92388+#ifdef CONFIG_PAX_SEGMEXEC
92389+ pax_mirror_pte(vma, address, pte, pmd, ptl);
92390+ return 0;
92391+#endif
92392+
92393 unlock:
92394 pte_unmap_unlock(pte, ptl);
92395 return 0;
92396@@ -3697,9 +3906,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92397 pmd_t *pmd;
92398 pte_t *pte;
92399
92400+#ifdef CONFIG_PAX_SEGMEXEC
92401+ struct vm_area_struct *vma_m;
92402+#endif
92403+
92404 if (unlikely(is_vm_hugetlb_page(vma)))
92405 return hugetlb_fault(mm, vma, address, flags);
92406
92407+#ifdef CONFIG_PAX_SEGMEXEC
92408+ vma_m = pax_find_mirror_vma(vma);
92409+ if (vma_m) {
92410+ unsigned long address_m;
92411+ pgd_t *pgd_m;
92412+ pud_t *pud_m;
92413+ pmd_t *pmd_m;
92414+
92415+ if (vma->vm_start > vma_m->vm_start) {
92416+ address_m = address;
92417+ address -= SEGMEXEC_TASK_SIZE;
92418+ vma = vma_m;
92419+ } else
92420+ address_m = address + SEGMEXEC_TASK_SIZE;
92421+
92422+ pgd_m = pgd_offset(mm, address_m);
92423+ pud_m = pud_alloc(mm, pgd_m, address_m);
92424+ if (!pud_m)
92425+ return VM_FAULT_OOM;
92426+ pmd_m = pmd_alloc(mm, pud_m, address_m);
92427+ if (!pmd_m)
92428+ return VM_FAULT_OOM;
92429+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
92430+ return VM_FAULT_OOM;
92431+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
92432+ }
92433+#endif
92434+
92435 pgd = pgd_offset(mm, address);
92436 pud = pud_alloc(mm, pgd, address);
92437 if (!pud)
92438@@ -3830,6 +4071,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
92439 spin_unlock(&mm->page_table_lock);
92440 return 0;
92441 }
92442+
92443+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
92444+{
92445+ pud_t *new = pud_alloc_one(mm, address);
92446+ if (!new)
92447+ return -ENOMEM;
92448+
92449+ smp_wmb(); /* See comment in __pte_alloc */
92450+
92451+ spin_lock(&mm->page_table_lock);
92452+ if (pgd_present(*pgd)) /* Another has populated it */
92453+ pud_free(mm, new);
92454+ else
92455+ pgd_populate_kernel(mm, pgd, new);
92456+ spin_unlock(&mm->page_table_lock);
92457+ return 0;
92458+}
92459 #endif /* __PAGETABLE_PUD_FOLDED */
92460
92461 #ifndef __PAGETABLE_PMD_FOLDED
92462@@ -3860,6 +4118,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
92463 spin_unlock(&mm->page_table_lock);
92464 return 0;
92465 }
92466+
92467+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
92468+{
92469+ pmd_t *new = pmd_alloc_one(mm, address);
92470+ if (!new)
92471+ return -ENOMEM;
92472+
92473+ smp_wmb(); /* See comment in __pte_alloc */
92474+
92475+ spin_lock(&mm->page_table_lock);
92476+#ifndef __ARCH_HAS_4LEVEL_HACK
92477+ if (pud_present(*pud)) /* Another has populated it */
92478+ pmd_free(mm, new);
92479+ else
92480+ pud_populate_kernel(mm, pud, new);
92481+#else
92482+ if (pgd_present(*pud)) /* Another has populated it */
92483+ pmd_free(mm, new);
92484+ else
92485+ pgd_populate_kernel(mm, pud, new);
92486+#endif /* __ARCH_HAS_4LEVEL_HACK */
92487+ spin_unlock(&mm->page_table_lock);
92488+ return 0;
92489+}
92490 #endif /* __PAGETABLE_PMD_FOLDED */
92491
92492 #if !defined(__HAVE_ARCH_GATE_AREA)
92493@@ -3873,7 +4155,7 @@ static int __init gate_vma_init(void)
92494 gate_vma.vm_start = FIXADDR_USER_START;
92495 gate_vma.vm_end = FIXADDR_USER_END;
92496 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
92497- gate_vma.vm_page_prot = __P101;
92498+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
92499
92500 return 0;
92501 }
92502@@ -4007,8 +4289,8 @@ out:
92503 return ret;
92504 }
92505
92506-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
92507- void *buf, int len, int write)
92508+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
92509+ void *buf, size_t len, int write)
92510 {
92511 resource_size_t phys_addr;
92512 unsigned long prot = 0;
92513@@ -4034,8 +4316,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
92514 * Access another process' address space as given in mm. If non-NULL, use the
92515 * given task for page fault accounting.
92516 */
92517-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92518- unsigned long addr, void *buf, int len, int write)
92519+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92520+ unsigned long addr, void *buf, size_t len, int write)
92521 {
92522 struct vm_area_struct *vma;
92523 void *old_buf = buf;
92524@@ -4043,7 +4325,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92525 down_read(&mm->mmap_sem);
92526 /* ignore errors, just check how much was successfully transferred */
92527 while (len) {
92528- int bytes, ret, offset;
92529+ ssize_t bytes, ret, offset;
92530 void *maddr;
92531 struct page *page = NULL;
92532
92533@@ -4102,8 +4384,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92534 *
92535 * The caller must hold a reference on @mm.
92536 */
92537-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
92538- void *buf, int len, int write)
92539+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
92540+ void *buf, size_t len, int write)
92541 {
92542 return __access_remote_vm(NULL, mm, addr, buf, len, write);
92543 }
92544@@ -4113,11 +4395,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
92545 * Source/target buffer must be kernel space,
92546 * Do not walk the page table directly, use get_user_pages
92547 */
92548-int access_process_vm(struct task_struct *tsk, unsigned long addr,
92549- void *buf, int len, int write)
92550+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
92551+ void *buf, size_t len, int write)
92552 {
92553 struct mm_struct *mm;
92554- int ret;
92555+ ssize_t ret;
92556
92557 mm = get_task_mm(tsk);
92558 if (!mm)
92559diff --git a/mm/mempolicy.c b/mm/mempolicy.c
92560index cb2f3dd..fb80468 100644
92561--- a/mm/mempolicy.c
92562+++ b/mm/mempolicy.c
92563@@ -747,6 +747,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
92564 unsigned long vmstart;
92565 unsigned long vmend;
92566
92567+#ifdef CONFIG_PAX_SEGMEXEC
92568+ struct vm_area_struct *vma_m;
92569+#endif
92570+
92571 vma = find_vma(mm, start);
92572 if (!vma || vma->vm_start > start)
92573 return -EFAULT;
92574@@ -790,6 +794,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
92575 err = vma_replace_policy(vma, new_pol);
92576 if (err)
92577 goto out;
92578+
92579+#ifdef CONFIG_PAX_SEGMEXEC
92580+ vma_m = pax_find_mirror_vma(vma);
92581+ if (vma_m) {
92582+ err = vma_replace_policy(vma_m, new_pol);
92583+ if (err)
92584+ goto out;
92585+ }
92586+#endif
92587+
92588 }
92589
92590 out:
92591@@ -1255,6 +1269,17 @@ static long do_mbind(unsigned long start, unsigned long len,
92592
92593 if (end < start)
92594 return -EINVAL;
92595+
92596+#ifdef CONFIG_PAX_SEGMEXEC
92597+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
92598+ if (end > SEGMEXEC_TASK_SIZE)
92599+ return -EINVAL;
92600+ } else
92601+#endif
92602+
92603+ if (end > TASK_SIZE)
92604+ return -EINVAL;
92605+
92606 if (end == start)
92607 return 0;
92608
92609@@ -1483,8 +1508,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
92610 */
92611 tcred = __task_cred(task);
92612 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
92613- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
92614- !capable(CAP_SYS_NICE)) {
92615+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
92616 rcu_read_unlock();
92617 err = -EPERM;
92618 goto out_put;
92619@@ -1515,6 +1539,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
92620 goto out;
92621 }
92622
92623+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
92624+ if (mm != current->mm &&
92625+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
92626+ mmput(mm);
92627+ err = -EPERM;
92628+ goto out;
92629+ }
92630+#endif
92631+
92632 err = do_migrate_pages(mm, old, new,
92633 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
92634
92635diff --git a/mm/migrate.c b/mm/migrate.c
92636index 9194375..75c81e2 100644
92637--- a/mm/migrate.c
92638+++ b/mm/migrate.c
92639@@ -1464,8 +1464,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
92640 */
92641 tcred = __task_cred(task);
92642 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
92643- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
92644- !capable(CAP_SYS_NICE)) {
92645+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
92646 rcu_read_unlock();
92647 err = -EPERM;
92648 goto out;
92649diff --git a/mm/mlock.c b/mm/mlock.c
92650index 192e6ee..b044449 100644
92651--- a/mm/mlock.c
92652+++ b/mm/mlock.c
92653@@ -14,6 +14,7 @@
92654 #include <linux/pagevec.h>
92655 #include <linux/mempolicy.h>
92656 #include <linux/syscalls.h>
92657+#include <linux/security.h>
92658 #include <linux/sched.h>
92659 #include <linux/export.h>
92660 #include <linux/rmap.h>
92661@@ -588,7 +589,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
92662 {
92663 unsigned long nstart, end, tmp;
92664 struct vm_area_struct * vma, * prev;
92665- int error;
92666+ int error = 0;
92667
92668 VM_BUG_ON(start & ~PAGE_MASK);
92669 VM_BUG_ON(len != PAGE_ALIGN(len));
92670@@ -597,6 +598,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
92671 return -EINVAL;
92672 if (end == start)
92673 return 0;
92674+ if (end > TASK_SIZE)
92675+ return -EINVAL;
92676+
92677 vma = find_vma(current->mm, start);
92678 if (!vma || vma->vm_start > start)
92679 return -ENOMEM;
92680@@ -608,6 +612,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
92681 for (nstart = start ; ; ) {
92682 vm_flags_t newflags;
92683
92684+#ifdef CONFIG_PAX_SEGMEXEC
92685+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
92686+ break;
92687+#endif
92688+
92689 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
92690
92691 newflags = vma->vm_flags & ~VM_LOCKED;
92692@@ -720,6 +729,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
92693 lock_limit >>= PAGE_SHIFT;
92694
92695 /* check against resource limits */
92696+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
92697 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
92698 error = do_mlock(start, len, 1);
92699 up_write(&current->mm->mmap_sem);
92700@@ -754,6 +764,11 @@ static int do_mlockall(int flags)
92701 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
92702 vm_flags_t newflags;
92703
92704+#ifdef CONFIG_PAX_SEGMEXEC
92705+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
92706+ break;
92707+#endif
92708+
92709 newflags = vma->vm_flags & ~VM_LOCKED;
92710 if (flags & MCL_CURRENT)
92711 newflags |= VM_LOCKED;
92712@@ -787,6 +802,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
92713 lock_limit >>= PAGE_SHIFT;
92714
92715 ret = -ENOMEM;
92716+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
92717 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
92718 capable(CAP_IPC_LOCK))
92719 ret = do_mlockall(flags);
92720diff --git a/mm/mmap.c b/mm/mmap.c
92721index 546db74..650d1b9 100644
92722--- a/mm/mmap.c
92723+++ b/mm/mmap.c
92724@@ -36,6 +36,7 @@
92725 #include <linux/sched/sysctl.h>
92726 #include <linux/notifier.h>
92727 #include <linux/memory.h>
92728+#include <linux/random.h>
92729
92730 #include <asm/uaccess.h>
92731 #include <asm/cacheflush.h>
92732@@ -52,6 +53,16 @@
92733 #define arch_rebalance_pgtables(addr, len) (addr)
92734 #endif
92735
92736+static inline void verify_mm_writelocked(struct mm_struct *mm)
92737+{
92738+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
92739+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
92740+ up_read(&mm->mmap_sem);
92741+ BUG();
92742+ }
92743+#endif
92744+}
92745+
92746 static void unmap_region(struct mm_struct *mm,
92747 struct vm_area_struct *vma, struct vm_area_struct *prev,
92748 unsigned long start, unsigned long end);
92749@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
92750 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
92751 *
92752 */
92753-pgprot_t protection_map[16] = {
92754+pgprot_t protection_map[16] __read_only = {
92755 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
92756 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
92757 };
92758
92759-pgprot_t vm_get_page_prot(unsigned long vm_flags)
92760+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
92761 {
92762- return __pgprot(pgprot_val(protection_map[vm_flags &
92763+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
92764 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
92765 pgprot_val(arch_vm_get_page_prot(vm_flags)));
92766+
92767+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
92768+ if (!(__supported_pte_mask & _PAGE_NX) &&
92769+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
92770+ (vm_flags & (VM_READ | VM_WRITE)))
92771+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
92772+#endif
92773+
92774+ return prot;
92775 }
92776 EXPORT_SYMBOL(vm_get_page_prot);
92777
92778@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
92779 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
92780 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
92781 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
92782+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
92783 /*
92784 * Make sure vm_committed_as in one cacheline and not cacheline shared with
92785 * other variables. It can be updated by several CPUs frequently.
92786@@ -245,6 +266,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
92787 struct vm_area_struct *next = vma->vm_next;
92788
92789 might_sleep();
92790+ BUG_ON(vma->vm_mirror);
92791 if (vma->vm_ops && vma->vm_ops->close)
92792 vma->vm_ops->close(vma);
92793 if (vma->vm_file)
92794@@ -289,6 +311,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
92795 * not page aligned -Ram Gupta
92796 */
92797 rlim = rlimit(RLIMIT_DATA);
92798+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
92799 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
92800 (mm->end_data - mm->start_data) > rlim)
92801 goto out;
92802@@ -939,6 +962,12 @@ static int
92803 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
92804 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
92805 {
92806+
92807+#ifdef CONFIG_PAX_SEGMEXEC
92808+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
92809+ return 0;
92810+#endif
92811+
92812 if (is_mergeable_vma(vma, file, vm_flags) &&
92813 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
92814 if (vma->vm_pgoff == vm_pgoff)
92815@@ -958,6 +987,12 @@ static int
92816 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
92817 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
92818 {
92819+
92820+#ifdef CONFIG_PAX_SEGMEXEC
92821+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
92822+ return 0;
92823+#endif
92824+
92825 if (is_mergeable_vma(vma, file, vm_flags) &&
92826 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
92827 pgoff_t vm_pglen;
92828@@ -1000,13 +1035,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
92829 struct vm_area_struct *vma_merge(struct mm_struct *mm,
92830 struct vm_area_struct *prev, unsigned long addr,
92831 unsigned long end, unsigned long vm_flags,
92832- struct anon_vma *anon_vma, struct file *file,
92833+ struct anon_vma *anon_vma, struct file *file,
92834 pgoff_t pgoff, struct mempolicy *policy)
92835 {
92836 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
92837 struct vm_area_struct *area, *next;
92838 int err;
92839
92840+#ifdef CONFIG_PAX_SEGMEXEC
92841+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
92842+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
92843+
92844+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
92845+#endif
92846+
92847 /*
92848 * We later require that vma->vm_flags == vm_flags,
92849 * so this tests vma->vm_flags & VM_SPECIAL, too.
92850@@ -1022,6 +1064,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
92851 if (next && next->vm_end == end) /* cases 6, 7, 8 */
92852 next = next->vm_next;
92853
92854+#ifdef CONFIG_PAX_SEGMEXEC
92855+ if (prev)
92856+ prev_m = pax_find_mirror_vma(prev);
92857+ if (area)
92858+ area_m = pax_find_mirror_vma(area);
92859+ if (next)
92860+ next_m = pax_find_mirror_vma(next);
92861+#endif
92862+
92863 /*
92864 * Can it merge with the predecessor?
92865 */
92866@@ -1041,9 +1092,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
92867 /* cases 1, 6 */
92868 err = vma_adjust(prev, prev->vm_start,
92869 next->vm_end, prev->vm_pgoff, NULL);
92870- } else /* cases 2, 5, 7 */
92871+
92872+#ifdef CONFIG_PAX_SEGMEXEC
92873+ if (!err && prev_m)
92874+ err = vma_adjust(prev_m, prev_m->vm_start,
92875+ next_m->vm_end, prev_m->vm_pgoff, NULL);
92876+#endif
92877+
92878+ } else { /* cases 2, 5, 7 */
92879 err = vma_adjust(prev, prev->vm_start,
92880 end, prev->vm_pgoff, NULL);
92881+
92882+#ifdef CONFIG_PAX_SEGMEXEC
92883+ if (!err && prev_m)
92884+ err = vma_adjust(prev_m, prev_m->vm_start,
92885+ end_m, prev_m->vm_pgoff, NULL);
92886+#endif
92887+
92888+ }
92889 if (err)
92890 return NULL;
92891 khugepaged_enter_vma_merge(prev);
92892@@ -1057,12 +1123,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
92893 mpol_equal(policy, vma_policy(next)) &&
92894 can_vma_merge_before(next, vm_flags,
92895 anon_vma, file, pgoff+pglen)) {
92896- if (prev && addr < prev->vm_end) /* case 4 */
92897+ if (prev && addr < prev->vm_end) { /* case 4 */
92898 err = vma_adjust(prev, prev->vm_start,
92899 addr, prev->vm_pgoff, NULL);
92900- else /* cases 3, 8 */
92901+
92902+#ifdef CONFIG_PAX_SEGMEXEC
92903+ if (!err && prev_m)
92904+ err = vma_adjust(prev_m, prev_m->vm_start,
92905+ addr_m, prev_m->vm_pgoff, NULL);
92906+#endif
92907+
92908+ } else { /* cases 3, 8 */
92909 err = vma_adjust(area, addr, next->vm_end,
92910 next->vm_pgoff - pglen, NULL);
92911+
92912+#ifdef CONFIG_PAX_SEGMEXEC
92913+ if (!err && area_m)
92914+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
92915+ next_m->vm_pgoff - pglen, NULL);
92916+#endif
92917+
92918+ }
92919 if (err)
92920 return NULL;
92921 khugepaged_enter_vma_merge(area);
92922@@ -1171,8 +1252,10 @@ none:
92923 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
92924 struct file *file, long pages)
92925 {
92926- const unsigned long stack_flags
92927- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
92928+
92929+#ifdef CONFIG_PAX_RANDMMAP
92930+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
92931+#endif
92932
92933 mm->total_vm += pages;
92934
92935@@ -1180,7 +1263,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
92936 mm->shared_vm += pages;
92937 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
92938 mm->exec_vm += pages;
92939- } else if (flags & stack_flags)
92940+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
92941 mm->stack_vm += pages;
92942 }
92943 #endif /* CONFIG_PROC_FS */
92944@@ -1218,7 +1301,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92945 * (the exception is when the underlying filesystem is noexec
92946 * mounted, in which case we dont add PROT_EXEC.)
92947 */
92948- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
92949+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
92950 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
92951 prot |= PROT_EXEC;
92952
92953@@ -1244,7 +1327,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92954 /* Obtain the address to map to. we verify (or select) it and ensure
92955 * that it represents a valid section of the address space.
92956 */
92957- addr = get_unmapped_area(file, addr, len, pgoff, flags);
92958+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
92959 if (addr & ~PAGE_MASK)
92960 return addr;
92961
92962@@ -1255,6 +1338,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92963 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
92964 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
92965
92966+#ifdef CONFIG_PAX_MPROTECT
92967+ if (mm->pax_flags & MF_PAX_MPROTECT) {
92968+
92969+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
92970+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
92971+ mm->binfmt->handle_mmap)
92972+ mm->binfmt->handle_mmap(file);
92973+#endif
92974+
92975+#ifndef CONFIG_PAX_MPROTECT_COMPAT
92976+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
92977+ gr_log_rwxmmap(file);
92978+
92979+#ifdef CONFIG_PAX_EMUPLT
92980+ vm_flags &= ~VM_EXEC;
92981+#else
92982+ return -EPERM;
92983+#endif
92984+
92985+ }
92986+
92987+ if (!(vm_flags & VM_EXEC))
92988+ vm_flags &= ~VM_MAYEXEC;
92989+#else
92990+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
92991+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
92992+#endif
92993+ else
92994+ vm_flags &= ~VM_MAYWRITE;
92995+ }
92996+#endif
92997+
92998+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
92999+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
93000+ vm_flags &= ~VM_PAGEEXEC;
93001+#endif
93002+
93003 if (flags & MAP_LOCKED)
93004 if (!can_do_mlock())
93005 return -EPERM;
93006@@ -1266,6 +1386,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93007 locked += mm->locked_vm;
93008 lock_limit = rlimit(RLIMIT_MEMLOCK);
93009 lock_limit >>= PAGE_SHIFT;
93010+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93011 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
93012 return -EAGAIN;
93013 }
93014@@ -1350,6 +1471,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93015 vm_flags |= VM_NORESERVE;
93016 }
93017
93018+ if (!gr_acl_handle_mmap(file, prot))
93019+ return -EACCES;
93020+
93021 addr = mmap_region(file, addr, len, vm_flags, pgoff);
93022 if (!IS_ERR_VALUE(addr) &&
93023 ((vm_flags & VM_LOCKED) ||
93024@@ -1443,7 +1567,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
93025 vm_flags_t vm_flags = vma->vm_flags;
93026
93027 /* If it was private or non-writable, the write bit is already clear */
93028- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
93029+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
93030 return 0;
93031
93032 /* The backer wishes to know when pages are first written to? */
93033@@ -1489,7 +1613,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
93034 struct rb_node **rb_link, *rb_parent;
93035 unsigned long charged = 0;
93036
93037+#ifdef CONFIG_PAX_SEGMEXEC
93038+ struct vm_area_struct *vma_m = NULL;
93039+#endif
93040+
93041+ /*
93042+ * mm->mmap_sem is required to protect against another thread
93043+ * changing the mappings in case we sleep.
93044+ */
93045+ verify_mm_writelocked(mm);
93046+
93047 /* Check against address space limit. */
93048+
93049+#ifdef CONFIG_PAX_RANDMMAP
93050+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93051+#endif
93052+
93053 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
93054 unsigned long nr_pages;
93055
93056@@ -1508,11 +1647,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
93057
93058 /* Clear old maps */
93059 error = -ENOMEM;
93060-munmap_back:
93061 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
93062 if (do_munmap(mm, addr, len))
93063 return -ENOMEM;
93064- goto munmap_back;
93065+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
93066 }
93067
93068 /*
93069@@ -1543,6 +1681,16 @@ munmap_back:
93070 goto unacct_error;
93071 }
93072
93073+#ifdef CONFIG_PAX_SEGMEXEC
93074+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
93075+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93076+ if (!vma_m) {
93077+ error = -ENOMEM;
93078+ goto free_vma;
93079+ }
93080+ }
93081+#endif
93082+
93083 vma->vm_mm = mm;
93084 vma->vm_start = addr;
93085 vma->vm_end = addr + len;
93086@@ -1562,6 +1710,13 @@ munmap_back:
93087 if (error)
93088 goto unmap_and_free_vma;
93089
93090+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93091+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
93092+ vma->vm_flags |= VM_PAGEEXEC;
93093+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
93094+ }
93095+#endif
93096+
93097 /* Can addr have changed??
93098 *
93099 * Answer: Yes, several device drivers can do it in their
93100@@ -1595,6 +1750,12 @@ munmap_back:
93101 }
93102
93103 vma_link(mm, vma, prev, rb_link, rb_parent);
93104+
93105+#ifdef CONFIG_PAX_SEGMEXEC
93106+ if (vma_m)
93107+ BUG_ON(pax_mirror_vma(vma_m, vma));
93108+#endif
93109+
93110 /* Once vma denies write, undo our temporary denial count */
93111 if (vm_flags & VM_DENYWRITE)
93112 allow_write_access(file);
93113@@ -1603,6 +1764,7 @@ out:
93114 perf_event_mmap(vma);
93115
93116 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
93117+ track_exec_limit(mm, addr, addr + len, vm_flags);
93118 if (vm_flags & VM_LOCKED) {
93119 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
93120 vma == get_gate_vma(current->mm)))
93121@@ -1635,6 +1797,12 @@ unmap_and_free_vma:
93122 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
93123 charged = 0;
93124 free_vma:
93125+
93126+#ifdef CONFIG_PAX_SEGMEXEC
93127+ if (vma_m)
93128+ kmem_cache_free(vm_area_cachep, vma_m);
93129+#endif
93130+
93131 kmem_cache_free(vm_area_cachep, vma);
93132 unacct_error:
93133 if (charged)
93134@@ -1642,7 +1810,63 @@ unacct_error:
93135 return error;
93136 }
93137
93138-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
93139+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
93140+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
93141+{
93142+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
93143+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
93144+
93145+ return 0;
93146+}
93147+#endif
93148+
93149+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
93150+{
93151+ if (!vma) {
93152+#ifdef CONFIG_STACK_GROWSUP
93153+ if (addr > sysctl_heap_stack_gap)
93154+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
93155+ else
93156+ vma = find_vma(current->mm, 0);
93157+ if (vma && (vma->vm_flags & VM_GROWSUP))
93158+ return false;
93159+#endif
93160+ return true;
93161+ }
93162+
93163+ if (addr + len > vma->vm_start)
93164+ return false;
93165+
93166+ if (vma->vm_flags & VM_GROWSDOWN)
93167+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
93168+#ifdef CONFIG_STACK_GROWSUP
93169+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
93170+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
93171+#endif
93172+ else if (offset)
93173+ return offset <= vma->vm_start - addr - len;
93174+
93175+ return true;
93176+}
93177+
93178+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
93179+{
93180+ if (vma->vm_start < len)
93181+ return -ENOMEM;
93182+
93183+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
93184+ if (offset <= vma->vm_start - len)
93185+ return vma->vm_start - len - offset;
93186+ else
93187+ return -ENOMEM;
93188+ }
93189+
93190+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
93191+ return vma->vm_start - len - sysctl_heap_stack_gap;
93192+ return -ENOMEM;
93193+}
93194+
93195+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
93196 {
93197 /*
93198 * We implement the search by looking for an rbtree node that
93199@@ -1690,11 +1914,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
93200 }
93201 }
93202
93203- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
93204+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
93205 check_current:
93206 /* Check if current node has a suitable gap */
93207 if (gap_start > high_limit)
93208 return -ENOMEM;
93209+
93210+ if (gap_end - gap_start > info->threadstack_offset)
93211+ gap_start += info->threadstack_offset;
93212+ else
93213+ gap_start = gap_end;
93214+
93215+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
93216+ if (gap_end - gap_start > sysctl_heap_stack_gap)
93217+ gap_start += sysctl_heap_stack_gap;
93218+ else
93219+ gap_start = gap_end;
93220+ }
93221+ if (vma->vm_flags & VM_GROWSDOWN) {
93222+ if (gap_end - gap_start > sysctl_heap_stack_gap)
93223+ gap_end -= sysctl_heap_stack_gap;
93224+ else
93225+ gap_end = gap_start;
93226+ }
93227 if (gap_end >= low_limit && gap_end - gap_start >= length)
93228 goto found;
93229
93230@@ -1744,7 +1986,7 @@ found:
93231 return gap_start;
93232 }
93233
93234-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
93235+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
93236 {
93237 struct mm_struct *mm = current->mm;
93238 struct vm_area_struct *vma;
93239@@ -1798,6 +2040,24 @@ check_current:
93240 gap_end = vma->vm_start;
93241 if (gap_end < low_limit)
93242 return -ENOMEM;
93243+
93244+ if (gap_end - gap_start > info->threadstack_offset)
93245+ gap_end -= info->threadstack_offset;
93246+ else
93247+ gap_end = gap_start;
93248+
93249+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
93250+ if (gap_end - gap_start > sysctl_heap_stack_gap)
93251+ gap_start += sysctl_heap_stack_gap;
93252+ else
93253+ gap_start = gap_end;
93254+ }
93255+ if (vma->vm_flags & VM_GROWSDOWN) {
93256+ if (gap_end - gap_start > sysctl_heap_stack_gap)
93257+ gap_end -= sysctl_heap_stack_gap;
93258+ else
93259+ gap_end = gap_start;
93260+ }
93261 if (gap_start <= high_limit && gap_end - gap_start >= length)
93262 goto found;
93263
93264@@ -1861,6 +2121,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93265 struct mm_struct *mm = current->mm;
93266 struct vm_area_struct *vma;
93267 struct vm_unmapped_area_info info;
93268+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
93269
93270 if (len > TASK_SIZE - mmap_min_addr)
93271 return -ENOMEM;
93272@@ -1868,11 +2129,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93273 if (flags & MAP_FIXED)
93274 return addr;
93275
93276+#ifdef CONFIG_PAX_RANDMMAP
93277+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
93278+#endif
93279+
93280 if (addr) {
93281 addr = PAGE_ALIGN(addr);
93282 vma = find_vma(mm, addr);
93283 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
93284- (!vma || addr + len <= vma->vm_start))
93285+ check_heap_stack_gap(vma, addr, len, offset))
93286 return addr;
93287 }
93288
93289@@ -1881,6 +2146,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93290 info.low_limit = mm->mmap_base;
93291 info.high_limit = TASK_SIZE;
93292 info.align_mask = 0;
93293+ info.threadstack_offset = offset;
93294 return vm_unmapped_area(&info);
93295 }
93296 #endif
93297@@ -1899,6 +2165,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93298 struct mm_struct *mm = current->mm;
93299 unsigned long addr = addr0;
93300 struct vm_unmapped_area_info info;
93301+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
93302
93303 /* requested length too big for entire address space */
93304 if (len > TASK_SIZE - mmap_min_addr)
93305@@ -1907,12 +2174,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93306 if (flags & MAP_FIXED)
93307 return addr;
93308
93309+#ifdef CONFIG_PAX_RANDMMAP
93310+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
93311+#endif
93312+
93313 /* requesting a specific address */
93314 if (addr) {
93315 addr = PAGE_ALIGN(addr);
93316 vma = find_vma(mm, addr);
93317 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
93318- (!vma || addr + len <= vma->vm_start))
93319+ check_heap_stack_gap(vma, addr, len, offset))
93320 return addr;
93321 }
93322
93323@@ -1921,6 +2192,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93324 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
93325 info.high_limit = mm->mmap_base;
93326 info.align_mask = 0;
93327+ info.threadstack_offset = offset;
93328 addr = vm_unmapped_area(&info);
93329
93330 /*
93331@@ -1933,6 +2205,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93332 VM_BUG_ON(addr != -ENOMEM);
93333 info.flags = 0;
93334 info.low_limit = TASK_UNMAPPED_BASE;
93335+
93336+#ifdef CONFIG_PAX_RANDMMAP
93337+ if (mm->pax_flags & MF_PAX_RANDMMAP)
93338+ info.low_limit += mm->delta_mmap;
93339+#endif
93340+
93341 info.high_limit = TASK_SIZE;
93342 addr = vm_unmapped_area(&info);
93343 }
93344@@ -2034,6 +2312,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
93345 return vma;
93346 }
93347
93348+#ifdef CONFIG_PAX_SEGMEXEC
93349+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
93350+{
93351+ struct vm_area_struct *vma_m;
93352+
93353+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
93354+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
93355+ BUG_ON(vma->vm_mirror);
93356+ return NULL;
93357+ }
93358+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
93359+ vma_m = vma->vm_mirror;
93360+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
93361+ BUG_ON(vma->vm_file != vma_m->vm_file);
93362+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
93363+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
93364+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
93365+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
93366+ return vma_m;
93367+}
93368+#endif
93369+
93370 /*
93371 * Verify that the stack growth is acceptable and
93372 * update accounting. This is shared with both the
93373@@ -2050,6 +2350,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93374 return -ENOMEM;
93375
93376 /* Stack limit test */
93377+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
93378 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
93379 return -ENOMEM;
93380
93381@@ -2060,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93382 locked = mm->locked_vm + grow;
93383 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
93384 limit >>= PAGE_SHIFT;
93385+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93386 if (locked > limit && !capable(CAP_IPC_LOCK))
93387 return -ENOMEM;
93388 }
93389@@ -2089,37 +2391,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93390 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
93391 * vma is the last one with address > vma->vm_end. Have to extend vma.
93392 */
93393+#ifndef CONFIG_IA64
93394+static
93395+#endif
93396 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
93397 {
93398 int error;
93399+ bool locknext;
93400
93401 if (!(vma->vm_flags & VM_GROWSUP))
93402 return -EFAULT;
93403
93404+ /* Also guard against wrapping around to address 0. */
93405+ if (address < PAGE_ALIGN(address+1))
93406+ address = PAGE_ALIGN(address+1);
93407+ else
93408+ return -ENOMEM;
93409+
93410 /*
93411 * We must make sure the anon_vma is allocated
93412 * so that the anon_vma locking is not a noop.
93413 */
93414 if (unlikely(anon_vma_prepare(vma)))
93415 return -ENOMEM;
93416+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
93417+ if (locknext && anon_vma_prepare(vma->vm_next))
93418+ return -ENOMEM;
93419 vma_lock_anon_vma(vma);
93420+ if (locknext)
93421+ vma_lock_anon_vma(vma->vm_next);
93422
93423 /*
93424 * vma->vm_start/vm_end cannot change under us because the caller
93425 * is required to hold the mmap_sem in read mode. We need the
93426- * anon_vma lock to serialize against concurrent expand_stacks.
93427- * Also guard against wrapping around to address 0.
93428+ * anon_vma locks to serialize against concurrent expand_stacks
93429+ * and expand_upwards.
93430 */
93431- if (address < PAGE_ALIGN(address+4))
93432- address = PAGE_ALIGN(address+4);
93433- else {
93434- vma_unlock_anon_vma(vma);
93435- return -ENOMEM;
93436- }
93437 error = 0;
93438
93439 /* Somebody else might have raced and expanded it already */
93440- if (address > vma->vm_end) {
93441+ 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)
93442+ error = -ENOMEM;
93443+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
93444 unsigned long size, grow;
93445
93446 size = address - vma->vm_start;
93447@@ -2154,6 +2467,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
93448 }
93449 }
93450 }
93451+ if (locknext)
93452+ vma_unlock_anon_vma(vma->vm_next);
93453 vma_unlock_anon_vma(vma);
93454 khugepaged_enter_vma_merge(vma);
93455 validate_mm(vma->vm_mm);
93456@@ -2168,6 +2483,8 @@ int expand_downwards(struct vm_area_struct *vma,
93457 unsigned long address)
93458 {
93459 int error;
93460+ bool lockprev = false;
93461+ struct vm_area_struct *prev;
93462
93463 /*
93464 * We must make sure the anon_vma is allocated
93465@@ -2181,6 +2498,15 @@ int expand_downwards(struct vm_area_struct *vma,
93466 if (error)
93467 return error;
93468
93469+ prev = vma->vm_prev;
93470+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
93471+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
93472+#endif
93473+ if (lockprev && anon_vma_prepare(prev))
93474+ return -ENOMEM;
93475+ if (lockprev)
93476+ vma_lock_anon_vma(prev);
93477+
93478 vma_lock_anon_vma(vma);
93479
93480 /*
93481@@ -2190,9 +2516,17 @@ int expand_downwards(struct vm_area_struct *vma,
93482 */
93483
93484 /* Somebody else might have raced and expanded it already */
93485- if (address < vma->vm_start) {
93486+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
93487+ error = -ENOMEM;
93488+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
93489 unsigned long size, grow;
93490
93491+#ifdef CONFIG_PAX_SEGMEXEC
93492+ struct vm_area_struct *vma_m;
93493+
93494+ vma_m = pax_find_mirror_vma(vma);
93495+#endif
93496+
93497 size = vma->vm_end - address;
93498 grow = (vma->vm_start - address) >> PAGE_SHIFT;
93499
93500@@ -2217,13 +2551,27 @@ int expand_downwards(struct vm_area_struct *vma,
93501 vma->vm_pgoff -= grow;
93502 anon_vma_interval_tree_post_update_vma(vma);
93503 vma_gap_update(vma);
93504+
93505+#ifdef CONFIG_PAX_SEGMEXEC
93506+ if (vma_m) {
93507+ anon_vma_interval_tree_pre_update_vma(vma_m);
93508+ vma_m->vm_start -= grow << PAGE_SHIFT;
93509+ vma_m->vm_pgoff -= grow;
93510+ anon_vma_interval_tree_post_update_vma(vma_m);
93511+ vma_gap_update(vma_m);
93512+ }
93513+#endif
93514+
93515 spin_unlock(&vma->vm_mm->page_table_lock);
93516
93517+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
93518 perf_event_mmap(vma);
93519 }
93520 }
93521 }
93522 vma_unlock_anon_vma(vma);
93523+ if (lockprev)
93524+ vma_unlock_anon_vma(prev);
93525 khugepaged_enter_vma_merge(vma);
93526 validate_mm(vma->vm_mm);
93527 return error;
93528@@ -2321,6 +2669,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
93529 do {
93530 long nrpages = vma_pages(vma);
93531
93532+#ifdef CONFIG_PAX_SEGMEXEC
93533+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
93534+ vma = remove_vma(vma);
93535+ continue;
93536+ }
93537+#endif
93538+
93539 if (vma->vm_flags & VM_ACCOUNT)
93540 nr_accounted += nrpages;
93541 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
93542@@ -2365,6 +2720,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
93543 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
93544 vma->vm_prev = NULL;
93545 do {
93546+
93547+#ifdef CONFIG_PAX_SEGMEXEC
93548+ if (vma->vm_mirror) {
93549+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
93550+ vma->vm_mirror->vm_mirror = NULL;
93551+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
93552+ vma->vm_mirror = NULL;
93553+ }
93554+#endif
93555+
93556 vma_rb_erase(vma, &mm->mm_rb);
93557 mm->map_count--;
93558 tail_vma = vma;
93559@@ -2390,14 +2755,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93560 struct vm_area_struct *new;
93561 int err = -ENOMEM;
93562
93563+#ifdef CONFIG_PAX_SEGMEXEC
93564+ struct vm_area_struct *vma_m, *new_m = NULL;
93565+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
93566+#endif
93567+
93568 if (is_vm_hugetlb_page(vma) && (addr &
93569 ~(huge_page_mask(hstate_vma(vma)))))
93570 return -EINVAL;
93571
93572+#ifdef CONFIG_PAX_SEGMEXEC
93573+ vma_m = pax_find_mirror_vma(vma);
93574+#endif
93575+
93576 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
93577 if (!new)
93578 goto out_err;
93579
93580+#ifdef CONFIG_PAX_SEGMEXEC
93581+ if (vma_m) {
93582+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
93583+ if (!new_m) {
93584+ kmem_cache_free(vm_area_cachep, new);
93585+ goto out_err;
93586+ }
93587+ }
93588+#endif
93589+
93590 /* most fields are the same, copy all, and then fixup */
93591 *new = *vma;
93592
93593@@ -2410,6 +2794,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93594 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
93595 }
93596
93597+#ifdef CONFIG_PAX_SEGMEXEC
93598+ if (vma_m) {
93599+ *new_m = *vma_m;
93600+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
93601+ new_m->vm_mirror = new;
93602+ new->vm_mirror = new_m;
93603+
93604+ if (new_below)
93605+ new_m->vm_end = addr_m;
93606+ else {
93607+ new_m->vm_start = addr_m;
93608+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
93609+ }
93610+ }
93611+#endif
93612+
93613 err = vma_dup_policy(vma, new);
93614 if (err)
93615 goto out_free_vma;
93616@@ -2429,6 +2829,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93617 else
93618 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
93619
93620+#ifdef CONFIG_PAX_SEGMEXEC
93621+ if (!err && vma_m) {
93622+ struct mempolicy *pol = vma_policy(new);
93623+
93624+ if (anon_vma_clone(new_m, vma_m))
93625+ goto out_free_mpol;
93626+
93627+ mpol_get(pol);
93628+ set_vma_policy(new_m, pol);
93629+
93630+ if (new_m->vm_file)
93631+ get_file(new_m->vm_file);
93632+
93633+ if (new_m->vm_ops && new_m->vm_ops->open)
93634+ new_m->vm_ops->open(new_m);
93635+
93636+ if (new_below)
93637+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
93638+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
93639+ else
93640+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
93641+
93642+ if (err) {
93643+ if (new_m->vm_ops && new_m->vm_ops->close)
93644+ new_m->vm_ops->close(new_m);
93645+ if (new_m->vm_file)
93646+ fput(new_m->vm_file);
93647+ mpol_put(pol);
93648+ }
93649+ }
93650+#endif
93651+
93652 /* Success. */
93653 if (!err)
93654 return 0;
93655@@ -2438,10 +2870,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93656 new->vm_ops->close(new);
93657 if (new->vm_file)
93658 fput(new->vm_file);
93659- unlink_anon_vmas(new);
93660 out_free_mpol:
93661 mpol_put(vma_policy(new));
93662 out_free_vma:
93663+
93664+#ifdef CONFIG_PAX_SEGMEXEC
93665+ if (new_m) {
93666+ unlink_anon_vmas(new_m);
93667+ kmem_cache_free(vm_area_cachep, new_m);
93668+ }
93669+#endif
93670+
93671+ unlink_anon_vmas(new);
93672 kmem_cache_free(vm_area_cachep, new);
93673 out_err:
93674 return err;
93675@@ -2454,6 +2894,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93676 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
93677 unsigned long addr, int new_below)
93678 {
93679+
93680+#ifdef CONFIG_PAX_SEGMEXEC
93681+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
93682+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
93683+ if (mm->map_count >= sysctl_max_map_count-1)
93684+ return -ENOMEM;
93685+ } else
93686+#endif
93687+
93688 if (mm->map_count >= sysctl_max_map_count)
93689 return -ENOMEM;
93690
93691@@ -2465,11 +2914,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
93692 * work. This now handles partial unmappings.
93693 * Jeremy Fitzhardinge <jeremy@goop.org>
93694 */
93695+#ifdef CONFIG_PAX_SEGMEXEC
93696 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93697 {
93698+ int ret = __do_munmap(mm, start, len);
93699+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
93700+ return ret;
93701+
93702+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
93703+}
93704+
93705+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93706+#else
93707+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93708+#endif
93709+{
93710 unsigned long end;
93711 struct vm_area_struct *vma, *prev, *last;
93712
93713+ /*
93714+ * mm->mmap_sem is required to protect against another thread
93715+ * changing the mappings in case we sleep.
93716+ */
93717+ verify_mm_writelocked(mm);
93718+
93719 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
93720 return -EINVAL;
93721
93722@@ -2544,6 +3012,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93723 /* Fix up all other VM information */
93724 remove_vma_list(mm, vma);
93725
93726+ track_exec_limit(mm, start, end, 0UL);
93727+
93728 return 0;
93729 }
93730
93731@@ -2552,6 +3022,13 @@ int vm_munmap(unsigned long start, size_t len)
93732 int ret;
93733 struct mm_struct *mm = current->mm;
93734
93735+
93736+#ifdef CONFIG_PAX_SEGMEXEC
93737+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
93738+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
93739+ return -EINVAL;
93740+#endif
93741+
93742 down_write(&mm->mmap_sem);
93743 ret = do_munmap(mm, start, len);
93744 up_write(&mm->mmap_sem);
93745@@ -2565,16 +3042,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
93746 return vm_munmap(addr, len);
93747 }
93748
93749-static inline void verify_mm_writelocked(struct mm_struct *mm)
93750-{
93751-#ifdef CONFIG_DEBUG_VM
93752- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
93753- WARN_ON(1);
93754- up_read(&mm->mmap_sem);
93755- }
93756-#endif
93757-}
93758-
93759 /*
93760 * this is really a simplified "do_mmap". it only handles
93761 * anonymous maps. eventually we may be able to do some
93762@@ -2588,6 +3055,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93763 struct rb_node ** rb_link, * rb_parent;
93764 pgoff_t pgoff = addr >> PAGE_SHIFT;
93765 int error;
93766+ unsigned long charged;
93767
93768 len = PAGE_ALIGN(len);
93769 if (!len)
93770@@ -2595,16 +3063,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93771
93772 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
93773
93774+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
93775+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
93776+ flags &= ~VM_EXEC;
93777+
93778+#ifdef CONFIG_PAX_MPROTECT
93779+ if (mm->pax_flags & MF_PAX_MPROTECT)
93780+ flags &= ~VM_MAYEXEC;
93781+#endif
93782+
93783+ }
93784+#endif
93785+
93786 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
93787 if (error & ~PAGE_MASK)
93788 return error;
93789
93790+ charged = len >> PAGE_SHIFT;
93791+
93792 /*
93793 * mlock MCL_FUTURE?
93794 */
93795 if (mm->def_flags & VM_LOCKED) {
93796 unsigned long locked, lock_limit;
93797- locked = len >> PAGE_SHIFT;
93798+ locked = charged;
93799 locked += mm->locked_vm;
93800 lock_limit = rlimit(RLIMIT_MEMLOCK);
93801 lock_limit >>= PAGE_SHIFT;
93802@@ -2621,21 +3103,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93803 /*
93804 * Clear old maps. this also does some error checking for us
93805 */
93806- munmap_back:
93807 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
93808 if (do_munmap(mm, addr, len))
93809 return -ENOMEM;
93810- goto munmap_back;
93811+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
93812 }
93813
93814 /* Check against address space limits *after* clearing old maps... */
93815- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
93816+ if (!may_expand_vm(mm, charged))
93817 return -ENOMEM;
93818
93819 if (mm->map_count > sysctl_max_map_count)
93820 return -ENOMEM;
93821
93822- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
93823+ if (security_vm_enough_memory_mm(mm, charged))
93824 return -ENOMEM;
93825
93826 /* Can we just expand an old private anonymous mapping? */
93827@@ -2649,7 +3130,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93828 */
93829 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93830 if (!vma) {
93831- vm_unacct_memory(len >> PAGE_SHIFT);
93832+ vm_unacct_memory(charged);
93833 return -ENOMEM;
93834 }
93835
93836@@ -2663,10 +3144,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93837 vma_link(mm, vma, prev, rb_link, rb_parent);
93838 out:
93839 perf_event_mmap(vma);
93840- mm->total_vm += len >> PAGE_SHIFT;
93841+ mm->total_vm += charged;
93842 if (flags & VM_LOCKED)
93843- mm->locked_vm += (len >> PAGE_SHIFT);
93844+ mm->locked_vm += charged;
93845 vma->vm_flags |= VM_SOFTDIRTY;
93846+ track_exec_limit(mm, addr, addr + len, flags);
93847 return addr;
93848 }
93849
93850@@ -2728,6 +3210,7 @@ void exit_mmap(struct mm_struct *mm)
93851 while (vma) {
93852 if (vma->vm_flags & VM_ACCOUNT)
93853 nr_accounted += vma_pages(vma);
93854+ vma->vm_mirror = NULL;
93855 vma = remove_vma(vma);
93856 }
93857 vm_unacct_memory(nr_accounted);
93858@@ -2745,6 +3228,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
93859 struct vm_area_struct *prev;
93860 struct rb_node **rb_link, *rb_parent;
93861
93862+#ifdef CONFIG_PAX_SEGMEXEC
93863+ struct vm_area_struct *vma_m = NULL;
93864+#endif
93865+
93866+ if (security_mmap_addr(vma->vm_start))
93867+ return -EPERM;
93868+
93869 /*
93870 * The vm_pgoff of a purely anonymous vma should be irrelevant
93871 * until its first write fault, when page's anon_vma and index
93872@@ -2768,7 +3258,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
93873 security_vm_enough_memory_mm(mm, vma_pages(vma)))
93874 return -ENOMEM;
93875
93876+#ifdef CONFIG_PAX_SEGMEXEC
93877+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
93878+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93879+ if (!vma_m)
93880+ return -ENOMEM;
93881+ }
93882+#endif
93883+
93884 vma_link(mm, vma, prev, rb_link, rb_parent);
93885+
93886+#ifdef CONFIG_PAX_SEGMEXEC
93887+ if (vma_m)
93888+ BUG_ON(pax_mirror_vma(vma_m, vma));
93889+#endif
93890+
93891 return 0;
93892 }
93893
93894@@ -2787,6 +3291,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
93895 struct rb_node **rb_link, *rb_parent;
93896 bool faulted_in_anon_vma = true;
93897
93898+ BUG_ON(vma->vm_mirror);
93899+
93900 /*
93901 * If anonymous vma has not yet been faulted, update new pgoff
93902 * to match new location, to increase its chance of merging.
93903@@ -2851,6 +3357,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
93904 return NULL;
93905 }
93906
93907+#ifdef CONFIG_PAX_SEGMEXEC
93908+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
93909+{
93910+ struct vm_area_struct *prev_m;
93911+ struct rb_node **rb_link_m, *rb_parent_m;
93912+ struct mempolicy *pol_m;
93913+
93914+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
93915+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
93916+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
93917+ *vma_m = *vma;
93918+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
93919+ if (anon_vma_clone(vma_m, vma))
93920+ return -ENOMEM;
93921+ pol_m = vma_policy(vma_m);
93922+ mpol_get(pol_m);
93923+ set_vma_policy(vma_m, pol_m);
93924+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
93925+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
93926+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
93927+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
93928+ if (vma_m->vm_file)
93929+ get_file(vma_m->vm_file);
93930+ if (vma_m->vm_ops && vma_m->vm_ops->open)
93931+ vma_m->vm_ops->open(vma_m);
93932+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
93933+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
93934+ vma_m->vm_mirror = vma;
93935+ vma->vm_mirror = vma_m;
93936+ return 0;
93937+}
93938+#endif
93939+
93940 /*
93941 * Return true if the calling process may expand its vm space by the passed
93942 * number of pages
93943@@ -2862,6 +3401,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
93944
93945 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
93946
93947+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
93948 if (cur + npages > lim)
93949 return 0;
93950 return 1;
93951@@ -2932,6 +3472,22 @@ int install_special_mapping(struct mm_struct *mm,
93952 vma->vm_start = addr;
93953 vma->vm_end = addr + len;
93954
93955+#ifdef CONFIG_PAX_MPROTECT
93956+ if (mm->pax_flags & MF_PAX_MPROTECT) {
93957+#ifndef CONFIG_PAX_MPROTECT_COMPAT
93958+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
93959+ return -EPERM;
93960+ if (!(vm_flags & VM_EXEC))
93961+ vm_flags &= ~VM_MAYEXEC;
93962+#else
93963+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
93964+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
93965+#endif
93966+ else
93967+ vm_flags &= ~VM_MAYWRITE;
93968+ }
93969+#endif
93970+
93971 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
93972 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
93973
93974diff --git a/mm/mprotect.c b/mm/mprotect.c
93975index bb53a65..249c052 100644
93976--- a/mm/mprotect.c
93977+++ b/mm/mprotect.c
93978@@ -23,10 +23,18 @@
93979 #include <linux/mmu_notifier.h>
93980 #include <linux/migrate.h>
93981 #include <linux/perf_event.h>
93982+#include <linux/sched/sysctl.h>
93983+
93984+#ifdef CONFIG_PAX_MPROTECT
93985+#include <linux/elf.h>
93986+#include <linux/binfmts.h>
93987+#endif
93988+
93989 #include <asm/uaccess.h>
93990 #include <asm/pgtable.h>
93991 #include <asm/cacheflush.h>
93992 #include <asm/tlbflush.h>
93993+#include <asm/mmu_context.h>
93994
93995 #ifndef pgprot_modify
93996 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
93997@@ -222,6 +230,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
93998 return pages;
93999 }
94000
94001+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
94002+/* called while holding the mmap semaphor for writing except stack expansion */
94003+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
94004+{
94005+ unsigned long oldlimit, newlimit = 0UL;
94006+
94007+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
94008+ return;
94009+
94010+ spin_lock(&mm->page_table_lock);
94011+ oldlimit = mm->context.user_cs_limit;
94012+ if ((prot & VM_EXEC) && oldlimit < end)
94013+ /* USER_CS limit moved up */
94014+ newlimit = end;
94015+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
94016+ /* USER_CS limit moved down */
94017+ newlimit = start;
94018+
94019+ if (newlimit) {
94020+ mm->context.user_cs_limit = newlimit;
94021+
94022+#ifdef CONFIG_SMP
94023+ wmb();
94024+ cpus_clear(mm->context.cpu_user_cs_mask);
94025+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
94026+#endif
94027+
94028+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
94029+ }
94030+ spin_unlock(&mm->page_table_lock);
94031+ if (newlimit == end) {
94032+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
94033+
94034+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
94035+ if (is_vm_hugetlb_page(vma))
94036+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
94037+ else
94038+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
94039+ }
94040+}
94041+#endif
94042+
94043 int
94044 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94045 unsigned long start, unsigned long end, unsigned long newflags)
94046@@ -234,11 +284,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94047 int error;
94048 int dirty_accountable = 0;
94049
94050+#ifdef CONFIG_PAX_SEGMEXEC
94051+ struct vm_area_struct *vma_m = NULL;
94052+ unsigned long start_m, end_m;
94053+
94054+ start_m = start + SEGMEXEC_TASK_SIZE;
94055+ end_m = end + SEGMEXEC_TASK_SIZE;
94056+#endif
94057+
94058 if (newflags == oldflags) {
94059 *pprev = vma;
94060 return 0;
94061 }
94062
94063+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
94064+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
94065+
94066+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
94067+ return -ENOMEM;
94068+
94069+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
94070+ return -ENOMEM;
94071+ }
94072+
94073 /*
94074 * If we make a private mapping writable we increase our commit;
94075 * but (without finer accounting) cannot reduce our commit if we
94076@@ -255,6 +323,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94077 }
94078 }
94079
94080+#ifdef CONFIG_PAX_SEGMEXEC
94081+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
94082+ if (start != vma->vm_start) {
94083+ error = split_vma(mm, vma, start, 1);
94084+ if (error)
94085+ goto fail;
94086+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
94087+ *pprev = (*pprev)->vm_next;
94088+ }
94089+
94090+ if (end != vma->vm_end) {
94091+ error = split_vma(mm, vma, end, 0);
94092+ if (error)
94093+ goto fail;
94094+ }
94095+
94096+ if (pax_find_mirror_vma(vma)) {
94097+ error = __do_munmap(mm, start_m, end_m - start_m);
94098+ if (error)
94099+ goto fail;
94100+ } else {
94101+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94102+ if (!vma_m) {
94103+ error = -ENOMEM;
94104+ goto fail;
94105+ }
94106+ vma->vm_flags = newflags;
94107+ error = pax_mirror_vma(vma_m, vma);
94108+ if (error) {
94109+ vma->vm_flags = oldflags;
94110+ goto fail;
94111+ }
94112+ }
94113+ }
94114+#endif
94115+
94116 /*
94117 * First try to merge with previous and/or next vma.
94118 */
94119@@ -285,9 +389,21 @@ success:
94120 * vm_flags and vm_page_prot are protected by the mmap_sem
94121 * held in write mode.
94122 */
94123+
94124+#ifdef CONFIG_PAX_SEGMEXEC
94125+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
94126+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
94127+#endif
94128+
94129 vma->vm_flags = newflags;
94130+
94131+#ifdef CONFIG_PAX_MPROTECT
94132+ if (mm->binfmt && mm->binfmt->handle_mprotect)
94133+ mm->binfmt->handle_mprotect(vma, newflags);
94134+#endif
94135+
94136 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
94137- vm_get_page_prot(newflags));
94138+ vm_get_page_prot(vma->vm_flags));
94139
94140 if (vma_wants_writenotify(vma)) {
94141 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
94142@@ -326,6 +442,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94143 end = start + len;
94144 if (end <= start)
94145 return -ENOMEM;
94146+
94147+#ifdef CONFIG_PAX_SEGMEXEC
94148+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
94149+ if (end > SEGMEXEC_TASK_SIZE)
94150+ return -EINVAL;
94151+ } else
94152+#endif
94153+
94154+ if (end > TASK_SIZE)
94155+ return -EINVAL;
94156+
94157 if (!arch_validate_prot(prot))
94158 return -EINVAL;
94159
94160@@ -333,7 +460,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94161 /*
94162 * Does the application expect PROT_READ to imply PROT_EXEC:
94163 */
94164- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
94165+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
94166 prot |= PROT_EXEC;
94167
94168 vm_flags = calc_vm_prot_bits(prot);
94169@@ -365,6 +492,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94170 if (start > vma->vm_start)
94171 prev = vma;
94172
94173+#ifdef CONFIG_PAX_MPROTECT
94174+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
94175+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
94176+#endif
94177+
94178 for (nstart = start ; ; ) {
94179 unsigned long newflags;
94180
94181@@ -375,6 +507,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94182
94183 /* newflags >> 4 shift VM_MAY% in place of VM_% */
94184 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
94185+ if (prot & (PROT_WRITE | PROT_EXEC))
94186+ gr_log_rwxmprotect(vma);
94187+
94188+ error = -EACCES;
94189+ goto out;
94190+ }
94191+
94192+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
94193 error = -EACCES;
94194 goto out;
94195 }
94196@@ -389,6 +529,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94197 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
94198 if (error)
94199 goto out;
94200+
94201+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
94202+
94203 nstart = tmp;
94204
94205 if (nstart < prev->vm_end)
94206diff --git a/mm/mremap.c b/mm/mremap.c
94207index 0843feb..4f5b2e6 100644
94208--- a/mm/mremap.c
94209+++ b/mm/mremap.c
94210@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
94211 continue;
94212 pte = ptep_get_and_clear(mm, old_addr, old_pte);
94213 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
94214+
94215+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
94216+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
94217+ pte = pte_exprotect(pte);
94218+#endif
94219+
94220 pte = move_soft_dirty_pte(pte);
94221 set_pte_at(mm, new_addr, new_pte, pte);
94222 }
94223@@ -337,6 +343,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
94224 if (is_vm_hugetlb_page(vma))
94225 goto Einval;
94226
94227+#ifdef CONFIG_PAX_SEGMEXEC
94228+ if (pax_find_mirror_vma(vma))
94229+ goto Einval;
94230+#endif
94231+
94232 /* We can't remap across vm area boundaries */
94233 if (old_len > vma->vm_end - addr)
94234 goto Efault;
94235@@ -392,20 +403,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
94236 unsigned long ret = -EINVAL;
94237 unsigned long charged = 0;
94238 unsigned long map_flags;
94239+ unsigned long pax_task_size = TASK_SIZE;
94240
94241 if (new_addr & ~PAGE_MASK)
94242 goto out;
94243
94244- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
94245+#ifdef CONFIG_PAX_SEGMEXEC
94246+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
94247+ pax_task_size = SEGMEXEC_TASK_SIZE;
94248+#endif
94249+
94250+ pax_task_size -= PAGE_SIZE;
94251+
94252+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
94253 goto out;
94254
94255 /* Check if the location we're moving into overlaps the
94256 * old location at all, and fail if it does.
94257 */
94258- if ((new_addr <= addr) && (new_addr+new_len) > addr)
94259- goto out;
94260-
94261- if ((addr <= new_addr) && (addr+old_len) > new_addr)
94262+ if (addr + old_len > new_addr && new_addr + new_len > addr)
94263 goto out;
94264
94265 ret = do_munmap(mm, new_addr, new_len);
94266@@ -474,6 +490,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94267 unsigned long ret = -EINVAL;
94268 unsigned long charged = 0;
94269 bool locked = false;
94270+ unsigned long pax_task_size = TASK_SIZE;
94271
94272 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
94273 return ret;
94274@@ -495,6 +512,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94275 if (!new_len)
94276 return ret;
94277
94278+#ifdef CONFIG_PAX_SEGMEXEC
94279+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
94280+ pax_task_size = SEGMEXEC_TASK_SIZE;
94281+#endif
94282+
94283+ pax_task_size -= PAGE_SIZE;
94284+
94285+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
94286+ old_len > pax_task_size || addr > pax_task_size-old_len)
94287+ return ret;
94288+
94289 down_write(&current->mm->mmap_sem);
94290
94291 if (flags & MREMAP_FIXED) {
94292@@ -545,6 +573,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94293 new_addr = addr;
94294 }
94295 ret = addr;
94296+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
94297 goto out;
94298 }
94299 }
94300@@ -568,7 +597,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94301 goto out;
94302 }
94303
94304+ map_flags = vma->vm_flags;
94305 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
94306+ if (!(ret & ~PAGE_MASK)) {
94307+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
94308+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
94309+ }
94310 }
94311 out:
94312 if (ret & ~PAGE_MASK)
94313diff --git a/mm/nommu.c b/mm/nommu.c
94314index fec093a..8162f74 100644
94315--- a/mm/nommu.c
94316+++ b/mm/nommu.c
94317@@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
94318 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
94319 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
94320 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
94321-int heap_stack_gap = 0;
94322
94323 atomic_long_t mmap_pages_allocated;
94324
94325@@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
94326 EXPORT_SYMBOL(find_vma);
94327
94328 /*
94329- * find a VMA
94330- * - we don't extend stack VMAs under NOMMU conditions
94331- */
94332-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
94333-{
94334- return find_vma(mm, addr);
94335-}
94336-
94337-/*
94338 * expand a stack to a given address
94339 * - not supported under NOMMU conditions
94340 */
94341@@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94342
94343 /* most fields are the same, copy all, and then fixup */
94344 *new = *vma;
94345+ INIT_LIST_HEAD(&new->anon_vma_chain);
94346 *region = *vma->vm_region;
94347 new->vm_region = region;
94348
94349@@ -1992,8 +1983,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
94350 }
94351 EXPORT_SYMBOL(generic_file_remap_pages);
94352
94353-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94354- unsigned long addr, void *buf, int len, int write)
94355+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94356+ unsigned long addr, void *buf, size_t len, int write)
94357 {
94358 struct vm_area_struct *vma;
94359
94360@@ -2034,8 +2025,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94361 *
94362 * The caller must hold a reference on @mm.
94363 */
94364-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94365- void *buf, int len, int write)
94366+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
94367+ void *buf, size_t len, int write)
94368 {
94369 return __access_remote_vm(NULL, mm, addr, buf, len, write);
94370 }
94371@@ -2044,7 +2035,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94372 * Access another process' address space.
94373 * - source/target buffer must be kernel space
94374 */
94375-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
94376+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
94377 {
94378 struct mm_struct *mm;
94379
94380diff --git a/mm/page-writeback.c b/mm/page-writeback.c
94381index 7106cb1..0805f48 100644
94382--- a/mm/page-writeback.c
94383+++ b/mm/page-writeback.c
94384@@ -685,7 +685,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
94385 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
94386 * - the bdi dirty thresh drops quickly due to change of JBOD workload
94387 */
94388-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
94389+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
94390 unsigned long thresh,
94391 unsigned long bg_thresh,
94392 unsigned long dirty,
94393diff --git a/mm/page_alloc.c b/mm/page_alloc.c
94394index 589521d..314053a 100644
94395--- a/mm/page_alloc.c
94396+++ b/mm/page_alloc.c
94397@@ -61,6 +61,7 @@
94398 #include <linux/page-debug-flags.h>
94399 #include <linux/hugetlb.h>
94400 #include <linux/sched/rt.h>
94401+#include <linux/random.h>
94402
94403 #include <asm/sections.h>
94404 #include <asm/tlbflush.h>
94405@@ -354,7 +355,7 @@ out:
94406 * This usage means that zero-order pages may not be compound.
94407 */
94408
94409-static void free_compound_page(struct page *page)
94410+void free_compound_page(struct page *page)
94411 {
94412 __free_pages_ok(page, compound_order(page));
94413 }
94414@@ -714,6 +715,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
94415 int i;
94416 int bad = 0;
94417
94418+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94419+ unsigned long index = 1UL << order;
94420+#endif
94421+
94422 trace_mm_page_free(page, order);
94423 kmemcheck_free_shadow(page, order);
94424
94425@@ -730,6 +735,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
94426 debug_check_no_obj_freed(page_address(page),
94427 PAGE_SIZE << order);
94428 }
94429+
94430+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94431+ for (; index; --index)
94432+ sanitize_highpage(page + index - 1);
94433+#endif
94434+
94435 arch_free_page(page, order);
94436 kernel_map_pages(page, 1 << order, 0);
94437
94438@@ -752,6 +763,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
94439 local_irq_restore(flags);
94440 }
94441
94442+#ifdef CONFIG_PAX_LATENT_ENTROPY
94443+bool __meminitdata extra_latent_entropy;
94444+
94445+static int __init setup_pax_extra_latent_entropy(char *str)
94446+{
94447+ extra_latent_entropy = true;
94448+ return 0;
94449+}
94450+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
94451+
94452+volatile u64 latent_entropy __latent_entropy;
94453+EXPORT_SYMBOL(latent_entropy);
94454+#endif
94455+
94456 void __init __free_pages_bootmem(struct page *page, unsigned int order)
94457 {
94458 unsigned int nr_pages = 1 << order;
94459@@ -767,6 +792,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
94460 __ClearPageReserved(p);
94461 set_page_count(p, 0);
94462
94463+#ifdef CONFIG_PAX_LATENT_ENTROPY
94464+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
94465+ u64 hash = 0;
94466+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
94467+ const u64 *data = lowmem_page_address(page);
94468+
94469+ for (index = 0; index < end; index++)
94470+ hash ^= hash + data[index];
94471+ latent_entropy ^= hash;
94472+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
94473+ }
94474+#endif
94475+
94476 page_zone(page)->managed_pages += nr_pages;
94477 set_page_refcounted(page);
94478 __free_pages(page, order);
94479@@ -872,8 +910,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
94480 arch_alloc_page(page, order);
94481 kernel_map_pages(page, 1 << order, 1);
94482
94483+#ifndef CONFIG_PAX_MEMORY_SANITIZE
94484 if (gfp_flags & __GFP_ZERO)
94485 prep_zero_page(page, order, gfp_flags);
94486+#endif
94487
94488 if (order && (gfp_flags & __GFP_COMP))
94489 prep_compound_page(page, order);
94490diff --git a/mm/page_io.c b/mm/page_io.c
94491index 8c79a47..a689e0d 100644
94492--- a/mm/page_io.c
94493+++ b/mm/page_io.c
94494@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
94495 struct file *swap_file = sis->swap_file;
94496 struct address_space *mapping = swap_file->f_mapping;
94497 struct iovec iov = {
94498- .iov_base = kmap(page),
94499+ .iov_base = (void __force_user *)kmap(page),
94500 .iov_len = PAGE_SIZE,
94501 };
94502
94503diff --git a/mm/percpu.c b/mm/percpu.c
94504index 0d10def..6dc822d 100644
94505--- a/mm/percpu.c
94506+++ b/mm/percpu.c
94507@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
94508 static unsigned int pcpu_high_unit_cpu __read_mostly;
94509
94510 /* the address of the first chunk which starts with the kernel static area */
94511-void *pcpu_base_addr __read_mostly;
94512+void *pcpu_base_addr __read_only;
94513 EXPORT_SYMBOL_GPL(pcpu_base_addr);
94514
94515 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
94516diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
94517index fd26d04..0cea1b0 100644
94518--- a/mm/process_vm_access.c
94519+++ b/mm/process_vm_access.c
94520@@ -13,6 +13,7 @@
94521 #include <linux/uio.h>
94522 #include <linux/sched.h>
94523 #include <linux/highmem.h>
94524+#include <linux/security.h>
94525 #include <linux/ptrace.h>
94526 #include <linux/slab.h>
94527 #include <linux/syscalls.h>
94528@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
94529 size_t iov_l_curr_offset = 0;
94530 ssize_t iov_len;
94531
94532+ return -ENOSYS; // PaX: until properly audited
94533+
94534 /*
94535 * Work out how many pages of struct pages we're going to need
94536 * when eventually calling get_user_pages
94537 */
94538 for (i = 0; i < riovcnt; i++) {
94539 iov_len = rvec[i].iov_len;
94540- if (iov_len > 0) {
94541- nr_pages_iov = ((unsigned long)rvec[i].iov_base
94542- + iov_len)
94543- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
94544- / PAGE_SIZE + 1;
94545- nr_pages = max(nr_pages, nr_pages_iov);
94546- }
94547+ if (iov_len <= 0)
94548+ continue;
94549+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
94550+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
94551+ nr_pages = max(nr_pages, nr_pages_iov);
94552 }
94553
94554 if (nr_pages == 0)
94555@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
94556 goto free_proc_pages;
94557 }
94558
94559+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
94560+ rc = -EPERM;
94561+ goto put_task_struct;
94562+ }
94563+
94564 mm = mm_access(task, PTRACE_MODE_ATTACH);
94565 if (!mm || IS_ERR(mm)) {
94566 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
94567diff --git a/mm/rmap.c b/mm/rmap.c
94568index 068522d..f539f21 100644
94569--- a/mm/rmap.c
94570+++ b/mm/rmap.c
94571@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94572 struct anon_vma *anon_vma = vma->anon_vma;
94573 struct anon_vma_chain *avc;
94574
94575+#ifdef CONFIG_PAX_SEGMEXEC
94576+ struct anon_vma_chain *avc_m = NULL;
94577+#endif
94578+
94579 might_sleep();
94580 if (unlikely(!anon_vma)) {
94581 struct mm_struct *mm = vma->vm_mm;
94582@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94583 if (!avc)
94584 goto out_enomem;
94585
94586+#ifdef CONFIG_PAX_SEGMEXEC
94587+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
94588+ if (!avc_m)
94589+ goto out_enomem_free_avc;
94590+#endif
94591+
94592 anon_vma = find_mergeable_anon_vma(vma);
94593 allocated = NULL;
94594 if (!anon_vma) {
94595@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94596 /* page_table_lock to protect against threads */
94597 spin_lock(&mm->page_table_lock);
94598 if (likely(!vma->anon_vma)) {
94599+
94600+#ifdef CONFIG_PAX_SEGMEXEC
94601+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
94602+
94603+ if (vma_m) {
94604+ BUG_ON(vma_m->anon_vma);
94605+ vma_m->anon_vma = anon_vma;
94606+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
94607+ avc_m = NULL;
94608+ }
94609+#endif
94610+
94611 vma->anon_vma = anon_vma;
94612 anon_vma_chain_link(vma, avc, anon_vma);
94613 allocated = NULL;
94614@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94615
94616 if (unlikely(allocated))
94617 put_anon_vma(allocated);
94618+
94619+#ifdef CONFIG_PAX_SEGMEXEC
94620+ if (unlikely(avc_m))
94621+ anon_vma_chain_free(avc_m);
94622+#endif
94623+
94624 if (unlikely(avc))
94625 anon_vma_chain_free(avc);
94626 }
94627 return 0;
94628
94629 out_enomem_free_avc:
94630+
94631+#ifdef CONFIG_PAX_SEGMEXEC
94632+ if (avc_m)
94633+ anon_vma_chain_free(avc_m);
94634+#endif
94635+
94636 anon_vma_chain_free(avc);
94637 out_enomem:
94638 return -ENOMEM;
94639@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
94640 * Attach the anon_vmas from src to dst.
94641 * Returns 0 on success, -ENOMEM on failure.
94642 */
94643-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
94644+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
94645 {
94646 struct anon_vma_chain *avc, *pavc;
94647 struct anon_vma *root = NULL;
94648@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
94649 * the corresponding VMA in the parent process is attached to.
94650 * Returns 0 on success, non-zero on failure.
94651 */
94652-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
94653+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
94654 {
94655 struct anon_vma_chain *avc;
94656 struct anon_vma *anon_vma;
94657@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
94658 void __init anon_vma_init(void)
94659 {
94660 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
94661- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
94662- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
94663+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
94664+ anon_vma_ctor);
94665+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
94666+ SLAB_PANIC|SLAB_NO_SANITIZE);
94667 }
94668
94669 /*
94670diff --git a/mm/shmem.c b/mm/shmem.c
94671index 902a148..58f9d59 100644
94672--- a/mm/shmem.c
94673+++ b/mm/shmem.c
94674@@ -33,7 +33,7 @@
94675 #include <linux/swap.h>
94676 #include <linux/aio.h>
94677
94678-static struct vfsmount *shm_mnt;
94679+struct vfsmount *shm_mnt;
94680
94681 #ifdef CONFIG_SHMEM
94682 /*
94683@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
94684 #define BOGO_DIRENT_SIZE 20
94685
94686 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
94687-#define SHORT_SYMLINK_LEN 128
94688+#define SHORT_SYMLINK_LEN 64
94689
94690 /*
94691 * shmem_fallocate and shmem_writepage communicate via inode->i_private
94692@@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
94693 static int shmem_xattr_validate(const char *name)
94694 {
94695 struct { const char *prefix; size_t len; } arr[] = {
94696+
94697+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
94698+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
94699+#endif
94700+
94701 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
94702 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
94703 };
94704@@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
94705 if (err)
94706 return err;
94707
94708+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
94709+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
94710+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
94711+ return -EOPNOTSUPP;
94712+ if (size > 8)
94713+ return -EINVAL;
94714+ }
94715+#endif
94716+
94717 return simple_xattr_set(&info->xattrs, name, value, size, flags);
94718 }
94719
94720@@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
94721 int err = -ENOMEM;
94722
94723 /* Round up to L1_CACHE_BYTES to resist false sharing */
94724- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
94725- L1_CACHE_BYTES), GFP_KERNEL);
94726+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
94727 if (!sbinfo)
94728 return -ENOMEM;
94729
94730diff --git a/mm/slab.c b/mm/slab.c
94731index eb043bf..d82f5a8 100644
94732--- a/mm/slab.c
94733+++ b/mm/slab.c
94734@@ -300,10 +300,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
94735 if ((x)->max_freeable < i) \
94736 (x)->max_freeable = i; \
94737 } while (0)
94738-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
94739-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
94740-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
94741-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
94742+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
94743+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
94744+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
94745+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
94746+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
94747+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
94748 #else
94749 #define STATS_INC_ACTIVE(x) do { } while (0)
94750 #define STATS_DEC_ACTIVE(x) do { } while (0)
94751@@ -320,6 +322,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
94752 #define STATS_INC_ALLOCMISS(x) do { } while (0)
94753 #define STATS_INC_FREEHIT(x) do { } while (0)
94754 #define STATS_INC_FREEMISS(x) do { } while (0)
94755+#define STATS_INC_SANITIZED(x) do { } while (0)
94756+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
94757 #endif
94758
94759 #if DEBUG
94760@@ -403,7 +407,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
94761 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
94762 */
94763 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
94764- const struct page *page, void *obj)
94765+ const struct page *page, const void *obj)
94766 {
94767 u32 offset = (obj - page->s_mem);
94768 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
94769@@ -1489,12 +1493,12 @@ void __init kmem_cache_init(void)
94770 */
94771
94772 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
94773- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
94774+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
94775
94776 if (INDEX_AC != INDEX_NODE)
94777 kmalloc_caches[INDEX_NODE] =
94778 create_kmalloc_cache("kmalloc-node",
94779- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
94780+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
94781
94782 slab_early_init = 0;
94783
94784@@ -3428,6 +3432,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
94785 struct array_cache *ac = cpu_cache_get(cachep);
94786
94787 check_irq_off();
94788+
94789+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94790+ if (pax_sanitize_slab) {
94791+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
94792+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
94793+
94794+ if (cachep->ctor)
94795+ cachep->ctor(objp);
94796+
94797+ STATS_INC_SANITIZED(cachep);
94798+ } else
94799+ STATS_INC_NOT_SANITIZED(cachep);
94800+ }
94801+#endif
94802+
94803 kmemleak_free_recursive(objp, cachep->flags);
94804 objp = cache_free_debugcheck(cachep, objp, caller);
94805
94806@@ -3656,6 +3675,7 @@ void kfree(const void *objp)
94807
94808 if (unlikely(ZERO_OR_NULL_PTR(objp)))
94809 return;
94810+ VM_BUG_ON(!virt_addr_valid(objp));
94811 local_irq_save(flags);
94812 kfree_debugcheck(objp);
94813 c = virt_to_cache(objp);
94814@@ -4097,14 +4117,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
94815 }
94816 /* cpu stats */
94817 {
94818- unsigned long allochit = atomic_read(&cachep->allochit);
94819- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
94820- unsigned long freehit = atomic_read(&cachep->freehit);
94821- unsigned long freemiss = atomic_read(&cachep->freemiss);
94822+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
94823+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
94824+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
94825+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
94826
94827 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
94828 allochit, allocmiss, freehit, freemiss);
94829 }
94830+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94831+ {
94832+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
94833+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
94834+
94835+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
94836+ }
94837+#endif
94838 #endif
94839 }
94840
94841@@ -4334,13 +4362,69 @@ static const struct file_operations proc_slabstats_operations = {
94842 static int __init slab_proc_init(void)
94843 {
94844 #ifdef CONFIG_DEBUG_SLAB_LEAK
94845- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
94846+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
94847 #endif
94848 return 0;
94849 }
94850 module_init(slab_proc_init);
94851 #endif
94852
94853+bool is_usercopy_object(const void *ptr)
94854+{
94855+ struct page *page;
94856+ struct kmem_cache *cachep;
94857+
94858+ if (ZERO_OR_NULL_PTR(ptr))
94859+ return false;
94860+
94861+ if (!slab_is_available())
94862+ return false;
94863+
94864+ if (!virt_addr_valid(ptr))
94865+ return false;
94866+
94867+ page = virt_to_head_page(ptr);
94868+
94869+ if (!PageSlab(page))
94870+ return false;
94871+
94872+ cachep = page->slab_cache;
94873+ return cachep->flags & SLAB_USERCOPY;
94874+}
94875+
94876+#ifdef CONFIG_PAX_USERCOPY
94877+const char *check_heap_object(const void *ptr, unsigned long n)
94878+{
94879+ struct page *page;
94880+ struct kmem_cache *cachep;
94881+ unsigned int objnr;
94882+ unsigned long offset;
94883+
94884+ if (ZERO_OR_NULL_PTR(ptr))
94885+ return "<null>";
94886+
94887+ if (!virt_addr_valid(ptr))
94888+ return NULL;
94889+
94890+ page = virt_to_head_page(ptr);
94891+
94892+ if (!PageSlab(page))
94893+ return NULL;
94894+
94895+ cachep = page->slab_cache;
94896+ if (!(cachep->flags & SLAB_USERCOPY))
94897+ return cachep->name;
94898+
94899+ objnr = obj_to_index(cachep, page, ptr);
94900+ BUG_ON(objnr >= cachep->num);
94901+ offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
94902+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
94903+ return NULL;
94904+
94905+ return cachep->name;
94906+}
94907+#endif
94908+
94909 /**
94910 * ksize - get the actual amount of memory allocated for a given object
94911 * @objp: Pointer to the object
94912diff --git a/mm/slab.h b/mm/slab.h
94913index 0859c42..2f7b737 100644
94914--- a/mm/slab.h
94915+++ b/mm/slab.h
94916@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
94917 /* The slab cache that manages slab cache information */
94918 extern struct kmem_cache *kmem_cache;
94919
94920+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94921+#ifdef CONFIG_X86_64
94922+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
94923+#else
94924+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
94925+#endif
94926+extern bool pax_sanitize_slab;
94927+#endif
94928+
94929 unsigned long calculate_alignment(unsigned long flags,
94930 unsigned long align, unsigned long size);
94931
94932@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
94933
94934 /* Legal flag mask for kmem_cache_create(), for various configurations */
94935 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
94936- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
94937+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
94938+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
94939
94940 #if defined(CONFIG_DEBUG_SLAB)
94941 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
94942@@ -233,6 +243,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
94943 return s;
94944
94945 page = virt_to_head_page(x);
94946+
94947+ BUG_ON(!PageSlab(page));
94948+
94949 cachep = page->slab_cache;
94950 if (slab_equal_or_root(cachep, s))
94951 return cachep;
94952diff --git a/mm/slab_common.c b/mm/slab_common.c
94953index 0b7bb39..334c328 100644
94954--- a/mm/slab_common.c
94955+++ b/mm/slab_common.c
94956@@ -23,11 +23,22 @@
94957
94958 #include "slab.h"
94959
94960-enum slab_state slab_state;
94961+enum slab_state slab_state __read_only;
94962 LIST_HEAD(slab_caches);
94963 DEFINE_MUTEX(slab_mutex);
94964 struct kmem_cache *kmem_cache;
94965
94966+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94967+bool pax_sanitize_slab __read_only = true;
94968+static int __init pax_sanitize_slab_setup(char *str)
94969+{
94970+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
94971+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
94972+ return 1;
94973+}
94974+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
94975+#endif
94976+
94977 #ifdef CONFIG_DEBUG_VM
94978 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
94979 size_t size)
94980@@ -212,7 +223,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
94981
94982 err = __kmem_cache_create(s, flags);
94983 if (!err) {
94984- s->refcount = 1;
94985+ atomic_set(&s->refcount, 1);
94986 list_add(&s->list, &slab_caches);
94987 memcg_cache_list_add(memcg, s);
94988 } else {
94989@@ -258,8 +269,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
94990
94991 get_online_cpus();
94992 mutex_lock(&slab_mutex);
94993- s->refcount--;
94994- if (!s->refcount) {
94995+ if (atomic_dec_and_test(&s->refcount)) {
94996 list_del(&s->list);
94997
94998 if (!__kmem_cache_shutdown(s)) {
94999@@ -305,7 +315,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
95000 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
95001 name, size, err);
95002
95003- s->refcount = -1; /* Exempt from merging for now */
95004+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
95005 }
95006
95007 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
95008@@ -318,7 +328,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
95009
95010 create_boot_cache(s, name, size, flags);
95011 list_add(&s->list, &slab_caches);
95012- s->refcount = 1;
95013+ atomic_set(&s->refcount, 1);
95014 return s;
95015 }
95016
95017@@ -330,6 +340,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
95018 EXPORT_SYMBOL(kmalloc_dma_caches);
95019 #endif
95020
95021+#ifdef CONFIG_PAX_USERCOPY_SLABS
95022+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
95023+EXPORT_SYMBOL(kmalloc_usercopy_caches);
95024+#endif
95025+
95026 /*
95027 * Conversion table for small slabs sizes / 8 to the index in the
95028 * kmalloc array. This is necessary for slabs < 192 since we have non power
95029@@ -394,6 +409,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
95030 return kmalloc_dma_caches[index];
95031
95032 #endif
95033+
95034+#ifdef CONFIG_PAX_USERCOPY_SLABS
95035+ if (unlikely((flags & GFP_USERCOPY)))
95036+ return kmalloc_usercopy_caches[index];
95037+
95038+#endif
95039+
95040 return kmalloc_caches[index];
95041 }
95042
95043@@ -450,7 +472,7 @@ void __init create_kmalloc_caches(unsigned long flags)
95044 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
95045 if (!kmalloc_caches[i]) {
95046 kmalloc_caches[i] = create_kmalloc_cache(NULL,
95047- 1 << i, flags);
95048+ 1 << i, SLAB_USERCOPY | flags);
95049 }
95050
95051 /*
95052@@ -459,10 +481,10 @@ void __init create_kmalloc_caches(unsigned long flags)
95053 * earlier power of two caches
95054 */
95055 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
95056- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
95057+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
95058
95059 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
95060- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
95061+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
95062 }
95063
95064 /* Kmalloc array is now usable */
95065@@ -495,6 +517,23 @@ void __init create_kmalloc_caches(unsigned long flags)
95066 }
95067 }
95068 #endif
95069+
95070+#ifdef CONFIG_PAX_USERCOPY_SLABS
95071+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
95072+ struct kmem_cache *s = kmalloc_caches[i];
95073+
95074+ if (s) {
95075+ int size = kmalloc_size(i);
95076+ char *n = kasprintf(GFP_NOWAIT,
95077+ "usercopy-kmalloc-%d", size);
95078+
95079+ BUG_ON(!n);
95080+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
95081+ size, SLAB_USERCOPY | flags);
95082+ }
95083+ }
95084+#endif
95085+
95086 }
95087 #endif /* !CONFIG_SLOB */
95088
95089@@ -535,6 +574,9 @@ void print_slabinfo_header(struct seq_file *m)
95090 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
95091 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
95092 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
95093+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95094+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
95095+#endif
95096 #endif
95097 seq_putc(m, '\n');
95098 }
95099diff --git a/mm/slob.c b/mm/slob.c
95100index 4bf8809..98a6914 100644
95101--- a/mm/slob.c
95102+++ b/mm/slob.c
95103@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
95104 /*
95105 * Return the size of a slob block.
95106 */
95107-static slobidx_t slob_units(slob_t *s)
95108+static slobidx_t slob_units(const slob_t *s)
95109 {
95110 if (s->units > 0)
95111 return s->units;
95112@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
95113 /*
95114 * Return the next free slob block pointer after this one.
95115 */
95116-static slob_t *slob_next(slob_t *s)
95117+static slob_t *slob_next(const slob_t *s)
95118 {
95119 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
95120 slobidx_t next;
95121@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
95122 /*
95123 * Returns true if s is the last free block in its page.
95124 */
95125-static int slob_last(slob_t *s)
95126+static int slob_last(const slob_t *s)
95127 {
95128 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
95129 }
95130
95131-static void *slob_new_pages(gfp_t gfp, int order, int node)
95132+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
95133 {
95134- void *page;
95135+ struct page *page;
95136
95137 #ifdef CONFIG_NUMA
95138 if (node != NUMA_NO_NODE)
95139@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
95140 if (!page)
95141 return NULL;
95142
95143- return page_address(page);
95144+ __SetPageSlab(page);
95145+ return page;
95146 }
95147
95148-static void slob_free_pages(void *b, int order)
95149+static void slob_free_pages(struct page *sp, int order)
95150 {
95151 if (current->reclaim_state)
95152 current->reclaim_state->reclaimed_slab += 1 << order;
95153- free_pages((unsigned long)b, order);
95154+ __ClearPageSlab(sp);
95155+ page_mapcount_reset(sp);
95156+ sp->private = 0;
95157+ __free_pages(sp, order);
95158 }
95159
95160 /*
95161@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
95162
95163 /* Not enough space: must allocate a new page */
95164 if (!b) {
95165- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
95166- if (!b)
95167+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
95168+ if (!sp)
95169 return NULL;
95170- sp = virt_to_page(b);
95171- __SetPageSlab(sp);
95172+ b = page_address(sp);
95173
95174 spin_lock_irqsave(&slob_lock, flags);
95175 sp->units = SLOB_UNITS(PAGE_SIZE);
95176 sp->freelist = b;
95177+ sp->private = 0;
95178 INIT_LIST_HEAD(&sp->list);
95179 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
95180 set_slob_page_free(sp, slob_list);
95181@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
95182 if (slob_page_free(sp))
95183 clear_slob_page_free(sp);
95184 spin_unlock_irqrestore(&slob_lock, flags);
95185- __ClearPageSlab(sp);
95186- page_mapcount_reset(sp);
95187- slob_free_pages(b, 0);
95188+ slob_free_pages(sp, 0);
95189 return;
95190 }
95191
95192+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95193+ if (pax_sanitize_slab)
95194+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
95195+#endif
95196+
95197 if (!slob_page_free(sp)) {
95198 /* This slob page is about to become partially free. Easy! */
95199 sp->units = units;
95200@@ -424,11 +431,10 @@ out:
95201 */
95202
95203 static __always_inline void *
95204-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95205+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
95206 {
95207- unsigned int *m;
95208- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95209- void *ret;
95210+ slob_t *m;
95211+ void *ret = NULL;
95212
95213 gfp &= gfp_allowed_mask;
95214
95215@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95216
95217 if (!m)
95218 return NULL;
95219- *m = size;
95220+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
95221+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
95222+ m[0].units = size;
95223+ m[1].units = align;
95224 ret = (void *)m + align;
95225
95226 trace_kmalloc_node(caller, ret,
95227 size, size + align, gfp, node);
95228 } else {
95229 unsigned int order = get_order(size);
95230+ struct page *page;
95231
95232 if (likely(order))
95233 gfp |= __GFP_COMP;
95234- ret = slob_new_pages(gfp, order, node);
95235+ page = slob_new_pages(gfp, order, node);
95236+ if (page) {
95237+ ret = page_address(page);
95238+ page->private = size;
95239+ }
95240
95241 trace_kmalloc_node(caller, ret,
95242 size, PAGE_SIZE << order, gfp, node);
95243 }
95244
95245- kmemleak_alloc(ret, size, 1, gfp);
95246+ return ret;
95247+}
95248+
95249+static __always_inline void *
95250+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95251+{
95252+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95253+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
95254+
95255+ if (!ZERO_OR_NULL_PTR(ret))
95256+ kmemleak_alloc(ret, size, 1, gfp);
95257 return ret;
95258 }
95259
95260@@ -493,34 +517,112 @@ void kfree(const void *block)
95261 return;
95262 kmemleak_free(block);
95263
95264+ VM_BUG_ON(!virt_addr_valid(block));
95265 sp = virt_to_page(block);
95266- if (PageSlab(sp)) {
95267+ VM_BUG_ON(!PageSlab(sp));
95268+ if (!sp->private) {
95269 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95270- unsigned int *m = (unsigned int *)(block - align);
95271- slob_free(m, *m + align);
95272- } else
95273+ slob_t *m = (slob_t *)(block - align);
95274+ slob_free(m, m[0].units + align);
95275+ } else {
95276+ __ClearPageSlab(sp);
95277+ page_mapcount_reset(sp);
95278+ sp->private = 0;
95279 __free_pages(sp, compound_order(sp));
95280+ }
95281 }
95282 EXPORT_SYMBOL(kfree);
95283
95284+bool is_usercopy_object(const void *ptr)
95285+{
95286+ if (!slab_is_available())
95287+ return false;
95288+
95289+ // PAX: TODO
95290+
95291+ return false;
95292+}
95293+
95294+#ifdef CONFIG_PAX_USERCOPY
95295+const char *check_heap_object(const void *ptr, unsigned long n)
95296+{
95297+ struct page *page;
95298+ const slob_t *free;
95299+ const void *base;
95300+ unsigned long flags;
95301+
95302+ if (ZERO_OR_NULL_PTR(ptr))
95303+ return "<null>";
95304+
95305+ if (!virt_addr_valid(ptr))
95306+ return NULL;
95307+
95308+ page = virt_to_head_page(ptr);
95309+ if (!PageSlab(page))
95310+ return NULL;
95311+
95312+ if (page->private) {
95313+ base = page;
95314+ if (base <= ptr && n <= page->private - (ptr - base))
95315+ return NULL;
95316+ return "<slob>";
95317+ }
95318+
95319+ /* some tricky double walking to find the chunk */
95320+ spin_lock_irqsave(&slob_lock, flags);
95321+ base = (void *)((unsigned long)ptr & PAGE_MASK);
95322+ free = page->freelist;
95323+
95324+ while (!slob_last(free) && (void *)free <= ptr) {
95325+ base = free + slob_units(free);
95326+ free = slob_next(free);
95327+ }
95328+
95329+ while (base < (void *)free) {
95330+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
95331+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
95332+ int offset;
95333+
95334+ if (ptr < base + align)
95335+ break;
95336+
95337+ offset = ptr - base - align;
95338+ if (offset >= m) {
95339+ base += size;
95340+ continue;
95341+ }
95342+
95343+ if (n > m - offset)
95344+ break;
95345+
95346+ spin_unlock_irqrestore(&slob_lock, flags);
95347+ return NULL;
95348+ }
95349+
95350+ spin_unlock_irqrestore(&slob_lock, flags);
95351+ return "<slob>";
95352+}
95353+#endif
95354+
95355 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
95356 size_t ksize(const void *block)
95357 {
95358 struct page *sp;
95359 int align;
95360- unsigned int *m;
95361+ slob_t *m;
95362
95363 BUG_ON(!block);
95364 if (unlikely(block == ZERO_SIZE_PTR))
95365 return 0;
95366
95367 sp = virt_to_page(block);
95368- if (unlikely(!PageSlab(sp)))
95369- return PAGE_SIZE << compound_order(sp);
95370+ VM_BUG_ON(!PageSlab(sp));
95371+ if (sp->private)
95372+ return sp->private;
95373
95374 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95375- m = (unsigned int *)(block - align);
95376- return SLOB_UNITS(*m) * SLOB_UNIT;
95377+ m = (slob_t *)(block - align);
95378+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
95379 }
95380 EXPORT_SYMBOL(ksize);
95381
95382@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
95383
95384 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
95385 {
95386- void *b;
95387+ void *b = NULL;
95388
95389 flags &= gfp_allowed_mask;
95390
95391 lockdep_trace_alloc(flags);
95392
95393+#ifdef CONFIG_PAX_USERCOPY_SLABS
95394+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
95395+#else
95396 if (c->size < PAGE_SIZE) {
95397 b = slob_alloc(c->size, flags, c->align, node);
95398 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
95399 SLOB_UNITS(c->size) * SLOB_UNIT,
95400 flags, node);
95401 } else {
95402- b = slob_new_pages(flags, get_order(c->size), node);
95403+ struct page *sp;
95404+
95405+ sp = slob_new_pages(flags, get_order(c->size), node);
95406+ if (sp) {
95407+ b = page_address(sp);
95408+ sp->private = c->size;
95409+ }
95410 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
95411 PAGE_SIZE << get_order(c->size),
95412 flags, node);
95413 }
95414+#endif
95415
95416 if (b && c->ctor)
95417 c->ctor(b);
95418@@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
95419
95420 static void __kmem_cache_free(void *b, int size)
95421 {
95422- if (size < PAGE_SIZE)
95423+ struct page *sp;
95424+
95425+ sp = virt_to_page(b);
95426+ BUG_ON(!PageSlab(sp));
95427+ if (!sp->private)
95428 slob_free(b, size);
95429 else
95430- slob_free_pages(b, get_order(size));
95431+ slob_free_pages(sp, get_order(size));
95432 }
95433
95434 static void kmem_rcu_free(struct rcu_head *head)
95435@@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
95436
95437 void kmem_cache_free(struct kmem_cache *c, void *b)
95438 {
95439+ int size = c->size;
95440+
95441+#ifdef CONFIG_PAX_USERCOPY_SLABS
95442+ if (size + c->align < PAGE_SIZE) {
95443+ size += c->align;
95444+ b -= c->align;
95445+ }
95446+#endif
95447+
95448 kmemleak_free_recursive(b, c->flags);
95449 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
95450 struct slob_rcu *slob_rcu;
95451- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
95452- slob_rcu->size = c->size;
95453+ slob_rcu = b + (size - sizeof(struct slob_rcu));
95454+ slob_rcu->size = size;
95455 call_rcu(&slob_rcu->head, kmem_rcu_free);
95456 } else {
95457- __kmem_cache_free(b, c->size);
95458+ __kmem_cache_free(b, size);
95459 }
95460
95461+#ifdef CONFIG_PAX_USERCOPY_SLABS
95462+ trace_kfree(_RET_IP_, b);
95463+#else
95464 trace_kmem_cache_free(_RET_IP_, b);
95465+#endif
95466+
95467 }
95468 EXPORT_SYMBOL(kmem_cache_free);
95469
95470diff --git a/mm/slub.c b/mm/slub.c
95471index 89490d9..c7b226a 100644
95472--- a/mm/slub.c
95473+++ b/mm/slub.c
95474@@ -207,7 +207,7 @@ struct track {
95475
95476 enum track_item { TRACK_ALLOC, TRACK_FREE };
95477
95478-#ifdef CONFIG_SYSFS
95479+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95480 static int sysfs_slab_add(struct kmem_cache *);
95481 static int sysfs_slab_alias(struct kmem_cache *, const char *);
95482 static void sysfs_slab_remove(struct kmem_cache *);
95483@@ -530,7 +530,7 @@ static void print_track(const char *s, struct track *t)
95484 if (!t->addr)
95485 return;
95486
95487- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
95488+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
95489 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
95490 #ifdef CONFIG_STACKTRACE
95491 {
95492@@ -2643,6 +2643,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
95493
95494 slab_free_hook(s, x);
95495
95496+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95497+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
95498+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
95499+ if (s->ctor)
95500+ s->ctor(x);
95501+ }
95502+#endif
95503+
95504 redo:
95505 /*
95506 * Determine the currently cpus per cpu slab.
95507@@ -2710,7 +2718,7 @@ static int slub_min_objects;
95508 * Merge control. If this is set then no merging of slab caches will occur.
95509 * (Could be removed. This was introduced to pacify the merge skeptics.)
95510 */
95511-static int slub_nomerge;
95512+static int slub_nomerge = 1;
95513
95514 /*
95515 * Calculate the order of allocation given an slab object size.
95516@@ -2987,6 +2995,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
95517 s->inuse = size;
95518
95519 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
95520+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95521+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
95522+#endif
95523 s->ctor)) {
95524 /*
95525 * Relocate free pointer after the object if it is not
95526@@ -3332,6 +3343,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
95527 EXPORT_SYMBOL(__kmalloc_node);
95528 #endif
95529
95530+bool is_usercopy_object(const void *ptr)
95531+{
95532+ struct page *page;
95533+ struct kmem_cache *s;
95534+
95535+ if (ZERO_OR_NULL_PTR(ptr))
95536+ return false;
95537+
95538+ if (!slab_is_available())
95539+ return false;
95540+
95541+ if (!virt_addr_valid(ptr))
95542+ return false;
95543+
95544+ page = virt_to_head_page(ptr);
95545+
95546+ if (!PageSlab(page))
95547+ return false;
95548+
95549+ s = page->slab_cache;
95550+ return s->flags & SLAB_USERCOPY;
95551+}
95552+
95553+#ifdef CONFIG_PAX_USERCOPY
95554+const char *check_heap_object(const void *ptr, unsigned long n)
95555+{
95556+ struct page *page;
95557+ struct kmem_cache *s;
95558+ unsigned long offset;
95559+
95560+ if (ZERO_OR_NULL_PTR(ptr))
95561+ return "<null>";
95562+
95563+ if (!virt_addr_valid(ptr))
95564+ return NULL;
95565+
95566+ page = virt_to_head_page(ptr);
95567+
95568+ if (!PageSlab(page))
95569+ return NULL;
95570+
95571+ s = page->slab_cache;
95572+ if (!(s->flags & SLAB_USERCOPY))
95573+ return s->name;
95574+
95575+ offset = (ptr - page_address(page)) % s->size;
95576+ if (offset <= s->object_size && n <= s->object_size - offset)
95577+ return NULL;
95578+
95579+ return s->name;
95580+}
95581+#endif
95582+
95583 size_t ksize(const void *object)
95584 {
95585 struct page *page;
95586@@ -3360,6 +3424,7 @@ void kfree(const void *x)
95587 if (unlikely(ZERO_OR_NULL_PTR(x)))
95588 return;
95589
95590+ VM_BUG_ON(!virt_addr_valid(x));
95591 page = virt_to_head_page(x);
95592 if (unlikely(!PageSlab(page))) {
95593 BUG_ON(!PageCompound(page));
95594@@ -3665,7 +3730,7 @@ static int slab_unmergeable(struct kmem_cache *s)
95595 /*
95596 * We may have set a slab to be unmergeable during bootstrap.
95597 */
95598- if (s->refcount < 0)
95599+ if (atomic_read(&s->refcount) < 0)
95600 return 1;
95601
95602 return 0;
95603@@ -3723,7 +3788,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95604
95605 s = find_mergeable(memcg, size, align, flags, name, ctor);
95606 if (s) {
95607- s->refcount++;
95608+ atomic_inc(&s->refcount);
95609 /*
95610 * Adjust the object sizes so that we clear
95611 * the complete object on kzalloc.
95612@@ -3732,7 +3797,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95613 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
95614
95615 if (sysfs_slab_alias(s, name)) {
95616- s->refcount--;
95617+ atomic_dec(&s->refcount);
95618 s = NULL;
95619 }
95620 }
95621@@ -3852,7 +3917,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
95622 }
95623 #endif
95624
95625-#ifdef CONFIG_SYSFS
95626+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95627 static int count_inuse(struct page *page)
95628 {
95629 return page->inuse;
95630@@ -4241,12 +4306,12 @@ static void resiliency_test(void)
95631 validate_slab_cache(kmalloc_caches[9]);
95632 }
95633 #else
95634-#ifdef CONFIG_SYSFS
95635+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95636 static void resiliency_test(void) {};
95637 #endif
95638 #endif
95639
95640-#ifdef CONFIG_SYSFS
95641+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95642 enum slab_stat_type {
95643 SL_ALL, /* All slabs */
95644 SL_PARTIAL, /* Only partially allocated slabs */
95645@@ -4492,7 +4557,7 @@ SLAB_ATTR_RO(ctor);
95646
95647 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
95648 {
95649- return sprintf(buf, "%d\n", s->refcount - 1);
95650+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
95651 }
95652 SLAB_ATTR_RO(aliases);
95653
95654@@ -4580,6 +4645,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
95655 SLAB_ATTR_RO(cache_dma);
95656 #endif
95657
95658+#ifdef CONFIG_PAX_USERCOPY_SLABS
95659+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
95660+{
95661+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
95662+}
95663+SLAB_ATTR_RO(usercopy);
95664+#endif
95665+
95666 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
95667 {
95668 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
95669@@ -4914,6 +4987,9 @@ static struct attribute *slab_attrs[] = {
95670 #ifdef CONFIG_ZONE_DMA
95671 &cache_dma_attr.attr,
95672 #endif
95673+#ifdef CONFIG_PAX_USERCOPY_SLABS
95674+ &usercopy_attr.attr,
95675+#endif
95676 #ifdef CONFIG_NUMA
95677 &remote_node_defrag_ratio_attr.attr,
95678 #endif
95679@@ -5146,6 +5222,7 @@ static char *create_unique_id(struct kmem_cache *s)
95680 return name;
95681 }
95682
95683+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95684 static int sysfs_slab_add(struct kmem_cache *s)
95685 {
95686 int err;
95687@@ -5169,7 +5246,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
95688 }
95689
95690 s->kobj.kset = slab_kset;
95691- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
95692+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
95693 if (err) {
95694 kobject_put(&s->kobj);
95695 return err;
95696@@ -5203,6 +5280,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
95697 kobject_del(&s->kobj);
95698 kobject_put(&s->kobj);
95699 }
95700+#endif
95701
95702 /*
95703 * Need to buffer aliases during bootup until sysfs becomes
95704@@ -5216,6 +5294,7 @@ struct saved_alias {
95705
95706 static struct saved_alias *alias_list;
95707
95708+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95709 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
95710 {
95711 struct saved_alias *al;
95712@@ -5238,6 +5317,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
95713 alias_list = al;
95714 return 0;
95715 }
95716+#endif
95717
95718 static int __init slab_sysfs_init(void)
95719 {
95720diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
95721index 27eeab3..7c3f7f2 100644
95722--- a/mm/sparse-vmemmap.c
95723+++ b/mm/sparse-vmemmap.c
95724@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
95725 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
95726 if (!p)
95727 return NULL;
95728- pud_populate(&init_mm, pud, p);
95729+ pud_populate_kernel(&init_mm, pud, p);
95730 }
95731 return pud;
95732 }
95733@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
95734 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
95735 if (!p)
95736 return NULL;
95737- pgd_populate(&init_mm, pgd, p);
95738+ pgd_populate_kernel(&init_mm, pgd, p);
95739 }
95740 return pgd;
95741 }
95742diff --git a/mm/sparse.c b/mm/sparse.c
95743index 8cc7be0..d0f7d7a 100644
95744--- a/mm/sparse.c
95745+++ b/mm/sparse.c
95746@@ -745,7 +745,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
95747
95748 for (i = 0; i < PAGES_PER_SECTION; i++) {
95749 if (PageHWPoison(&memmap[i])) {
95750- atomic_long_sub(1, &num_poisoned_pages);
95751+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
95752 ClearPageHWPoison(&memmap[i]);
95753 }
95754 }
95755diff --git a/mm/swap.c b/mm/swap.c
95756index 7010cf4..f0a56a4 100644
95757--- a/mm/swap.c
95758+++ b/mm/swap.c
95759@@ -77,6 +77,8 @@ static void __put_compound_page(struct page *page)
95760
95761 __page_cache_release(page);
95762 dtor = get_compound_page_dtor(page);
95763+ if (!PageHuge(page))
95764+ BUG_ON(dtor != free_compound_page);
95765 (*dtor)(page);
95766 }
95767
95768diff --git a/mm/swapfile.c b/mm/swapfile.c
95769index 461fce2..363ae44 100644
95770--- a/mm/swapfile.c
95771+++ b/mm/swapfile.c
95772@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
95773
95774 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
95775 /* Activity counter to indicate that a swapon or swapoff has occurred */
95776-static atomic_t proc_poll_event = ATOMIC_INIT(0);
95777+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
95778
95779 static inline unsigned char swap_count(unsigned char ent)
95780 {
95781@@ -1958,7 +1958,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
95782 spin_unlock(&swap_lock);
95783
95784 err = 0;
95785- atomic_inc(&proc_poll_event);
95786+ atomic_inc_unchecked(&proc_poll_event);
95787 wake_up_interruptible(&proc_poll_wait);
95788
95789 out_dput:
95790@@ -1975,8 +1975,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
95791
95792 poll_wait(file, &proc_poll_wait, wait);
95793
95794- if (seq->poll_event != atomic_read(&proc_poll_event)) {
95795- seq->poll_event = atomic_read(&proc_poll_event);
95796+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
95797+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
95798 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
95799 }
95800
95801@@ -2074,7 +2074,7 @@ static int swaps_open(struct inode *inode, struct file *file)
95802 return ret;
95803
95804 seq = file->private_data;
95805- seq->poll_event = atomic_read(&proc_poll_event);
95806+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
95807 return 0;
95808 }
95809
95810@@ -2533,7 +2533,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
95811 (frontswap_map) ? "FS" : "");
95812
95813 mutex_unlock(&swapon_mutex);
95814- atomic_inc(&proc_poll_event);
95815+ atomic_inc_unchecked(&proc_poll_event);
95816 wake_up_interruptible(&proc_poll_wait);
95817
95818 if (S_ISREG(inode->i_mode))
95819diff --git a/mm/util.c b/mm/util.c
95820index 808f375..e4764b5 100644
95821--- a/mm/util.c
95822+++ b/mm/util.c
95823@@ -297,6 +297,12 @@ done:
95824 void arch_pick_mmap_layout(struct mm_struct *mm)
95825 {
95826 mm->mmap_base = TASK_UNMAPPED_BASE;
95827+
95828+#ifdef CONFIG_PAX_RANDMMAP
95829+ if (mm->pax_flags & MF_PAX_RANDMMAP)
95830+ mm->mmap_base += mm->delta_mmap;
95831+#endif
95832+
95833 mm->get_unmapped_area = arch_get_unmapped_area;
95834 }
95835 #endif
95836diff --git a/mm/vmalloc.c b/mm/vmalloc.c
95837index 0fdf968..d6686e8 100644
95838--- a/mm/vmalloc.c
95839+++ b/mm/vmalloc.c
95840@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
95841
95842 pte = pte_offset_kernel(pmd, addr);
95843 do {
95844- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
95845- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
95846+
95847+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
95848+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
95849+ BUG_ON(!pte_exec(*pte));
95850+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
95851+ continue;
95852+ }
95853+#endif
95854+
95855+ {
95856+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
95857+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
95858+ }
95859 } while (pte++, addr += PAGE_SIZE, addr != end);
95860 }
95861
95862@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
95863 pte = pte_alloc_kernel(pmd, addr);
95864 if (!pte)
95865 return -ENOMEM;
95866+
95867+ pax_open_kernel();
95868 do {
95869 struct page *page = pages[*nr];
95870
95871- if (WARN_ON(!pte_none(*pte)))
95872+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
95873+ if (pgprot_val(prot) & _PAGE_NX)
95874+#endif
95875+
95876+ if (!pte_none(*pte)) {
95877+ pax_close_kernel();
95878+ WARN_ON(1);
95879 return -EBUSY;
95880- if (WARN_ON(!page))
95881+ }
95882+ if (!page) {
95883+ pax_close_kernel();
95884+ WARN_ON(1);
95885 return -ENOMEM;
95886+ }
95887 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
95888 (*nr)++;
95889 } while (pte++, addr += PAGE_SIZE, addr != end);
95890+ pax_close_kernel();
95891 return 0;
95892 }
95893
95894@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
95895 pmd_t *pmd;
95896 unsigned long next;
95897
95898- pmd = pmd_alloc(&init_mm, pud, addr);
95899+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
95900 if (!pmd)
95901 return -ENOMEM;
95902 do {
95903@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
95904 pud_t *pud;
95905 unsigned long next;
95906
95907- pud = pud_alloc(&init_mm, pgd, addr);
95908+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
95909 if (!pud)
95910 return -ENOMEM;
95911 do {
95912@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
95913 if (addr >= MODULES_VADDR && addr < MODULES_END)
95914 return 1;
95915 #endif
95916+
95917+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
95918+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
95919+ return 1;
95920+#endif
95921+
95922 return is_vmalloc_addr(x);
95923 }
95924
95925@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
95926
95927 if (!pgd_none(*pgd)) {
95928 pud_t *pud = pud_offset(pgd, addr);
95929+#ifdef CONFIG_X86
95930+ if (!pud_large(*pud))
95931+#endif
95932 if (!pud_none(*pud)) {
95933 pmd_t *pmd = pmd_offset(pud, addr);
95934+#ifdef CONFIG_X86
95935+ if (!pmd_large(*pmd))
95936+#endif
95937 if (!pmd_none(*pmd)) {
95938 pte_t *ptep, pte;
95939
95940@@ -1309,6 +1345,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
95941 struct vm_struct *area;
95942
95943 BUG_ON(in_interrupt());
95944+
95945+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
95946+ if (flags & VM_KERNEXEC) {
95947+ if (start != VMALLOC_START || end != VMALLOC_END)
95948+ return NULL;
95949+ start = (unsigned long)MODULES_EXEC_VADDR;
95950+ end = (unsigned long)MODULES_EXEC_END;
95951+ }
95952+#endif
95953+
95954 if (flags & VM_IOREMAP)
95955 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
95956
95957@@ -1534,6 +1580,11 @@ void *vmap(struct page **pages, unsigned int count,
95958 if (count > totalram_pages)
95959 return NULL;
95960
95961+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
95962+ if (!(pgprot_val(prot) & _PAGE_NX))
95963+ flags |= VM_KERNEXEC;
95964+#endif
95965+
95966 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
95967 __builtin_return_address(0));
95968 if (!area)
95969@@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
95970 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
95971 goto fail;
95972
95973+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
95974+ if (!(pgprot_val(prot) & _PAGE_NX))
95975+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
95976+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
95977+ else
95978+#endif
95979+
95980 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
95981 start, end, node, gfp_mask, caller);
95982 if (!area)
95983@@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
95984 * For tight control over page level allocator and protection flags
95985 * use __vmalloc() instead.
95986 */
95987-
95988 void *vmalloc_exec(unsigned long size)
95989 {
95990- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
95991+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
95992 NUMA_NO_NODE, __builtin_return_address(0));
95993 }
95994
95995@@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
95996 {
95997 struct vm_struct *area;
95998
95999+ BUG_ON(vma->vm_mirror);
96000+
96001 size = PAGE_ALIGN(size);
96002
96003 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
96004@@ -2602,7 +2661,11 @@ static int s_show(struct seq_file *m, void *p)
96005 v->addr, v->addr + v->size, v->size);
96006
96007 if (v->caller)
96008+#ifdef CONFIG_GRKERNSEC_HIDESYM
96009+ seq_printf(m, " %pK", v->caller);
96010+#else
96011 seq_printf(m, " %pS", v->caller);
96012+#endif
96013
96014 if (v->nr_pages)
96015 seq_printf(m, " pages=%d", v->nr_pages);
96016diff --git a/mm/vmstat.c b/mm/vmstat.c
96017index 7249614..2639fc7 100644
96018--- a/mm/vmstat.c
96019+++ b/mm/vmstat.c
96020@@ -20,6 +20,7 @@
96021 #include <linux/writeback.h>
96022 #include <linux/compaction.h>
96023 #include <linux/mm_inline.h>
96024+#include <linux/grsecurity.h>
96025
96026 #include "internal.h"
96027
96028@@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
96029 *
96030 * vm_stat contains the global counters
96031 */
96032-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
96033+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
96034 EXPORT_SYMBOL(vm_stat);
96035
96036 #ifdef CONFIG_SMP
96037@@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
96038
96039 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
96040 if (diff[i])
96041- atomic_long_add(diff[i], &vm_stat[i]);
96042+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
96043 }
96044
96045 /*
96046@@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
96047 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
96048 if (v) {
96049
96050- atomic_long_add(v, &zone->vm_stat[i]);
96051+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
96052 global_diff[i] += v;
96053 #ifdef CONFIG_NUMA
96054 /* 3 seconds idle till flush */
96055@@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
96056
96057 v = p->vm_stat_diff[i];
96058 p->vm_stat_diff[i] = 0;
96059- atomic_long_add(v, &zone->vm_stat[i]);
96060+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
96061 global_diff[i] += v;
96062 }
96063 }
96064@@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
96065 if (pset->vm_stat_diff[i]) {
96066 int v = pset->vm_stat_diff[i];
96067 pset->vm_stat_diff[i] = 0;
96068- atomic_long_add(v, &zone->vm_stat[i]);
96069- atomic_long_add(v, &vm_stat[i]);
96070+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
96071+ atomic_long_add_unchecked(v, &vm_stat[i]);
96072 }
96073 }
96074 #endif
96075@@ -1148,10 +1149,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
96076 stat_items_size += sizeof(struct vm_event_state);
96077 #endif
96078
96079- v = kmalloc(stat_items_size, GFP_KERNEL);
96080+ v = kzalloc(stat_items_size, GFP_KERNEL);
96081 m->private = v;
96082 if (!v)
96083 return ERR_PTR(-ENOMEM);
96084+
96085+#ifdef CONFIG_GRKERNSEC_PROC_ADD
96086+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
96087+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
96088+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
96089+ && !in_group_p(grsec_proc_gid)
96090+#endif
96091+ )
96092+ return (unsigned long *)m->private + *pos;
96093+#endif
96094+#endif
96095+
96096 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
96097 v[i] = global_page_state(i);
96098 v += NR_VM_ZONE_STAT_ITEMS;
96099@@ -1300,10 +1313,16 @@ static int __init setup_vmstat(void)
96100 put_online_cpus();
96101 #endif
96102 #ifdef CONFIG_PROC_FS
96103- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
96104- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
96105- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
96106- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
96107+ {
96108+ mode_t gr_mode = S_IRUGO;
96109+#ifdef CONFIG_GRKERNSEC_PROC_ADD
96110+ gr_mode = S_IRUSR;
96111+#endif
96112+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
96113+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
96114+ proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
96115+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
96116+ }
96117 #endif
96118 return 0;
96119 }
96120diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
96121index b3d17d1..e8e4cdd 100644
96122--- a/net/8021q/vlan.c
96123+++ b/net/8021q/vlan.c
96124@@ -472,7 +472,7 @@ out:
96125 return NOTIFY_DONE;
96126 }
96127
96128-static struct notifier_block vlan_notifier_block __read_mostly = {
96129+static struct notifier_block vlan_notifier_block = {
96130 .notifier_call = vlan_device_event,
96131 };
96132
96133@@ -547,8 +547,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
96134 err = -EPERM;
96135 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
96136 break;
96137- if ((args.u.name_type >= 0) &&
96138- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
96139+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
96140 struct vlan_net *vn;
96141
96142 vn = net_generic(net, vlan_net_id);
96143diff --git a/net/9p/client.c b/net/9p/client.c
96144index ee8fd6b..0469d50 100644
96145--- a/net/9p/client.c
96146+++ b/net/9p/client.c
96147@@ -588,7 +588,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
96148 len - inline_len);
96149 } else {
96150 err = copy_from_user(ename + inline_len,
96151- uidata, len - inline_len);
96152+ (char __force_user *)uidata, len - inline_len);
96153 if (err) {
96154 err = -EFAULT;
96155 goto out_err;
96156@@ -1563,7 +1563,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
96157 kernel_buf = 1;
96158 indata = data;
96159 } else
96160- indata = (__force char *)udata;
96161+ indata = (__force_kernel char *)udata;
96162 /*
96163 * response header len is 11
96164 * PDU Header(7) + IO Size (4)
96165@@ -1638,7 +1638,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
96166 kernel_buf = 1;
96167 odata = data;
96168 } else
96169- odata = (char *)udata;
96170+ odata = (char __force_kernel *)udata;
96171 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
96172 P9_ZC_HDR_SZ, kernel_buf, "dqd",
96173 fid->fid, offset, rsize);
96174diff --git a/net/9p/mod.c b/net/9p/mod.c
96175index 6ab36ae..6f1841b 100644
96176--- a/net/9p/mod.c
96177+++ b/net/9p/mod.c
96178@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
96179 void v9fs_register_trans(struct p9_trans_module *m)
96180 {
96181 spin_lock(&v9fs_trans_lock);
96182- list_add_tail(&m->list, &v9fs_trans_list);
96183+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
96184 spin_unlock(&v9fs_trans_lock);
96185 }
96186 EXPORT_SYMBOL(v9fs_register_trans);
96187@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
96188 void v9fs_unregister_trans(struct p9_trans_module *m)
96189 {
96190 spin_lock(&v9fs_trans_lock);
96191- list_del_init(&m->list);
96192+ pax_list_del_init((struct list_head *)&m->list);
96193 spin_unlock(&v9fs_trans_lock);
96194 }
96195 EXPORT_SYMBOL(v9fs_unregister_trans);
96196diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
96197index 9321a77..ed2f256 100644
96198--- a/net/9p/trans_fd.c
96199+++ b/net/9p/trans_fd.c
96200@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
96201 oldfs = get_fs();
96202 set_fs(get_ds());
96203 /* The cast to a user pointer is valid due to the set_fs() */
96204- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
96205+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
96206 set_fs(oldfs);
96207
96208 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
96209diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
96210index 876fbe8..8bbea9f 100644
96211--- a/net/atm/atm_misc.c
96212+++ b/net/atm/atm_misc.c
96213@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
96214 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
96215 return 1;
96216 atm_return(vcc, truesize);
96217- atomic_inc(&vcc->stats->rx_drop);
96218+ atomic_inc_unchecked(&vcc->stats->rx_drop);
96219 return 0;
96220 }
96221 EXPORT_SYMBOL(atm_charge);
96222@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
96223 }
96224 }
96225 atm_return(vcc, guess);
96226- atomic_inc(&vcc->stats->rx_drop);
96227+ atomic_inc_unchecked(&vcc->stats->rx_drop);
96228 return NULL;
96229 }
96230 EXPORT_SYMBOL(atm_alloc_charge);
96231@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
96232
96233 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
96234 {
96235-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
96236+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
96237 __SONET_ITEMS
96238 #undef __HANDLE_ITEM
96239 }
96240@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
96241
96242 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
96243 {
96244-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
96245+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
96246 __SONET_ITEMS
96247 #undef __HANDLE_ITEM
96248 }
96249diff --git a/net/atm/lec.c b/net/atm/lec.c
96250index f23916b..dd4d26b 100644
96251--- a/net/atm/lec.c
96252+++ b/net/atm/lec.c
96253@@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
96254 }
96255
96256 static struct lane2_ops lane2_ops = {
96257- lane2_resolve, /* resolve, spec 3.1.3 */
96258- lane2_associate_req, /* associate_req, spec 3.1.4 */
96259- NULL /* associate indicator, spec 3.1.5 */
96260+ .resolve = lane2_resolve,
96261+ .associate_req = lane2_associate_req,
96262+ .associate_indicator = NULL
96263 };
96264
96265 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
96266diff --git a/net/atm/lec.h b/net/atm/lec.h
96267index 4149db1..f2ab682 100644
96268--- a/net/atm/lec.h
96269+++ b/net/atm/lec.h
96270@@ -48,7 +48,7 @@ struct lane2_ops {
96271 const u8 *tlvs, u32 sizeoftlvs);
96272 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
96273 const u8 *tlvs, u32 sizeoftlvs);
96274-};
96275+} __no_const;
96276
96277 /*
96278 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
96279diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
96280index d1b2d9a..d549f7f 100644
96281--- a/net/atm/mpoa_caches.c
96282+++ b/net/atm/mpoa_caches.c
96283@@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
96284
96285
96286 static struct in_cache_ops ingress_ops = {
96287- in_cache_add_entry, /* add_entry */
96288- in_cache_get, /* get */
96289- in_cache_get_with_mask, /* get_with_mask */
96290- in_cache_get_by_vcc, /* get_by_vcc */
96291- in_cache_put, /* put */
96292- in_cache_remove_entry, /* remove_entry */
96293- cache_hit, /* cache_hit */
96294- clear_count_and_expired, /* clear_count */
96295- check_resolving_entries, /* check_resolving */
96296- refresh_entries, /* refresh */
96297- in_destroy_cache /* destroy_cache */
96298+ .add_entry = in_cache_add_entry,
96299+ .get = in_cache_get,
96300+ .get_with_mask = in_cache_get_with_mask,
96301+ .get_by_vcc = in_cache_get_by_vcc,
96302+ .put = in_cache_put,
96303+ .remove_entry = in_cache_remove_entry,
96304+ .cache_hit = cache_hit,
96305+ .clear_count = clear_count_and_expired,
96306+ .check_resolving = check_resolving_entries,
96307+ .refresh = refresh_entries,
96308+ .destroy_cache = in_destroy_cache
96309 };
96310
96311 static struct eg_cache_ops egress_ops = {
96312- eg_cache_add_entry, /* add_entry */
96313- eg_cache_get_by_cache_id, /* get_by_cache_id */
96314- eg_cache_get_by_tag, /* get_by_tag */
96315- eg_cache_get_by_vcc, /* get_by_vcc */
96316- eg_cache_get_by_src_ip, /* get_by_src_ip */
96317- eg_cache_put, /* put */
96318- eg_cache_remove_entry, /* remove_entry */
96319- update_eg_cache_entry, /* update */
96320- clear_expired, /* clear_expired */
96321- eg_destroy_cache /* destroy_cache */
96322+ .add_entry = eg_cache_add_entry,
96323+ .get_by_cache_id = eg_cache_get_by_cache_id,
96324+ .get_by_tag = eg_cache_get_by_tag,
96325+ .get_by_vcc = eg_cache_get_by_vcc,
96326+ .get_by_src_ip = eg_cache_get_by_src_ip,
96327+ .put = eg_cache_put,
96328+ .remove_entry = eg_cache_remove_entry,
96329+ .update = update_eg_cache_entry,
96330+ .clear_expired = clear_expired,
96331+ .destroy_cache = eg_destroy_cache
96332 };
96333
96334
96335diff --git a/net/atm/proc.c b/net/atm/proc.c
96336index bbb6461..cf04016 100644
96337--- a/net/atm/proc.c
96338+++ b/net/atm/proc.c
96339@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
96340 const struct k_atm_aal_stats *stats)
96341 {
96342 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
96343- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
96344- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
96345- atomic_read(&stats->rx_drop));
96346+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
96347+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
96348+ atomic_read_unchecked(&stats->rx_drop));
96349 }
96350
96351 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
96352diff --git a/net/atm/resources.c b/net/atm/resources.c
96353index 0447d5d..3cf4728 100644
96354--- a/net/atm/resources.c
96355+++ b/net/atm/resources.c
96356@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
96357 static void copy_aal_stats(struct k_atm_aal_stats *from,
96358 struct atm_aal_stats *to)
96359 {
96360-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
96361+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
96362 __AAL_STAT_ITEMS
96363 #undef __HANDLE_ITEM
96364 }
96365@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
96366 static void subtract_aal_stats(struct k_atm_aal_stats *from,
96367 struct atm_aal_stats *to)
96368 {
96369-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
96370+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
96371 __AAL_STAT_ITEMS
96372 #undef __HANDLE_ITEM
96373 }
96374diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
96375index 919a5ce..cc6b444 100644
96376--- a/net/ax25/sysctl_net_ax25.c
96377+++ b/net/ax25/sysctl_net_ax25.c
96378@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
96379 {
96380 char path[sizeof("net/ax25/") + IFNAMSIZ];
96381 int k;
96382- struct ctl_table *table;
96383+ ctl_table_no_const *table;
96384
96385 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
96386 if (!table)
96387diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
96388index f7270b9..cd0d879 100644
96389--- a/net/batman-adv/bat_iv_ogm.c
96390+++ b/net/batman-adv/bat_iv_ogm.c
96391@@ -307,7 +307,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
96392
96393 /* randomize initial seqno to avoid collision */
96394 get_random_bytes(&random_seqno, sizeof(random_seqno));
96395- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
96396+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
96397
96398 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
96399 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
96400@@ -894,9 +894,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
96401 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
96402
96403 /* change sequence number to network order */
96404- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
96405+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
96406 batadv_ogm_packet->seqno = htonl(seqno);
96407- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
96408+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
96409
96410 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
96411 batadv_iv_ogm_queue_add(bat_priv, hard_iface->bat_iv.ogm_buff,
96412@@ -1261,7 +1261,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
96413 return;
96414
96415 /* could be changed by schedule_own_packet() */
96416- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
96417+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
96418
96419 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
96420 has_directlink_flag = 1;
96421diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
96422index 6ddb614..ca7e886 100644
96423--- a/net/batman-adv/fragmentation.c
96424+++ b/net/batman-adv/fragmentation.c
96425@@ -447,7 +447,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
96426 frag_header.packet_type = BATADV_UNICAST_FRAG;
96427 frag_header.version = BATADV_COMPAT_VERSION;
96428 frag_header.ttl = BATADV_TTL;
96429- frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
96430+ frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
96431 frag_header.reserved = 0;
96432 frag_header.no = 0;
96433 frag_header.total_size = htons(skb->len);
96434diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
96435index a8f99d1..11797ef 100644
96436--- a/net/batman-adv/soft-interface.c
96437+++ b/net/batman-adv/soft-interface.c
96438@@ -278,7 +278,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
96439 primary_if->net_dev->dev_addr, ETH_ALEN);
96440
96441 /* set broadcast sequence number */
96442- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
96443+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
96444 bcast_packet->seqno = htonl(seqno);
96445
96446 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
96447@@ -688,7 +688,7 @@ static int batadv_softif_init_late(struct net_device *dev)
96448 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
96449
96450 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
96451- atomic_set(&bat_priv->bcast_seqno, 1);
96452+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
96453 atomic_set(&bat_priv->tt.vn, 0);
96454 atomic_set(&bat_priv->tt.local_changes, 0);
96455 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
96456@@ -700,7 +700,7 @@ static int batadv_softif_init_late(struct net_device *dev)
96457
96458 /* randomize initial seqno to avoid collision */
96459 get_random_bytes(&random_seqno, sizeof(random_seqno));
96460- atomic_set(&bat_priv->frag_seqno, random_seqno);
96461+ atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
96462
96463 bat_priv->primary_if = NULL;
96464 bat_priv->num_ifaces = 0;
96465diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
96466index 91dd369..9c25750 100644
96467--- a/net/batman-adv/types.h
96468+++ b/net/batman-adv/types.h
96469@@ -56,7 +56,7 @@
96470 struct batadv_hard_iface_bat_iv {
96471 unsigned char *ogm_buff;
96472 int ogm_buff_len;
96473- atomic_t ogm_seqno;
96474+ atomic_unchecked_t ogm_seqno;
96475 };
96476
96477 /**
96478@@ -673,7 +673,7 @@ struct batadv_priv {
96479 atomic_t bonding;
96480 atomic_t fragmentation;
96481 atomic_t packet_size_max;
96482- atomic_t frag_seqno;
96483+ atomic_unchecked_t frag_seqno;
96484 #ifdef CONFIG_BATMAN_ADV_BLA
96485 atomic_t bridge_loop_avoidance;
96486 #endif
96487@@ -687,7 +687,7 @@ struct batadv_priv {
96488 #ifdef CONFIG_BATMAN_ADV_DEBUG
96489 atomic_t log_level;
96490 #endif
96491- atomic_t bcast_seqno;
96492+ atomic_unchecked_t bcast_seqno;
96493 atomic_t bcast_queue_left;
96494 atomic_t batman_queue_left;
96495 char num_ifaces;
96496diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
96497index 7552f9e..074ce29 100644
96498--- a/net/bluetooth/hci_sock.c
96499+++ b/net/bluetooth/hci_sock.c
96500@@ -1052,7 +1052,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
96501 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
96502 }
96503
96504- len = min_t(unsigned int, len, sizeof(uf));
96505+ len = min((size_t)len, sizeof(uf));
96506 if (copy_from_user(&uf, optval, len)) {
96507 err = -EFAULT;
96508 break;
96509diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
96510index 4af3821..f2ba46c 100644
96511--- a/net/bluetooth/l2cap_core.c
96512+++ b/net/bluetooth/l2cap_core.c
96513@@ -3500,8 +3500,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
96514 break;
96515
96516 case L2CAP_CONF_RFC:
96517- if (olen == sizeof(rfc))
96518- memcpy(&rfc, (void *)val, olen);
96519+ if (olen != sizeof(rfc))
96520+ break;
96521+
96522+ memcpy(&rfc, (void *)val, olen);
96523
96524 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
96525 rfc.mode != chan->mode)
96526diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
96527index 7cc24d2..e83f531 100644
96528--- a/net/bluetooth/l2cap_sock.c
96529+++ b/net/bluetooth/l2cap_sock.c
96530@@ -545,7 +545,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
96531 struct sock *sk = sock->sk;
96532 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
96533 struct l2cap_options opts;
96534- int len, err = 0;
96535+ int err = 0;
96536+ size_t len = optlen;
96537 u32 opt;
96538
96539 BT_DBG("sk %p", sk);
96540@@ -567,7 +568,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
96541 opts.max_tx = chan->max_tx;
96542 opts.txwin_size = chan->tx_win;
96543
96544- len = min_t(unsigned int, sizeof(opts), optlen);
96545+ len = min(sizeof(opts), len);
96546 if (copy_from_user((char *) &opts, optval, len)) {
96547 err = -EFAULT;
96548 break;
96549@@ -647,7 +648,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96550 struct bt_security sec;
96551 struct bt_power pwr;
96552 struct l2cap_conn *conn;
96553- int len, err = 0;
96554+ int err = 0;
96555+ size_t len = optlen;
96556 u32 opt;
96557
96558 BT_DBG("sk %p", sk);
96559@@ -670,7 +672,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96560
96561 sec.level = BT_SECURITY_LOW;
96562
96563- len = min_t(unsigned int, sizeof(sec), optlen);
96564+ len = min(sizeof(sec), len);
96565 if (copy_from_user((char *) &sec, optval, len)) {
96566 err = -EFAULT;
96567 break;
96568@@ -770,7 +772,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96569
96570 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
96571
96572- len = min_t(unsigned int, sizeof(pwr), optlen);
96573+ len = min(sizeof(pwr), len);
96574 if (copy_from_user((char *) &pwr, optval, len)) {
96575 err = -EFAULT;
96576 break;
96577diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
96578index 3c2d3e4..884855a 100644
96579--- a/net/bluetooth/rfcomm/sock.c
96580+++ b/net/bluetooth/rfcomm/sock.c
96581@@ -672,7 +672,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
96582 struct sock *sk = sock->sk;
96583 struct bt_security sec;
96584 int err = 0;
96585- size_t len;
96586+ size_t len = optlen;
96587 u32 opt;
96588
96589 BT_DBG("sk %p", sk);
96590@@ -694,7 +694,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
96591
96592 sec.level = BT_SECURITY_LOW;
96593
96594- len = min_t(unsigned int, sizeof(sec), optlen);
96595+ len = min(sizeof(sec), len);
96596 if (copy_from_user((char *) &sec, optval, len)) {
96597 err = -EFAULT;
96598 break;
96599diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
96600index 84fcf9f..e389b27 100644
96601--- a/net/bluetooth/rfcomm/tty.c
96602+++ b/net/bluetooth/rfcomm/tty.c
96603@@ -684,7 +684,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
96604 BT_DBG("tty %p id %d", tty, tty->index);
96605
96606 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
96607- dev->channel, dev->port.count);
96608+ dev->channel, atomic_read(&dev->port.count));
96609
96610 err = tty_port_open(&dev->port, tty, filp);
96611 if (err)
96612@@ -707,7 +707,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
96613 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
96614
96615 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
96616- dev->port.count);
96617+ atomic_read(&dev->port.count));
96618
96619 tty_port_close(&dev->port, tty, filp);
96620 }
96621diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
96622index ac78024..161a80c 100644
96623--- a/net/bridge/netfilter/ebtables.c
96624+++ b/net/bridge/netfilter/ebtables.c
96625@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
96626 tmp.valid_hooks = t->table->valid_hooks;
96627 }
96628 mutex_unlock(&ebt_mutex);
96629- if (copy_to_user(user, &tmp, *len) != 0){
96630+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
96631 BUGPRINT("c2u Didn't work\n");
96632 ret = -EFAULT;
96633 break;
96634@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
96635 goto out;
96636 tmp.valid_hooks = t->valid_hooks;
96637
96638- if (copy_to_user(user, &tmp, *len) != 0) {
96639+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
96640 ret = -EFAULT;
96641 break;
96642 }
96643@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
96644 tmp.entries_size = t->table->entries_size;
96645 tmp.valid_hooks = t->table->valid_hooks;
96646
96647- if (copy_to_user(user, &tmp, *len) != 0) {
96648+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
96649 ret = -EFAULT;
96650 break;
96651 }
96652diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
96653index 0f45522..dab651f 100644
96654--- a/net/caif/cfctrl.c
96655+++ b/net/caif/cfctrl.c
96656@@ -10,6 +10,7 @@
96657 #include <linux/spinlock.h>
96658 #include <linux/slab.h>
96659 #include <linux/pkt_sched.h>
96660+#include <linux/sched.h>
96661 #include <net/caif/caif_layer.h>
96662 #include <net/caif/cfpkt.h>
96663 #include <net/caif/cfctrl.h>
96664@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
96665 memset(&dev_info, 0, sizeof(dev_info));
96666 dev_info.id = 0xff;
96667 cfsrvl_init(&this->serv, 0, &dev_info, false);
96668- atomic_set(&this->req_seq_no, 1);
96669- atomic_set(&this->rsp_seq_no, 1);
96670+ atomic_set_unchecked(&this->req_seq_no, 1);
96671+ atomic_set_unchecked(&this->rsp_seq_no, 1);
96672 this->serv.layer.receive = cfctrl_recv;
96673 sprintf(this->serv.layer.name, "ctrl");
96674 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
96675@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
96676 struct cfctrl_request_info *req)
96677 {
96678 spin_lock_bh(&ctrl->info_list_lock);
96679- atomic_inc(&ctrl->req_seq_no);
96680- req->sequence_no = atomic_read(&ctrl->req_seq_no);
96681+ atomic_inc_unchecked(&ctrl->req_seq_no);
96682+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
96683 list_add_tail(&req->list, &ctrl->list);
96684 spin_unlock_bh(&ctrl->info_list_lock);
96685 }
96686@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
96687 if (p != first)
96688 pr_warn("Requests are not received in order\n");
96689
96690- atomic_set(&ctrl->rsp_seq_no,
96691+ atomic_set_unchecked(&ctrl->rsp_seq_no,
96692 p->sequence_no);
96693 list_del(&p->list);
96694 goto out;
96695diff --git a/net/can/af_can.c b/net/can/af_can.c
96696index a27f8aa..67174a3 100644
96697--- a/net/can/af_can.c
96698+++ b/net/can/af_can.c
96699@@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
96700 };
96701
96702 /* notifier block for netdevice event */
96703-static struct notifier_block can_netdev_notifier __read_mostly = {
96704+static struct notifier_block can_netdev_notifier = {
96705 .notifier_call = can_notifier,
96706 };
96707
96708diff --git a/net/can/gw.c b/net/can/gw.c
96709index 3f9b0f3..fc6d4fa 100644
96710--- a/net/can/gw.c
96711+++ b/net/can/gw.c
96712@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
96713 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
96714
96715 static HLIST_HEAD(cgw_list);
96716-static struct notifier_block notifier;
96717
96718 static struct kmem_cache *cgw_cache __read_mostly;
96719
96720@@ -954,6 +953,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
96721 return err;
96722 }
96723
96724+static struct notifier_block notifier = {
96725+ .notifier_call = cgw_notifier
96726+};
96727+
96728 static __init int cgw_module_init(void)
96729 {
96730 /* sanitize given module parameter */
96731@@ -969,7 +972,6 @@ static __init int cgw_module_init(void)
96732 return -ENOMEM;
96733
96734 /* set notifier */
96735- notifier.notifier_call = cgw_notifier;
96736 register_netdevice_notifier(&notifier);
96737
96738 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
96739diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
96740index 464303f..9c30218 100644
96741--- a/net/ceph/messenger.c
96742+++ b/net/ceph/messenger.c
96743@@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
96744 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
96745
96746 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
96747-static atomic_t addr_str_seq = ATOMIC_INIT(0);
96748+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
96749
96750 static struct page *zero_page; /* used in certain error cases */
96751
96752@@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
96753 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
96754 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
96755
96756- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
96757+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
96758 s = addr_str[i];
96759
96760 switch (ss->ss_family) {
96761diff --git a/net/compat.c b/net/compat.c
96762index f50161f..94fa415 100644
96763--- a/net/compat.c
96764+++ b/net/compat.c
96765@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
96766 return -EFAULT;
96767 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
96768 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
96769- kmsg->msg_name = compat_ptr(tmp1);
96770- kmsg->msg_iov = compat_ptr(tmp2);
96771- kmsg->msg_control = compat_ptr(tmp3);
96772+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
96773+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
96774+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
96775 return 0;
96776 }
96777
96778@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96779
96780 if (kern_msg->msg_namelen) {
96781 if (mode == VERIFY_READ) {
96782- int err = move_addr_to_kernel(kern_msg->msg_name,
96783+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
96784 kern_msg->msg_namelen,
96785 kern_address);
96786 if (err < 0)
96787@@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96788 kern_msg->msg_name = NULL;
96789
96790 tot_len = iov_from_user_compat_to_kern(kern_iov,
96791- (struct compat_iovec __user *)kern_msg->msg_iov,
96792+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
96793 kern_msg->msg_iovlen);
96794 if (tot_len >= 0)
96795 kern_msg->msg_iov = kern_iov;
96796@@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96797
96798 #define CMSG_COMPAT_FIRSTHDR(msg) \
96799 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
96800- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
96801+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
96802 (struct compat_cmsghdr __user *)NULL)
96803
96804 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
96805 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
96806 (ucmlen) <= (unsigned long) \
96807 ((mhdr)->msg_controllen - \
96808- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
96809+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
96810
96811 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
96812 struct compat_cmsghdr __user *cmsg, int cmsg_len)
96813 {
96814 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
96815- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
96816+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
96817 msg->msg_controllen)
96818 return NULL;
96819 return (struct compat_cmsghdr __user *)ptr;
96820@@ -222,7 +222,7 @@ Efault:
96821
96822 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
96823 {
96824- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
96825+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
96826 struct compat_cmsghdr cmhdr;
96827 struct compat_timeval ctv;
96828 struct compat_timespec cts[3];
96829@@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
96830
96831 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
96832 {
96833- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
96834+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
96835 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
96836 int fdnum = scm->fp->count;
96837 struct file **fp = scm->fp->fp;
96838@@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
96839 return -EFAULT;
96840 old_fs = get_fs();
96841 set_fs(KERNEL_DS);
96842- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
96843+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
96844 set_fs(old_fs);
96845
96846 return err;
96847@@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
96848 len = sizeof(ktime);
96849 old_fs = get_fs();
96850 set_fs(KERNEL_DS);
96851- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
96852+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
96853 set_fs(old_fs);
96854
96855 if (!err) {
96856@@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
96857 case MCAST_JOIN_GROUP:
96858 case MCAST_LEAVE_GROUP:
96859 {
96860- struct compat_group_req __user *gr32 = (void *)optval;
96861+ struct compat_group_req __user *gr32 = (void __user *)optval;
96862 struct group_req __user *kgr =
96863 compat_alloc_user_space(sizeof(struct group_req));
96864 u32 interface;
96865@@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
96866 case MCAST_BLOCK_SOURCE:
96867 case MCAST_UNBLOCK_SOURCE:
96868 {
96869- struct compat_group_source_req __user *gsr32 = (void *)optval;
96870+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
96871 struct group_source_req __user *kgsr = compat_alloc_user_space(
96872 sizeof(struct group_source_req));
96873 u32 interface;
96874@@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
96875 }
96876 case MCAST_MSFILTER:
96877 {
96878- struct compat_group_filter __user *gf32 = (void *)optval;
96879+ struct compat_group_filter __user *gf32 = (void __user *)optval;
96880 struct group_filter __user *kgf;
96881 u32 interface, fmode, numsrc;
96882
96883@@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
96884 char __user *optval, int __user *optlen,
96885 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
96886 {
96887- struct compat_group_filter __user *gf32 = (void *)optval;
96888+ struct compat_group_filter __user *gf32 = (void __user *)optval;
96889 struct group_filter __user *kgf;
96890 int __user *koptlen;
96891 u32 interface, fmode, numsrc;
96892@@ -803,7 +803,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
96893
96894 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
96895 return -EINVAL;
96896- if (copy_from_user(a, args, nas[call]))
96897+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
96898 return -EFAULT;
96899 a0 = a[0];
96900 a1 = a[1];
96901diff --git a/net/core/datagram.c b/net/core/datagram.c
96902index a16ed7b..eb44d17 100644
96903--- a/net/core/datagram.c
96904+++ b/net/core/datagram.c
96905@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
96906 }
96907
96908 kfree_skb(skb);
96909- atomic_inc(&sk->sk_drops);
96910+ atomic_inc_unchecked(&sk->sk_drops);
96911 sk_mem_reclaim_partial(sk);
96912
96913 return err;
96914diff --git a/net/core/dev.c b/net/core/dev.c
96915index 616eccf..31832d38 100644
96916--- a/net/core/dev.c
96917+++ b/net/core/dev.c
96918@@ -1684,14 +1684,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
96919 {
96920 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
96921 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
96922- atomic_long_inc(&dev->rx_dropped);
96923+ atomic_long_inc_unchecked(&dev->rx_dropped);
96924 kfree_skb(skb);
96925 return NET_RX_DROP;
96926 }
96927 }
96928
96929 if (unlikely(!is_skb_forwardable(dev, skb))) {
96930- atomic_long_inc(&dev->rx_dropped);
96931+ atomic_long_inc_unchecked(&dev->rx_dropped);
96932 kfree_skb(skb);
96933 return NET_RX_DROP;
96934 }
96935@@ -2434,7 +2434,7 @@ static int illegal_highdma(const struct net_device *dev, struct sk_buff *skb)
96936
96937 struct dev_gso_cb {
96938 void (*destructor)(struct sk_buff *skb);
96939-};
96940+} __no_const;
96941
96942 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
96943
96944@@ -3224,7 +3224,7 @@ enqueue:
96945
96946 local_irq_restore(flags);
96947
96948- atomic_long_inc(&skb->dev->rx_dropped);
96949+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
96950 kfree_skb(skb);
96951 return NET_RX_DROP;
96952 }
96953@@ -3296,7 +3296,7 @@ int netif_rx_ni(struct sk_buff *skb)
96954 }
96955 EXPORT_SYMBOL(netif_rx_ni);
96956
96957-static void net_tx_action(struct softirq_action *h)
96958+static __latent_entropy void net_tx_action(void)
96959 {
96960 struct softnet_data *sd = &__get_cpu_var(softnet_data);
96961
96962@@ -3630,7 +3630,7 @@ ncls:
96963 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
96964 } else {
96965 drop:
96966- atomic_long_inc(&skb->dev->rx_dropped);
96967+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
96968 kfree_skb(skb);
96969 /* Jamal, now you will not able to escape explaining
96970 * me how you were going to use this. :-)
96971@@ -4290,7 +4290,7 @@ void netif_napi_del(struct napi_struct *napi)
96972 }
96973 EXPORT_SYMBOL(netif_napi_del);
96974
96975-static void net_rx_action(struct softirq_action *h)
96976+static __latent_entropy void net_rx_action(void)
96977 {
96978 struct softnet_data *sd = &__get_cpu_var(softnet_data);
96979 unsigned long time_limit = jiffies + 2;
96980@@ -6179,7 +6179,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
96981 } else {
96982 netdev_stats_to_stats64(storage, &dev->stats);
96983 }
96984- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
96985+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
96986 return storage;
96987 }
96988 EXPORT_SYMBOL(dev_get_stats);
96989diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
96990index 5b7d0e1..cb960fc 100644
96991--- a/net/core/dev_ioctl.c
96992+++ b/net/core/dev_ioctl.c
96993@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
96994 if (no_module && capable(CAP_NET_ADMIN))
96995 no_module = request_module("netdev-%s", name);
96996 if (no_module && capable(CAP_SYS_MODULE)) {
96997+#ifdef CONFIG_GRKERNSEC_MODHARDEN
96998+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
96999+#else
97000 if (!request_module("%s", name))
97001 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
97002 name);
97003+#endif
97004 }
97005 }
97006 EXPORT_SYMBOL(dev_load);
97007diff --git a/net/core/filter.c b/net/core/filter.c
97008index ad30d62..821081f 100644
97009--- a/net/core/filter.c
97010+++ b/net/core/filter.c
97011@@ -126,7 +126,7 @@ unsigned int sk_run_filter(const struct sk_buff *skb,
97012 void *ptr;
97013 u32 A = 0; /* Accumulator */
97014 u32 X = 0; /* Index Register */
97015- u32 mem[BPF_MEMWORDS]; /* Scratch Memory Store */
97016+ u32 mem[BPF_MEMWORDS] = {}; /* Scratch Memory Store */
97017 u32 tmp;
97018 int k;
97019
97020@@ -292,10 +292,10 @@ load_b:
97021 X = K;
97022 continue;
97023 case BPF_S_LD_MEM:
97024- A = mem[K];
97025+ A = mem[K&15];
97026 continue;
97027 case BPF_S_LDX_MEM:
97028- X = mem[K];
97029+ X = mem[K&15];
97030 continue;
97031 case BPF_S_MISC_TAX:
97032 X = A;
97033@@ -308,10 +308,10 @@ load_b:
97034 case BPF_S_RET_A:
97035 return A;
97036 case BPF_S_ST:
97037- mem[K] = A;
97038+ mem[K&15] = A;
97039 continue;
97040 case BPF_S_STX:
97041- mem[K] = X;
97042+ mem[K&15] = X;
97043 continue;
97044 case BPF_S_ANC_PROTOCOL:
97045 A = ntohs(skb->protocol);
97046@@ -391,9 +391,10 @@ load_b:
97047 continue;
97048 #endif
97049 default:
97050- WARN_RATELIMIT(1, "Unknown code:%u jt:%u tf:%u k:%u\n",
97051+ WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
97052 fentry->code, fentry->jt,
97053 fentry->jf, fentry->k);
97054+ BUG();
97055 return 0;
97056 }
97057 }
97058@@ -416,7 +417,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
97059 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
97060 int pc, ret = 0;
97061
97062- BUILD_BUG_ON(BPF_MEMWORDS > 16);
97063+ BUILD_BUG_ON(BPF_MEMWORDS != 16);
97064 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
97065 if (!masks)
97066 return -ENOMEM;
97067@@ -679,7 +680,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
97068 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
97069 if (!fp)
97070 return -ENOMEM;
97071- memcpy(fp->insns, fprog->filter, fsize);
97072+ memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
97073
97074 atomic_set(&fp->refcnt, 1);
97075 fp->len = fprog->len;
97076diff --git a/net/core/flow.c b/net/core/flow.c
97077index dfa602c..3103d88 100644
97078--- a/net/core/flow.c
97079+++ b/net/core/flow.c
97080@@ -61,7 +61,7 @@ struct flow_cache {
97081 struct timer_list rnd_timer;
97082 };
97083
97084-atomic_t flow_cache_genid = ATOMIC_INIT(0);
97085+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
97086 EXPORT_SYMBOL(flow_cache_genid);
97087 static struct flow_cache flow_cache_global;
97088 static struct kmem_cache *flow_cachep __read_mostly;
97089@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
97090
97091 static int flow_entry_valid(struct flow_cache_entry *fle)
97092 {
97093- if (atomic_read(&flow_cache_genid) != fle->genid)
97094+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
97095 return 0;
97096 if (fle->object && !fle->object->ops->check(fle->object))
97097 return 0;
97098@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
97099 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
97100 fcp->hash_count++;
97101 }
97102- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
97103+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
97104 flo = fle->object;
97105 if (!flo)
97106 goto ret_object;
97107@@ -279,7 +279,7 @@ nocache:
97108 }
97109 flo = resolver(net, key, family, dir, flo, ctx);
97110 if (fle) {
97111- fle->genid = atomic_read(&flow_cache_genid);
97112+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
97113 if (!IS_ERR(flo))
97114 fle->object = flo;
97115 else
97116diff --git a/net/core/iovec.c b/net/core/iovec.c
97117index b618694..192bbba 100644
97118--- a/net/core/iovec.c
97119+++ b/net/core/iovec.c
97120@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
97121 if (m->msg_namelen) {
97122 if (mode == VERIFY_READ) {
97123 void __user *namep;
97124- namep = (void __user __force *) m->msg_name;
97125+ namep = (void __force_user *) m->msg_name;
97126 err = move_addr_to_kernel(namep, m->msg_namelen,
97127 address);
97128 if (err < 0)
97129@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
97130 }
97131
97132 size = m->msg_iovlen * sizeof(struct iovec);
97133- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
97134+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
97135 return -EFAULT;
97136
97137 m->msg_iov = iov;
97138diff --git a/net/core/neighbour.c b/net/core/neighbour.c
97139index 43128dd..e4d4311 100644
97140--- a/net/core/neighbour.c
97141+++ b/net/core/neighbour.c
97142@@ -2775,7 +2775,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
97143 void __user *buffer, size_t *lenp, loff_t *ppos)
97144 {
97145 int size, ret;
97146- struct ctl_table tmp = *ctl;
97147+ ctl_table_no_const tmp = *ctl;
97148
97149 tmp.extra1 = &zero;
97150 tmp.extra2 = &unres_qlen_max;
97151@@ -2983,11 +2983,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
97152 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
97153 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
97154 } else {
97155+ struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
97156 dev_name_source = "default";
97157- t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
97158- t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
97159- t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
97160- t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
97161+ t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
97162+ t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
97163+ t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
97164+ t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
97165 }
97166
97167
97168diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
97169index 2bf8329..7960607 100644
97170--- a/net/core/net-procfs.c
97171+++ b/net/core/net-procfs.c
97172@@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
97173 else
97174 seq_printf(seq, "%04x", ntohs(pt->type));
97175
97176+#ifdef CONFIG_GRKERNSEC_HIDESYM
97177+ seq_printf(seq, " %-8s %pf\n",
97178+ pt->dev ? pt->dev->name : "", NULL);
97179+#else
97180 seq_printf(seq, " %-8s %pf\n",
97181 pt->dev ? pt->dev->name : "", pt->func);
97182+#endif
97183 }
97184
97185 return 0;
97186diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
97187index f3edf96..3cd8b40 100644
97188--- a/net/core/net-sysfs.c
97189+++ b/net/core/net-sysfs.c
97190@@ -1358,7 +1358,7 @@ void netdev_class_remove_file_ns(struct class_attribute *class_attr,
97191 }
97192 EXPORT_SYMBOL(netdev_class_remove_file_ns);
97193
97194-int netdev_kobject_init(void)
97195+int __init netdev_kobject_init(void)
97196 {
97197 kobj_ns_type_register(&net_ns_type_operations);
97198 return class_register(&net_class);
97199diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
97200index 81d3a9a..a0bd7a8 100644
97201--- a/net/core/net_namespace.c
97202+++ b/net/core/net_namespace.c
97203@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
97204 int error;
97205 LIST_HEAD(net_exit_list);
97206
97207- list_add_tail(&ops->list, list);
97208+ pax_list_add_tail((struct list_head *)&ops->list, list);
97209 if (ops->init || (ops->id && ops->size)) {
97210 for_each_net(net) {
97211 error = ops_init(ops, net);
97212@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
97213
97214 out_undo:
97215 /* If I have an error cleanup all namespaces I initialized */
97216- list_del(&ops->list);
97217+ pax_list_del((struct list_head *)&ops->list);
97218 ops_exit_list(ops, &net_exit_list);
97219 ops_free_list(ops, &net_exit_list);
97220 return error;
97221@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
97222 struct net *net;
97223 LIST_HEAD(net_exit_list);
97224
97225- list_del(&ops->list);
97226+ pax_list_del((struct list_head *)&ops->list);
97227 for_each_net(net)
97228 list_add_tail(&net->exit_list, &net_exit_list);
97229 ops_exit_list(ops, &net_exit_list);
97230@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
97231 mutex_lock(&net_mutex);
97232 error = register_pernet_operations(&pernet_list, ops);
97233 if (!error && (first_device == &pernet_list))
97234- first_device = &ops->list;
97235+ first_device = (struct list_head *)&ops->list;
97236 mutex_unlock(&net_mutex);
97237 return error;
97238 }
97239diff --git a/net/core/netpoll.c b/net/core/netpoll.c
97240index 81975f2..9ef3531 100644
97241--- a/net/core/netpoll.c
97242+++ b/net/core/netpoll.c
97243@@ -435,7 +435,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
97244 struct udphdr *udph;
97245 struct iphdr *iph;
97246 struct ethhdr *eth;
97247- static atomic_t ip_ident;
97248+ static atomic_unchecked_t ip_ident;
97249 struct ipv6hdr *ip6h;
97250
97251 udp_len = len + sizeof(*udph);
97252@@ -506,7 +506,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
97253 put_unaligned(0x45, (unsigned char *)iph);
97254 iph->tos = 0;
97255 put_unaligned(htons(ip_len), &(iph->tot_len));
97256- iph->id = htons(atomic_inc_return(&ip_ident));
97257+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
97258 iph->frag_off = 0;
97259 iph->ttl = 64;
97260 iph->protocol = IPPROTO_UDP;
97261diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
97262index cf67144..12bf94c 100644
97263--- a/net/core/rtnetlink.c
97264+++ b/net/core/rtnetlink.c
97265@@ -58,7 +58,7 @@ struct rtnl_link {
97266 rtnl_doit_func doit;
97267 rtnl_dumpit_func dumpit;
97268 rtnl_calcit_func calcit;
97269-};
97270+} __no_const;
97271
97272 static DEFINE_MUTEX(rtnl_mutex);
97273
97274@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
97275 if (rtnl_link_ops_get(ops->kind))
97276 return -EEXIST;
97277
97278- if (!ops->dellink)
97279- ops->dellink = unregister_netdevice_queue;
97280+ if (!ops->dellink) {
97281+ pax_open_kernel();
97282+ *(void **)&ops->dellink = unregister_netdevice_queue;
97283+ pax_close_kernel();
97284+ }
97285
97286- list_add_tail(&ops->list, &link_ops);
97287+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
97288 return 0;
97289 }
97290 EXPORT_SYMBOL_GPL(__rtnl_link_register);
97291@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
97292 for_each_net(net) {
97293 __rtnl_kill_links(net, ops);
97294 }
97295- list_del(&ops->list);
97296+ pax_list_del((struct list_head *)&ops->list);
97297 }
97298 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
97299
97300diff --git a/net/core/scm.c b/net/core/scm.c
97301index b442e7e..6f5b5a2 100644
97302--- a/net/core/scm.c
97303+++ b/net/core/scm.c
97304@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
97305 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
97306 {
97307 struct cmsghdr __user *cm
97308- = (__force struct cmsghdr __user *)msg->msg_control;
97309+ = (struct cmsghdr __force_user *)msg->msg_control;
97310 struct cmsghdr cmhdr;
97311 int cmlen = CMSG_LEN(len);
97312 int err;
97313@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
97314 err = -EFAULT;
97315 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
97316 goto out;
97317- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
97318+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
97319 goto out;
97320 cmlen = CMSG_SPACE(len);
97321 if (msg->msg_controllen < cmlen)
97322@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
97323 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
97324 {
97325 struct cmsghdr __user *cm
97326- = (__force struct cmsghdr __user*)msg->msg_control;
97327+ = (struct cmsghdr __force_user *)msg->msg_control;
97328
97329 int fdmax = 0;
97330 int fdnum = scm->fp->count;
97331@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
97332 if (fdnum < fdmax)
97333 fdmax = fdnum;
97334
97335- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
97336+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
97337 i++, cmfptr++)
97338 {
97339 struct socket *sock;
97340diff --git a/net/core/skbuff.c b/net/core/skbuff.c
97341index deffb37..213db0a 100644
97342--- a/net/core/skbuff.c
97343+++ b/net/core/skbuff.c
97344@@ -2006,7 +2006,7 @@ EXPORT_SYMBOL(__skb_checksum);
97345 __wsum skb_checksum(const struct sk_buff *skb, int offset,
97346 int len, __wsum csum)
97347 {
97348- const struct skb_checksum_ops ops = {
97349+ static const struct skb_checksum_ops ops = {
97350 .update = csum_partial_ext,
97351 .combine = csum_block_add_ext,
97352 };
97353@@ -3119,13 +3119,15 @@ void __init skb_init(void)
97354 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
97355 sizeof(struct sk_buff),
97356 0,
97357- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
97358+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
97359+ SLAB_NO_SANITIZE,
97360 NULL);
97361 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
97362 (2*sizeof(struct sk_buff)) +
97363 sizeof(atomic_t),
97364 0,
97365- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
97366+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
97367+ SLAB_NO_SANITIZE,
97368 NULL);
97369 }
97370
97371diff --git a/net/core/sock.c b/net/core/sock.c
97372index fbc5cfb..6d7e8c3 100644
97373--- a/net/core/sock.c
97374+++ b/net/core/sock.c
97375@@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97376 struct sk_buff_head *list = &sk->sk_receive_queue;
97377
97378 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
97379- atomic_inc(&sk->sk_drops);
97380+ atomic_inc_unchecked(&sk->sk_drops);
97381 trace_sock_rcvqueue_full(sk, skb);
97382 return -ENOMEM;
97383 }
97384@@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97385 return err;
97386
97387 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
97388- atomic_inc(&sk->sk_drops);
97389+ atomic_inc_unchecked(&sk->sk_drops);
97390 return -ENOBUFS;
97391 }
97392
97393@@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97394 skb_dst_force(skb);
97395
97396 spin_lock_irqsave(&list->lock, flags);
97397- skb->dropcount = atomic_read(&sk->sk_drops);
97398+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
97399 __skb_queue_tail(list, skb);
97400 spin_unlock_irqrestore(&list->lock, flags);
97401
97402@@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
97403 skb->dev = NULL;
97404
97405 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
97406- atomic_inc(&sk->sk_drops);
97407+ atomic_inc_unchecked(&sk->sk_drops);
97408 goto discard_and_relse;
97409 }
97410 if (nested)
97411@@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
97412 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
97413 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
97414 bh_unlock_sock(sk);
97415- atomic_inc(&sk->sk_drops);
97416+ atomic_inc_unchecked(&sk->sk_drops);
97417 goto discard_and_relse;
97418 }
97419
97420@@ -950,12 +950,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97421 struct timeval tm;
97422 } v;
97423
97424- int lv = sizeof(int);
97425- int len;
97426+ unsigned int lv = sizeof(int);
97427+ unsigned int len;
97428
97429 if (get_user(len, optlen))
97430 return -EFAULT;
97431- if (len < 0)
97432+ if (len > INT_MAX)
97433 return -EINVAL;
97434
97435 memset(&v, 0, sizeof(v));
97436@@ -1107,11 +1107,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97437
97438 case SO_PEERNAME:
97439 {
97440- char address[128];
97441+ char address[_K_SS_MAXSIZE];
97442
97443 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
97444 return -ENOTCONN;
97445- if (lv < len)
97446+ if (lv < len || sizeof address < len)
97447 return -EINVAL;
97448 if (copy_to_user(optval, address, len))
97449 return -EFAULT;
97450@@ -1188,7 +1188,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97451
97452 if (len > lv)
97453 len = lv;
97454- if (copy_to_user(optval, &v, len))
97455+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
97456 return -EFAULT;
97457 lenout:
97458 if (put_user(len, optlen))
97459@@ -2353,7 +2353,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
97460 */
97461 smp_wmb();
97462 atomic_set(&sk->sk_refcnt, 1);
97463- atomic_set(&sk->sk_drops, 0);
97464+ atomic_set_unchecked(&sk->sk_drops, 0);
97465 }
97466 EXPORT_SYMBOL(sock_init_data);
97467
97468@@ -2478,6 +2478,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
97469 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
97470 int level, int type)
97471 {
97472+ struct sock_extended_err ee;
97473 struct sock_exterr_skb *serr;
97474 struct sk_buff *skb, *skb2;
97475 int copied, err;
97476@@ -2499,7 +2500,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
97477 sock_recv_timestamp(msg, sk, skb);
97478
97479 serr = SKB_EXT_ERR(skb);
97480- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
97481+ ee = serr->ee;
97482+ put_cmsg(msg, level, type, sizeof ee, &ee);
97483
97484 msg->msg_flags |= MSG_ERRQUEUE;
97485 err = copied;
97486diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
97487index a0e9cf6..ef7f9ed 100644
97488--- a/net/core/sock_diag.c
97489+++ b/net/core/sock_diag.c
97490@@ -9,26 +9,33 @@
97491 #include <linux/inet_diag.h>
97492 #include <linux/sock_diag.h>
97493
97494-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
97495+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
97496 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
97497 static DEFINE_MUTEX(sock_diag_table_mutex);
97498
97499 int sock_diag_check_cookie(void *sk, __u32 *cookie)
97500 {
97501+#ifndef CONFIG_GRKERNSEC_HIDESYM
97502 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
97503 cookie[1] != INET_DIAG_NOCOOKIE) &&
97504 ((u32)(unsigned long)sk != cookie[0] ||
97505 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
97506 return -ESTALE;
97507 else
97508+#endif
97509 return 0;
97510 }
97511 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
97512
97513 void sock_diag_save_cookie(void *sk, __u32 *cookie)
97514 {
97515+#ifdef CONFIG_GRKERNSEC_HIDESYM
97516+ cookie[0] = 0;
97517+ cookie[1] = 0;
97518+#else
97519 cookie[0] = (u32)(unsigned long)sk;
97520 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
97521+#endif
97522 }
97523 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
97524
97525@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
97526 mutex_lock(&sock_diag_table_mutex);
97527 if (sock_diag_handlers[hndl->family])
97528 err = -EBUSY;
97529- else
97530+ else {
97531+ pax_open_kernel();
97532 sock_diag_handlers[hndl->family] = hndl;
97533+ pax_close_kernel();
97534+ }
97535 mutex_unlock(&sock_diag_table_mutex);
97536
97537 return err;
97538@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
97539
97540 mutex_lock(&sock_diag_table_mutex);
97541 BUG_ON(sock_diag_handlers[family] != hnld);
97542+ pax_open_kernel();
97543 sock_diag_handlers[family] = NULL;
97544+ pax_close_kernel();
97545 mutex_unlock(&sock_diag_table_mutex);
97546 }
97547 EXPORT_SYMBOL_GPL(sock_diag_unregister);
97548diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
97549index cca4441..5e616de 100644
97550--- a/net/core/sysctl_net_core.c
97551+++ b/net/core/sysctl_net_core.c
97552@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
97553 {
97554 unsigned int orig_size, size;
97555 int ret, i;
97556- struct ctl_table tmp = {
97557+ ctl_table_no_const tmp = {
97558 .data = &size,
97559 .maxlen = sizeof(size),
97560 .mode = table->mode
97561@@ -199,7 +199,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
97562 void __user *buffer, size_t *lenp, loff_t *ppos)
97563 {
97564 char id[IFNAMSIZ];
97565- struct ctl_table tbl = {
97566+ ctl_table_no_const tbl = {
97567 .data = id,
97568 .maxlen = IFNAMSIZ,
97569 };
97570@@ -378,13 +378,12 @@ static struct ctl_table netns_core_table[] = {
97571
97572 static __net_init int sysctl_core_net_init(struct net *net)
97573 {
97574- struct ctl_table *tbl;
97575+ ctl_table_no_const *tbl = NULL;
97576
97577 net->core.sysctl_somaxconn = SOMAXCONN;
97578
97579- tbl = netns_core_table;
97580 if (!net_eq(net, &init_net)) {
97581- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
97582+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
97583 if (tbl == NULL)
97584 goto err_dup;
97585
97586@@ -394,17 +393,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
97587 if (net->user_ns != &init_user_ns) {
97588 tbl[0].procname = NULL;
97589 }
97590- }
97591-
97592- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
97593+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
97594+ } else
97595+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
97596 if (net->core.sysctl_hdr == NULL)
97597 goto err_reg;
97598
97599 return 0;
97600
97601 err_reg:
97602- if (tbl != netns_core_table)
97603- kfree(tbl);
97604+ kfree(tbl);
97605 err_dup:
97606 return -ENOMEM;
97607 }
97608@@ -419,7 +417,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
97609 kfree(tbl);
97610 }
97611
97612-static __net_initdata struct pernet_operations sysctl_core_ops = {
97613+static __net_initconst struct pernet_operations sysctl_core_ops = {
97614 .init = sysctl_core_net_init,
97615 .exit = sysctl_core_net_exit,
97616 };
97617diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
97618index dd4d506..fb2fb87 100644
97619--- a/net/decnet/af_decnet.c
97620+++ b/net/decnet/af_decnet.c
97621@@ -465,6 +465,7 @@ static struct proto dn_proto = {
97622 .sysctl_rmem = sysctl_decnet_rmem,
97623 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
97624 .obj_size = sizeof(struct dn_sock),
97625+ .slab_flags = SLAB_USERCOPY,
97626 };
97627
97628 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
97629diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
97630index dd0dfb2..fdbc764 100644
97631--- a/net/decnet/dn_dev.c
97632+++ b/net/decnet/dn_dev.c
97633@@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
97634 .extra1 = &min_t3,
97635 .extra2 = &max_t3
97636 },
97637- {0}
97638+ { }
97639 },
97640 };
97641
97642diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
97643index 5325b54..a0d4d69 100644
97644--- a/net/decnet/sysctl_net_decnet.c
97645+++ b/net/decnet/sysctl_net_decnet.c
97646@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
97647
97648 if (len > *lenp) len = *lenp;
97649
97650- if (copy_to_user(buffer, addr, len))
97651+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
97652 return -EFAULT;
97653
97654 *lenp = len;
97655@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
97656
97657 if (len > *lenp) len = *lenp;
97658
97659- if (copy_to_user(buffer, devname, len))
97660+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
97661 return -EFAULT;
97662
97663 *lenp = len;
97664diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
97665index 1865fdf..581a595 100644
97666--- a/net/ieee802154/dgram.c
97667+++ b/net/ieee802154/dgram.c
97668@@ -315,8 +315,9 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
97669 if (saddr) {
97670 saddr->family = AF_IEEE802154;
97671 saddr->addr = mac_cb(skb)->sa;
97672+ }
97673+ if (addr_len)
97674 *addr_len = sizeof(*saddr);
97675- }
97676
97677 if (flags & MSG_TRUNC)
97678 copied = skb->len;
97679diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
97680index e4d96d4..e1651da 100644
97681--- a/net/ipv4/af_inet.c
97682+++ b/net/ipv4/af_inet.c
97683@@ -1686,13 +1686,9 @@ static int __init inet_init(void)
97684
97685 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
97686
97687- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
97688- if (!sysctl_local_reserved_ports)
97689- goto out;
97690-
97691 rc = proto_register(&tcp_prot, 1);
97692 if (rc)
97693- goto out_free_reserved_ports;
97694+ goto out;
97695
97696 rc = proto_register(&udp_prot, 1);
97697 if (rc)
97698@@ -1799,8 +1795,6 @@ out_unregister_udp_proto:
97699 proto_unregister(&udp_prot);
97700 out_unregister_tcp_proto:
97701 proto_unregister(&tcp_prot);
97702-out_free_reserved_ports:
97703- kfree(sysctl_local_reserved_ports);
97704 goto out;
97705 }
97706
97707diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
97708index f4b34d8..c54a163 100644
97709--- a/net/ipv4/devinet.c
97710+++ b/net/ipv4/devinet.c
97711@@ -1534,7 +1534,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
97712 idx = 0;
97713 head = &net->dev_index_head[h];
97714 rcu_read_lock();
97715- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
97716+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
97717 net->dev_base_seq;
97718 hlist_for_each_entry_rcu(dev, head, index_hlist) {
97719 if (idx < s_idx)
97720@@ -1845,7 +1845,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
97721 idx = 0;
97722 head = &net->dev_index_head[h];
97723 rcu_read_lock();
97724- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
97725+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
97726 net->dev_base_seq;
97727 hlist_for_each_entry_rcu(dev, head, index_hlist) {
97728 if (idx < s_idx)
97729@@ -2070,7 +2070,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
97730 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
97731 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
97732
97733-static struct devinet_sysctl_table {
97734+static const struct devinet_sysctl_table {
97735 struct ctl_table_header *sysctl_header;
97736 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
97737 } devinet_sysctl = {
97738@@ -2192,7 +2192,7 @@ static __net_init int devinet_init_net(struct net *net)
97739 int err;
97740 struct ipv4_devconf *all, *dflt;
97741 #ifdef CONFIG_SYSCTL
97742- struct ctl_table *tbl = ctl_forward_entry;
97743+ ctl_table_no_const *tbl = NULL;
97744 struct ctl_table_header *forw_hdr;
97745 #endif
97746
97747@@ -2210,7 +2210,7 @@ static __net_init int devinet_init_net(struct net *net)
97748 goto err_alloc_dflt;
97749
97750 #ifdef CONFIG_SYSCTL
97751- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
97752+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
97753 if (tbl == NULL)
97754 goto err_alloc_ctl;
97755
97756@@ -2230,7 +2230,10 @@ static __net_init int devinet_init_net(struct net *net)
97757 goto err_reg_dflt;
97758
97759 err = -ENOMEM;
97760- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
97761+ if (!net_eq(net, &init_net))
97762+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
97763+ else
97764+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
97765 if (forw_hdr == NULL)
97766 goto err_reg_ctl;
97767 net->ipv4.forw_hdr = forw_hdr;
97768@@ -2246,8 +2249,7 @@ err_reg_ctl:
97769 err_reg_dflt:
97770 __devinet_sysctl_unregister(all);
97771 err_reg_all:
97772- if (tbl != ctl_forward_entry)
97773- kfree(tbl);
97774+ kfree(tbl);
97775 err_alloc_ctl:
97776 #endif
97777 if (dflt != &ipv4_devconf_dflt)
97778diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
97779index c7539e2..b455e51 100644
97780--- a/net/ipv4/fib_frontend.c
97781+++ b/net/ipv4/fib_frontend.c
97782@@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
97783 #ifdef CONFIG_IP_ROUTE_MULTIPATH
97784 fib_sync_up(dev);
97785 #endif
97786- atomic_inc(&net->ipv4.dev_addr_genid);
97787+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97788 rt_cache_flush(dev_net(dev));
97789 break;
97790 case NETDEV_DOWN:
97791 fib_del_ifaddr(ifa, NULL);
97792- atomic_inc(&net->ipv4.dev_addr_genid);
97793+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97794 if (ifa->ifa_dev->ifa_list == NULL) {
97795 /* Last address was deleted from this interface.
97796 * Disable IP.
97797@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
97798 #ifdef CONFIG_IP_ROUTE_MULTIPATH
97799 fib_sync_up(dev);
97800 #endif
97801- atomic_inc(&net->ipv4.dev_addr_genid);
97802+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97803 rt_cache_flush(net);
97804 break;
97805 case NETDEV_DOWN:
97806diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
97807index e63f47a..e5c531d 100644
97808--- a/net/ipv4/fib_semantics.c
97809+++ b/net/ipv4/fib_semantics.c
97810@@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
97811 nh->nh_saddr = inet_select_addr(nh->nh_dev,
97812 nh->nh_gw,
97813 nh->nh_parent->fib_scope);
97814- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
97815+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
97816
97817 return nh->nh_saddr;
97818 }
97819diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
97820index fc0e649..febfa65 100644
97821--- a/net/ipv4/inet_connection_sock.c
97822+++ b/net/ipv4/inet_connection_sock.c
97823@@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
97824 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
97825 #endif
97826
97827-unsigned long *sysctl_local_reserved_ports;
97828+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
97829 EXPORT_SYMBOL(sysctl_local_reserved_ports);
97830
97831 void inet_get_local_port_range(struct net *net, int *low, int *high)
97832diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c
97833index bb075fc..322dceb 100644
97834--- a/net/ipv4/inet_fragment.c
97835+++ b/net/ipv4/inet_fragment.c
97836@@ -278,9 +278,10 @@ static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf,
97837
97838 atomic_inc(&qp->refcnt);
97839 hlist_add_head(&qp->list, &hb->chain);
97840- spin_unlock(&hb->chain_lock);
97841- read_unlock(&f->lock);
97842 inet_frag_lru_add(nf, qp);
97843+ spin_unlock(&hb->chain_lock);
97844+ read_unlock(&f->lock);
97845+
97846 return qp;
97847 }
97848
97849diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
97850index 8b9cf27..0d8d592 100644
97851--- a/net/ipv4/inet_hashtables.c
97852+++ b/net/ipv4/inet_hashtables.c
97853@@ -18,6 +18,7 @@
97854 #include <linux/sched.h>
97855 #include <linux/slab.h>
97856 #include <linux/wait.h>
97857+#include <linux/security.h>
97858
97859 #include <net/inet_connection_sock.h>
97860 #include <net/inet_hashtables.h>
97861@@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
97862 return inet_ehashfn(net, laddr, lport, faddr, fport);
97863 }
97864
97865+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
97866+
97867 /*
97868 * Allocate and initialize a new local port bind bucket.
97869 * The bindhash mutex for snum's hash chain must be held here.
97870@@ -554,6 +557,8 @@ ok:
97871 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
97872 spin_unlock(&head->lock);
97873
97874+ gr_update_task_in_ip_table(current, inet_sk(sk));
97875+
97876 if (tw) {
97877 inet_twsk_deschedule(tw, death_row);
97878 while (twrefcnt) {
97879diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
97880index 33d5537..da337a4 100644
97881--- a/net/ipv4/inetpeer.c
97882+++ b/net/ipv4/inetpeer.c
97883@@ -503,8 +503,8 @@ relookup:
97884 if (p) {
97885 p->daddr = *daddr;
97886 atomic_set(&p->refcnt, 1);
97887- atomic_set(&p->rid, 0);
97888- atomic_set(&p->ip_id_count,
97889+ atomic_set_unchecked(&p->rid, 0);
97890+ atomic_set_unchecked(&p->ip_id_count,
97891 (daddr->family == AF_INET) ?
97892 secure_ip_id(daddr->addr.a4) :
97893 secure_ipv6_id(daddr->addr.a6));
97894diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
97895index 2481993..2d9a7a7 100644
97896--- a/net/ipv4/ip_fragment.c
97897+++ b/net/ipv4/ip_fragment.c
97898@@ -283,7 +283,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
97899 return 0;
97900
97901 start = qp->rid;
97902- end = atomic_inc_return(&peer->rid);
97903+ end = atomic_inc_return_unchecked(&peer->rid);
97904 qp->rid = end;
97905
97906 rc = qp->q.fragments && (end - start) > max;
97907@@ -760,12 +760,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
97908
97909 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
97910 {
97911- struct ctl_table *table;
97912+ ctl_table_no_const *table = NULL;
97913 struct ctl_table_header *hdr;
97914
97915- table = ip4_frags_ns_ctl_table;
97916 if (!net_eq(net, &init_net)) {
97917- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
97918+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
97919 if (table == NULL)
97920 goto err_alloc;
97921
97922@@ -776,9 +775,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
97923 /* Don't export sysctls to unprivileged users */
97924 if (net->user_ns != &init_user_ns)
97925 table[0].procname = NULL;
97926- }
97927+ hdr = register_net_sysctl(net, "net/ipv4", table);
97928+ } else
97929+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
97930
97931- hdr = register_net_sysctl(net, "net/ipv4", table);
97932 if (hdr == NULL)
97933 goto err_reg;
97934
97935@@ -786,8 +786,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
97936 return 0;
97937
97938 err_reg:
97939- if (!net_eq(net, &init_net))
97940- kfree(table);
97941+ kfree(table);
97942 err_alloc:
97943 return -ENOMEM;
97944 }
97945diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
97946index d306360..1c1a1f1 100644
97947--- a/net/ipv4/ip_gre.c
97948+++ b/net/ipv4/ip_gre.c
97949@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
97950 module_param(log_ecn_error, bool, 0644);
97951 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
97952
97953-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
97954+static struct rtnl_link_ops ipgre_link_ops;
97955 static int ipgre_tunnel_init(struct net_device *dev);
97956
97957 static int ipgre_net_id __read_mostly;
97958@@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
97959 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
97960 };
97961
97962-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
97963+static struct rtnl_link_ops ipgre_link_ops = {
97964 .kind = "gre",
97965 .maxtype = IFLA_GRE_MAX,
97966 .policy = ipgre_policy,
97967@@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
97968 .fill_info = ipgre_fill_info,
97969 };
97970
97971-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
97972+static struct rtnl_link_ops ipgre_tap_ops = {
97973 .kind = "gretap",
97974 .maxtype = IFLA_GRE_MAX,
97975 .policy = ipgre_policy,
97976diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
97977index ddf32a6..3fdeea9 100644
97978--- a/net/ipv4/ip_sockglue.c
97979+++ b/net/ipv4/ip_sockglue.c
97980@@ -1172,7 +1172,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
97981 len = min_t(unsigned int, len, opt->optlen);
97982 if (put_user(len, optlen))
97983 return -EFAULT;
97984- if (copy_to_user(optval, opt->__data, len))
97985+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
97986+ copy_to_user(optval, opt->__data, len))
97987 return -EFAULT;
97988 return 0;
97989 }
97990@@ -1303,7 +1304,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
97991 if (sk->sk_type != SOCK_STREAM)
97992 return -ENOPROTOOPT;
97993
97994- msg.msg_control = optval;
97995+ msg.msg_control = (void __force_kernel *)optval;
97996 msg.msg_controllen = len;
97997 msg.msg_flags = flags;
97998
97999diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
98000index 52b802a..b725179 100644
98001--- a/net/ipv4/ip_vti.c
98002+++ b/net/ipv4/ip_vti.c
98003@@ -44,7 +44,7 @@
98004 #include <net/net_namespace.h>
98005 #include <net/netns/generic.h>
98006
98007-static struct rtnl_link_ops vti_link_ops __read_mostly;
98008+static struct rtnl_link_ops vti_link_ops;
98009
98010 static int vti_net_id __read_mostly;
98011 static int vti_tunnel_init(struct net_device *dev);
98012@@ -360,7 +360,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
98013 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
98014 };
98015
98016-static struct rtnl_link_ops vti_link_ops __read_mostly = {
98017+static struct rtnl_link_ops vti_link_ops = {
98018 .kind = "vti",
98019 .maxtype = IFLA_VTI_MAX,
98020 .policy = vti_policy,
98021diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
98022index efa1138..20dbba0 100644
98023--- a/net/ipv4/ipconfig.c
98024+++ b/net/ipv4/ipconfig.c
98025@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
98026
98027 mm_segment_t oldfs = get_fs();
98028 set_fs(get_ds());
98029- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
98030+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
98031 set_fs(oldfs);
98032 return res;
98033 }
98034@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
98035
98036 mm_segment_t oldfs = get_fs();
98037 set_fs(get_ds());
98038- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
98039+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
98040 set_fs(oldfs);
98041 return res;
98042 }
98043@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
98044
98045 mm_segment_t oldfs = get_fs();
98046 set_fs(get_ds());
98047- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
98048+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
98049 set_fs(oldfs);
98050 return res;
98051 }
98052diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
98053index fe3e9f7..4956990 100644
98054--- a/net/ipv4/ipip.c
98055+++ b/net/ipv4/ipip.c
98056@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
98057 static int ipip_net_id __read_mostly;
98058
98059 static int ipip_tunnel_init(struct net_device *dev);
98060-static struct rtnl_link_ops ipip_link_ops __read_mostly;
98061+static struct rtnl_link_ops ipip_link_ops;
98062
98063 static int ipip_err(struct sk_buff *skb, u32 info)
98064 {
98065@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
98066 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
98067 };
98068
98069-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
98070+static struct rtnl_link_ops ipip_link_ops = {
98071 .kind = "ipip",
98072 .maxtype = IFLA_IPTUN_MAX,
98073 .policy = ipip_policy,
98074diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
98075index 59da7cd..e318de1 100644
98076--- a/net/ipv4/netfilter/arp_tables.c
98077+++ b/net/ipv4/netfilter/arp_tables.c
98078@@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
98079 #endif
98080
98081 static int get_info(struct net *net, void __user *user,
98082- const int *len, int compat)
98083+ int len, int compat)
98084 {
98085 char name[XT_TABLE_MAXNAMELEN];
98086 struct xt_table *t;
98087 int ret;
98088
98089- if (*len != sizeof(struct arpt_getinfo)) {
98090- duprintf("length %u != %Zu\n", *len,
98091+ if (len != sizeof(struct arpt_getinfo)) {
98092+ duprintf("length %u != %Zu\n", len,
98093 sizeof(struct arpt_getinfo));
98094 return -EINVAL;
98095 }
98096@@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
98097 info.size = private->size;
98098 strcpy(info.name, name);
98099
98100- if (copy_to_user(user, &info, *len) != 0)
98101+ if (copy_to_user(user, &info, len) != 0)
98102 ret = -EFAULT;
98103 else
98104 ret = 0;
98105@@ -1688,7 +1688,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
98106
98107 switch (cmd) {
98108 case ARPT_SO_GET_INFO:
98109- ret = get_info(sock_net(sk), user, len, 1);
98110+ ret = get_info(sock_net(sk), user, *len, 1);
98111 break;
98112 case ARPT_SO_GET_ENTRIES:
98113 ret = compat_get_entries(sock_net(sk), user, len);
98114@@ -1733,7 +1733,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
98115
98116 switch (cmd) {
98117 case ARPT_SO_GET_INFO:
98118- ret = get_info(sock_net(sk), user, len, 0);
98119+ ret = get_info(sock_net(sk), user, *len, 0);
98120 break;
98121
98122 case ARPT_SO_GET_ENTRIES:
98123diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
98124index 718dfbd..cef4152 100644
98125--- a/net/ipv4/netfilter/ip_tables.c
98126+++ b/net/ipv4/netfilter/ip_tables.c
98127@@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
98128 #endif
98129
98130 static int get_info(struct net *net, void __user *user,
98131- const int *len, int compat)
98132+ int len, int compat)
98133 {
98134 char name[XT_TABLE_MAXNAMELEN];
98135 struct xt_table *t;
98136 int ret;
98137
98138- if (*len != sizeof(struct ipt_getinfo)) {
98139- duprintf("length %u != %zu\n", *len,
98140+ if (len != sizeof(struct ipt_getinfo)) {
98141+ duprintf("length %u != %zu\n", len,
98142 sizeof(struct ipt_getinfo));
98143 return -EINVAL;
98144 }
98145@@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
98146 info.size = private->size;
98147 strcpy(info.name, name);
98148
98149- if (copy_to_user(user, &info, *len) != 0)
98150+ if (copy_to_user(user, &info, len) != 0)
98151 ret = -EFAULT;
98152 else
98153 ret = 0;
98154@@ -1971,7 +1971,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98155
98156 switch (cmd) {
98157 case IPT_SO_GET_INFO:
98158- ret = get_info(sock_net(sk), user, len, 1);
98159+ ret = get_info(sock_net(sk), user, *len, 1);
98160 break;
98161 case IPT_SO_GET_ENTRIES:
98162 ret = compat_get_entries(sock_net(sk), user, len);
98163@@ -2018,7 +2018,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98164
98165 switch (cmd) {
98166 case IPT_SO_GET_INFO:
98167- ret = get_info(sock_net(sk), user, len, 0);
98168+ ret = get_info(sock_net(sk), user, *len, 0);
98169 break;
98170
98171 case IPT_SO_GET_ENTRIES:
98172diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
98173index 242e7f4..a084e95 100644
98174--- a/net/ipv4/ping.c
98175+++ b/net/ipv4/ping.c
98176@@ -55,7 +55,7 @@
98177
98178
98179 struct ping_table ping_table;
98180-struct pingv6_ops pingv6_ops;
98181+struct pingv6_ops *pingv6_ops;
98182 EXPORT_SYMBOL_GPL(pingv6_ops);
98183
98184 static u16 ping_port_rover;
98185@@ -334,7 +334,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
98186 return -ENODEV;
98187 }
98188 }
98189- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
98190+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
98191 scoped);
98192 rcu_read_unlock();
98193
98194@@ -542,7 +542,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
98195 }
98196 #if IS_ENABLED(CONFIG_IPV6)
98197 } else if (skb->protocol == htons(ETH_P_IPV6)) {
98198- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
98199+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
98200 #endif
98201 }
98202
98203@@ -560,7 +560,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
98204 info, (u8 *)icmph);
98205 #if IS_ENABLED(CONFIG_IPV6)
98206 } else if (family == AF_INET6) {
98207- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
98208+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
98209 info, (u8 *)icmph);
98210 #endif
98211 }
98212@@ -830,6 +830,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98213 {
98214 struct inet_sock *isk = inet_sk(sk);
98215 int family = sk->sk_family;
98216+ struct sockaddr_in *sin;
98217+ struct sockaddr_in6 *sin6;
98218 struct sk_buff *skb;
98219 int copied, err;
98220
98221@@ -839,12 +841,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98222 if (flags & MSG_OOB)
98223 goto out;
98224
98225+ if (addr_len) {
98226+ if (family == AF_INET)
98227+ *addr_len = sizeof(*sin);
98228+ else if (family == AF_INET6 && addr_len)
98229+ *addr_len = sizeof(*sin6);
98230+ }
98231+
98232 if (flags & MSG_ERRQUEUE) {
98233 if (family == AF_INET) {
98234 return ip_recv_error(sk, msg, len, addr_len);
98235 #if IS_ENABLED(CONFIG_IPV6)
98236 } else if (family == AF_INET6) {
98237- return pingv6_ops.ipv6_recv_error(sk, msg, len,
98238+ return pingv6_ops->ipv6_recv_error(sk, msg, len,
98239 addr_len);
98240 #endif
98241 }
98242@@ -876,7 +885,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98243 sin->sin_port = 0 /* skb->h.uh->source */;
98244 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98245 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
98246- *addr_len = sizeof(*sin);
98247 }
98248
98249 if (isk->cmsg_flags)
98250@@ -899,11 +907,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98251 sin6->sin6_scope_id =
98252 ipv6_iface_scope_id(&sin6->sin6_addr,
98253 IP6CB(skb)->iif);
98254- *addr_len = sizeof(*sin6);
98255 }
98256
98257 if (inet6_sk(sk)->rxopt.all)
98258- pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
98259+ pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
98260 #endif
98261 } else {
98262 BUG();
98263@@ -1093,7 +1100,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
98264 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
98265 0, sock_i_ino(sp),
98266 atomic_read(&sp->sk_refcnt), sp,
98267- atomic_read(&sp->sk_drops));
98268+ atomic_read_unchecked(&sp->sk_drops));
98269 }
98270
98271 static int ping_v4_seq_show(struct seq_file *seq, void *v)
98272diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
98273index 23c3e5b..cdb8b36 100644
98274--- a/net/ipv4/raw.c
98275+++ b/net/ipv4/raw.c
98276@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
98277 int raw_rcv(struct sock *sk, struct sk_buff *skb)
98278 {
98279 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
98280- atomic_inc(&sk->sk_drops);
98281+ atomic_inc_unchecked(&sk->sk_drops);
98282 kfree_skb(skb);
98283 return NET_RX_DROP;
98284 }
98285@@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98286 if (flags & MSG_OOB)
98287 goto out;
98288
98289+ if (addr_len)
98290+ *addr_len = sizeof(*sin);
98291+
98292 if (flags & MSG_ERRQUEUE) {
98293 err = ip_recv_error(sk, msg, len, addr_len);
98294 goto out;
98295@@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98296 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98297 sin->sin_port = 0;
98298 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
98299- *addr_len = sizeof(*sin);
98300 }
98301 if (inet->cmsg_flags)
98302 ip_cmsg_recv(msg, skb);
98303@@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
98304
98305 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
98306 {
98307+ struct icmp_filter filter;
98308+
98309 if (optlen > sizeof(struct icmp_filter))
98310 optlen = sizeof(struct icmp_filter);
98311- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
98312+ if (copy_from_user(&filter, optval, optlen))
98313 return -EFAULT;
98314+ raw_sk(sk)->filter = filter;
98315 return 0;
98316 }
98317
98318 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
98319 {
98320 int len, ret = -EFAULT;
98321+ struct icmp_filter filter;
98322
98323 if (get_user(len, optlen))
98324 goto out;
98325@@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
98326 if (len > sizeof(struct icmp_filter))
98327 len = sizeof(struct icmp_filter);
98328 ret = -EFAULT;
98329- if (put_user(len, optlen) ||
98330- copy_to_user(optval, &raw_sk(sk)->filter, len))
98331+ filter = raw_sk(sk)->filter;
98332+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
98333 goto out;
98334 ret = 0;
98335 out: return ret;
98336@@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
98337 0, 0L, 0,
98338 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
98339 0, sock_i_ino(sp),
98340- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
98341+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
98342 }
98343
98344 static int raw_seq_show(struct seq_file *seq, void *v)
98345diff --git a/net/ipv4/route.c b/net/ipv4/route.c
98346index e611651f..0c17263 100644
98347--- a/net/ipv4/route.c
98348+++ b/net/ipv4/route.c
98349@@ -2621,34 +2621,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
98350 .maxlen = sizeof(int),
98351 .mode = 0200,
98352 .proc_handler = ipv4_sysctl_rtcache_flush,
98353+ .extra1 = &init_net,
98354 },
98355 { },
98356 };
98357
98358 static __net_init int sysctl_route_net_init(struct net *net)
98359 {
98360- struct ctl_table *tbl;
98361+ ctl_table_no_const *tbl = NULL;
98362
98363- tbl = ipv4_route_flush_table;
98364 if (!net_eq(net, &init_net)) {
98365- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
98366+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
98367 if (tbl == NULL)
98368 goto err_dup;
98369
98370 /* Don't export sysctls to unprivileged users */
98371 if (net->user_ns != &init_user_ns)
98372 tbl[0].procname = NULL;
98373- }
98374- tbl[0].extra1 = net;
98375+ tbl[0].extra1 = net;
98376+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
98377+ } else
98378+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
98379
98380- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
98381 if (net->ipv4.route_hdr == NULL)
98382 goto err_reg;
98383 return 0;
98384
98385 err_reg:
98386- if (tbl != ipv4_route_flush_table)
98387- kfree(tbl);
98388+ kfree(tbl);
98389 err_dup:
98390 return -ENOMEM;
98391 }
98392@@ -2671,8 +2671,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
98393
98394 static __net_init int rt_genid_init(struct net *net)
98395 {
98396- atomic_set(&net->ipv4.rt_genid, 0);
98397- atomic_set(&net->fnhe_genid, 0);
98398+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
98399+ atomic_set_unchecked(&net->fnhe_genid, 0);
98400 get_random_bytes(&net->ipv4.dev_addr_genid,
98401 sizeof(net->ipv4.dev_addr_genid));
98402 return 0;
98403diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
98404index 3d69ec8..57207b4 100644
98405--- a/net/ipv4/sysctl_net_ipv4.c
98406+++ b/net/ipv4/sysctl_net_ipv4.c
98407@@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
98408 container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
98409 int ret;
98410 int range[2];
98411- struct ctl_table tmp = {
98412+ ctl_table_no_const tmp = {
98413 .data = &range,
98414 .maxlen = sizeof(range),
98415 .mode = table->mode,
98416@@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
98417 int ret;
98418 gid_t urange[2];
98419 kgid_t low, high;
98420- struct ctl_table tmp = {
98421+ ctl_table_no_const tmp = {
98422 .data = &urange,
98423 .maxlen = sizeof(urange),
98424 .mode = table->mode,
98425@@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
98426 void __user *buffer, size_t *lenp, loff_t *ppos)
98427 {
98428 char val[TCP_CA_NAME_MAX];
98429- struct ctl_table tbl = {
98430+ ctl_table_no_const tbl = {
98431 .data = val,
98432 .maxlen = TCP_CA_NAME_MAX,
98433 };
98434@@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
98435 void __user *buffer, size_t *lenp,
98436 loff_t *ppos)
98437 {
98438- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
98439+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
98440 int ret;
98441
98442 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
98443@@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
98444 void __user *buffer, size_t *lenp,
98445 loff_t *ppos)
98446 {
98447- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
98448+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
98449 int ret;
98450
98451 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
98452@@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
98453 void __user *buffer, size_t *lenp,
98454 loff_t *ppos)
98455 {
98456- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
98457+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
98458 struct tcp_fastopen_context *ctxt;
98459 int ret;
98460 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
98461@@ -445,7 +445,7 @@ static struct ctl_table ipv4_table[] = {
98462 },
98463 {
98464 .procname = "ip_local_reserved_ports",
98465- .data = NULL, /* initialized in sysctl_ipv4_init */
98466+ .data = sysctl_local_reserved_ports,
98467 .maxlen = 65536,
98468 .mode = 0644,
98469 .proc_handler = proc_do_large_bitmap,
98470@@ -827,13 +827,12 @@ static struct ctl_table ipv4_net_table[] = {
98471
98472 static __net_init int ipv4_sysctl_init_net(struct net *net)
98473 {
98474- struct ctl_table *table;
98475+ ctl_table_no_const *table = NULL;
98476
98477- table = ipv4_net_table;
98478 if (!net_eq(net, &init_net)) {
98479 int i;
98480
98481- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
98482+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
98483 if (table == NULL)
98484 goto err_alloc;
98485
98486@@ -856,15 +855,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
98487 net->ipv4.sysctl_local_ports.range[0] = 32768;
98488 net->ipv4.sysctl_local_ports.range[1] = 61000;
98489
98490- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
98491+ if (!net_eq(net, &init_net))
98492+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
98493+ else
98494+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
98495 if (net->ipv4.ipv4_hdr == NULL)
98496 goto err_reg;
98497
98498 return 0;
98499
98500 err_reg:
98501- if (!net_eq(net, &init_net))
98502- kfree(table);
98503+ kfree(table);
98504 err_alloc:
98505 return -ENOMEM;
98506 }
98507@@ -886,16 +887,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
98508 static __init int sysctl_ipv4_init(void)
98509 {
98510 struct ctl_table_header *hdr;
98511- struct ctl_table *i;
98512-
98513- for (i = ipv4_table; i->procname; i++) {
98514- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
98515- i->data = sysctl_local_reserved_ports;
98516- break;
98517- }
98518- }
98519- if (!i->procname)
98520- return -EINVAL;
98521
98522 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
98523 if (hdr == NULL)
98524diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
98525index c53b7f3..a89aadd 100644
98526--- a/net/ipv4/tcp_input.c
98527+++ b/net/ipv4/tcp_input.c
98528@@ -759,7 +759,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
98529 * without any lock. We want to make sure compiler wont store
98530 * intermediate values in this location.
98531 */
98532- ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
98533+ ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
98534 sk->sk_max_pacing_rate);
98535 }
98536
98537@@ -4482,7 +4482,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
98538 * simplifies code)
98539 */
98540 static void
98541-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
98542+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
98543 struct sk_buff *head, struct sk_buff *tail,
98544 u32 start, u32 end)
98545 {
98546@@ -5559,6 +5559,7 @@ discard:
98547 tcp_paws_reject(&tp->rx_opt, 0))
98548 goto discard_and_undo;
98549
98550+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
98551 if (th->syn) {
98552 /* We see SYN without ACK. It is attempt of
98553 * simultaneous connect with crossed SYNs.
98554@@ -5609,6 +5610,7 @@ discard:
98555 goto discard;
98556 #endif
98557 }
98558+#endif
98559 /* "fifth, if neither of the SYN or RST bits is set then
98560 * drop the segment and return."
98561 */
98562@@ -5655,7 +5657,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
98563 goto discard;
98564
98565 if (th->syn) {
98566- if (th->fin)
98567+ if (th->fin || th->urg || th->psh)
98568 goto discard;
98569 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
98570 return 1;
98571diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
98572index 0672139..cacc17d 100644
98573--- a/net/ipv4/tcp_ipv4.c
98574+++ b/net/ipv4/tcp_ipv4.c
98575@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
98576 EXPORT_SYMBOL(sysctl_tcp_low_latency);
98577
98578
98579+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98580+extern int grsec_enable_blackhole;
98581+#endif
98582+
98583 #ifdef CONFIG_TCP_MD5SIG
98584 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
98585 __be32 daddr, __be32 saddr, const struct tcphdr *th);
98586@@ -1830,6 +1834,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
98587 return 0;
98588
98589 reset:
98590+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98591+ if (!grsec_enable_blackhole)
98592+#endif
98593 tcp_v4_send_reset(rsk, skb);
98594 discard:
98595 kfree_skb(skb);
98596@@ -1975,12 +1982,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
98597 TCP_SKB_CB(skb)->sacked = 0;
98598
98599 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
98600- if (!sk)
98601+ if (!sk) {
98602+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98603+ ret = 1;
98604+#endif
98605 goto no_tcp_socket;
98606-
98607+ }
98608 process:
98609- if (sk->sk_state == TCP_TIME_WAIT)
98610+ if (sk->sk_state == TCP_TIME_WAIT) {
98611+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98612+ ret = 2;
98613+#endif
98614 goto do_time_wait;
98615+ }
98616
98617 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
98618 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
98619@@ -2034,6 +2048,10 @@ csum_error:
98620 bad_packet:
98621 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
98622 } else {
98623+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98624+ if (!grsec_enable_blackhole || (ret == 1 &&
98625+ (skb->dev->flags & IFF_LOOPBACK)))
98626+#endif
98627 tcp_v4_send_reset(NULL, skb);
98628 }
98629
98630diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
98631index 97b6841..0893357 100644
98632--- a/net/ipv4/tcp_minisocks.c
98633+++ b/net/ipv4/tcp_minisocks.c
98634@@ -27,6 +27,10 @@
98635 #include <net/inet_common.h>
98636 #include <net/xfrm.h>
98637
98638+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98639+extern int grsec_enable_blackhole;
98640+#endif
98641+
98642 int sysctl_tcp_syncookies __read_mostly = 1;
98643 EXPORT_SYMBOL(sysctl_tcp_syncookies);
98644
98645@@ -708,7 +712,10 @@ embryonic_reset:
98646 * avoid becoming vulnerable to outside attack aiming at
98647 * resetting legit local connections.
98648 */
98649- req->rsk_ops->send_reset(sk, skb);
98650+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98651+ if (!grsec_enable_blackhole)
98652+#endif
98653+ req->rsk_ops->send_reset(sk, skb);
98654 } else if (fastopen) { /* received a valid RST pkt */
98655 reqsk_fastopen_remove(sk, req, true);
98656 tcp_reset(sk);
98657diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
98658index 8b97d71..9d7ccf5 100644
98659--- a/net/ipv4/tcp_probe.c
98660+++ b/net/ipv4/tcp_probe.c
98661@@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
98662 if (cnt + width >= len)
98663 break;
98664
98665- if (copy_to_user(buf + cnt, tbuf, width))
98666+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
98667 return -EFAULT;
98668 cnt += width;
98669 }
98670diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
98671index 64f0354..a81b39d 100644
98672--- a/net/ipv4/tcp_timer.c
98673+++ b/net/ipv4/tcp_timer.c
98674@@ -22,6 +22,10 @@
98675 #include <linux/gfp.h>
98676 #include <net/tcp.h>
98677
98678+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98679+extern int grsec_lastack_retries;
98680+#endif
98681+
98682 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
98683 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
98684 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
98685@@ -189,6 +193,13 @@ static int tcp_write_timeout(struct sock *sk)
98686 }
98687 }
98688
98689+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98690+ if ((sk->sk_state == TCP_LAST_ACK) &&
98691+ (grsec_lastack_retries > 0) &&
98692+ (grsec_lastack_retries < retry_until))
98693+ retry_until = grsec_lastack_retries;
98694+#endif
98695+
98696 if (retransmits_timed_out(sk, retry_until,
98697 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
98698 /* Has it gone just too far? */
98699diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
98700index a7e4729..2758946 100644
98701--- a/net/ipv4/udp.c
98702+++ b/net/ipv4/udp.c
98703@@ -87,6 +87,7 @@
98704 #include <linux/types.h>
98705 #include <linux/fcntl.h>
98706 #include <linux/module.h>
98707+#include <linux/security.h>
98708 #include <linux/socket.h>
98709 #include <linux/sockios.h>
98710 #include <linux/igmp.h>
98711@@ -113,6 +114,10 @@
98712 #include <net/busy_poll.h>
98713 #include "udp_impl.h"
98714
98715+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98716+extern int grsec_enable_blackhole;
98717+#endif
98718+
98719 struct udp_table udp_table __read_mostly;
98720 EXPORT_SYMBOL(udp_table);
98721
98722@@ -615,6 +620,9 @@ found:
98723 return s;
98724 }
98725
98726+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
98727+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
98728+
98729 /*
98730 * This routine is called by the ICMP module when it gets some
98731 * sort of error condition. If err < 0 then the socket should
98732@@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98733 dport = usin->sin_port;
98734 if (dport == 0)
98735 return -EINVAL;
98736+
98737+ err = gr_search_udp_sendmsg(sk, usin);
98738+ if (err)
98739+ return err;
98740 } else {
98741 if (sk->sk_state != TCP_ESTABLISHED)
98742 return -EDESTADDRREQ;
98743+
98744+ err = gr_search_udp_sendmsg(sk, NULL);
98745+ if (err)
98746+ return err;
98747+
98748 daddr = inet->inet_daddr;
98749 dport = inet->inet_dport;
98750 /* Open fast path for connected socket.
98751@@ -1163,7 +1180,7 @@ static unsigned int first_packet_length(struct sock *sk)
98752 IS_UDPLITE(sk));
98753 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
98754 IS_UDPLITE(sk));
98755- atomic_inc(&sk->sk_drops);
98756+ atomic_inc_unchecked(&sk->sk_drops);
98757 __skb_unlink(skb, rcvq);
98758 __skb_queue_tail(&list_kill, skb);
98759 }
98760@@ -1234,6 +1251,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98761 int is_udplite = IS_UDPLITE(sk);
98762 bool slow;
98763
98764+ /*
98765+ * Check any passed addresses
98766+ */
98767+ if (addr_len)
98768+ *addr_len = sizeof(*sin);
98769+
98770 if (flags & MSG_ERRQUEUE)
98771 return ip_recv_error(sk, msg, len, addr_len);
98772
98773@@ -1243,6 +1266,10 @@ try_again:
98774 if (!skb)
98775 goto out;
98776
98777+ err = gr_search_udp_recvmsg(sk, skb);
98778+ if (err)
98779+ goto out_free;
98780+
98781 ulen = skb->len - sizeof(struct udphdr);
98782 copied = len;
98783 if (copied > ulen)
98784@@ -1276,7 +1303,7 @@ try_again:
98785 if (unlikely(err)) {
98786 trace_kfree_skb(skb, udp_recvmsg);
98787 if (!peeked) {
98788- atomic_inc(&sk->sk_drops);
98789+ atomic_inc_unchecked(&sk->sk_drops);
98790 UDP_INC_STATS_USER(sock_net(sk),
98791 UDP_MIB_INERRORS, is_udplite);
98792 }
98793@@ -1295,7 +1322,6 @@ try_again:
98794 sin->sin_port = udp_hdr(skb)->source;
98795 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98796 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
98797- *addr_len = sizeof(*sin);
98798 }
98799 if (inet->cmsg_flags)
98800 ip_cmsg_recv(msg, skb);
98801@@ -1566,7 +1592,7 @@ csum_error:
98802 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
98803 drop:
98804 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
98805- atomic_inc(&sk->sk_drops);
98806+ atomic_inc_unchecked(&sk->sk_drops);
98807 kfree_skb(skb);
98808 return -1;
98809 }
98810@@ -1585,7 +1611,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
98811 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
98812
98813 if (!skb1) {
98814- atomic_inc(&sk->sk_drops);
98815+ atomic_inc_unchecked(&sk->sk_drops);
98816 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
98817 IS_UDPLITE(sk));
98818 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
98819@@ -1786,6 +1812,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
98820 goto csum_error;
98821
98822 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
98823+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98824+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
98825+#endif
98826 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
98827
98828 /*
98829@@ -2350,7 +2379,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
98830 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
98831 0, sock_i_ino(sp),
98832 atomic_read(&sp->sk_refcnt), sp,
98833- atomic_read(&sp->sk_drops));
98834+ atomic_read_unchecked(&sp->sk_drops));
98835 }
98836
98837 int udp4_seq_show(struct seq_file *seq, void *v)
98838diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
98839index e1a6393..f634ce5 100644
98840--- a/net/ipv4/xfrm4_policy.c
98841+++ b/net/ipv4/xfrm4_policy.c
98842@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
98843 fl4->flowi4_tos = iph->tos;
98844 }
98845
98846-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
98847+static int xfrm4_garbage_collect(struct dst_ops *ops)
98848 {
98849 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
98850
98851- xfrm4_policy_afinfo.garbage_collect(net);
98852+ xfrm_garbage_collect_deferred(net);
98853 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
98854 }
98855
98856@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
98857
98858 static int __net_init xfrm4_net_init(struct net *net)
98859 {
98860- struct ctl_table *table;
98861+ ctl_table_no_const *table = NULL;
98862 struct ctl_table_header *hdr;
98863
98864- table = xfrm4_policy_table;
98865 if (!net_eq(net, &init_net)) {
98866- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
98867+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
98868 if (!table)
98869 goto err_alloc;
98870
98871 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
98872- }
98873-
98874- hdr = register_net_sysctl(net, "net/ipv4", table);
98875+ hdr = register_net_sysctl(net, "net/ipv4", table);
98876+ } else
98877+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
98878 if (!hdr)
98879 goto err_reg;
98880
98881@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
98882 return 0;
98883
98884 err_reg:
98885- if (!net_eq(net, &init_net))
98886- kfree(table);
98887+ kfree(table);
98888 err_alloc:
98889 return -ENOMEM;
98890 }
98891diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
98892index 9c05d77..9cfa714 100644
98893--- a/net/ipv6/addrconf.c
98894+++ b/net/ipv6/addrconf.c
98895@@ -589,7 +589,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
98896 idx = 0;
98897 head = &net->dev_index_head[h];
98898 rcu_read_lock();
98899- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
98900+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
98901 net->dev_base_seq;
98902 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98903 if (idx < s_idx)
98904@@ -2334,7 +2334,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
98905 p.iph.ihl = 5;
98906 p.iph.protocol = IPPROTO_IPV6;
98907 p.iph.ttl = 64;
98908- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
98909+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
98910
98911 if (ops->ndo_do_ioctl) {
98912 mm_segment_t oldfs = get_fs();
98913@@ -3964,7 +3964,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
98914 s_ip_idx = ip_idx = cb->args[2];
98915
98916 rcu_read_lock();
98917- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
98918+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
98919 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
98920 idx = 0;
98921 head = &net->dev_index_head[h];
98922@@ -4571,7 +4571,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
98923 dst_free(&ifp->rt->dst);
98924 break;
98925 }
98926- atomic_inc(&net->ipv6.dev_addr_genid);
98927+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
98928 rt_genid_bump_ipv6(net);
98929 }
98930
98931@@ -4592,7 +4592,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
98932 int *valp = ctl->data;
98933 int val = *valp;
98934 loff_t pos = *ppos;
98935- struct ctl_table lctl;
98936+ ctl_table_no_const lctl;
98937 int ret;
98938
98939 /*
98940@@ -4677,7 +4677,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
98941 int *valp = ctl->data;
98942 int val = *valp;
98943 loff_t pos = *ppos;
98944- struct ctl_table lctl;
98945+ ctl_table_no_const lctl;
98946 int ret;
98947
98948 /*
98949diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
98950index 4fbdb70..f6411f2 100644
98951--- a/net/ipv6/af_inet6.c
98952+++ b/net/ipv6/af_inet6.c
98953@@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
98954
98955 net->ipv6.sysctl.bindv6only = 0;
98956 net->ipv6.sysctl.icmpv6_time = 1*HZ;
98957- atomic_set(&net->ipv6.rt_genid, 0);
98958+ atomic_set_unchecked(&net->ipv6.rt_genid, 0);
98959
98960 err = ipv6_init_mibs(net);
98961 if (err)
98962diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
98963index 93b1aa3..e902855 100644
98964--- a/net/ipv6/datagram.c
98965+++ b/net/ipv6/datagram.c
98966@@ -906,5 +906,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
98967 0,
98968 sock_i_ino(sp),
98969 atomic_read(&sp->sk_refcnt), sp,
98970- atomic_read(&sp->sk_drops));
98971+ atomic_read_unchecked(&sp->sk_drops));
98972 }
98973diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
98974index eef8d94..cfa1852 100644
98975--- a/net/ipv6/icmp.c
98976+++ b/net/ipv6/icmp.c
98977@@ -997,7 +997,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
98978
98979 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
98980 {
98981- struct ctl_table *table;
98982+ ctl_table_no_const *table;
98983
98984 table = kmemdup(ipv6_icmp_table_template,
98985 sizeof(ipv6_icmp_table_template),
98986diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
98987index 8acb286..840dd06 100644
98988--- a/net/ipv6/ip6_gre.c
98989+++ b/net/ipv6/ip6_gre.c
98990@@ -74,7 +74,7 @@ struct ip6gre_net {
98991 struct net_device *fb_tunnel_dev;
98992 };
98993
98994-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
98995+static struct rtnl_link_ops ip6gre_link_ops;
98996 static int ip6gre_tunnel_init(struct net_device *dev);
98997 static void ip6gre_tunnel_setup(struct net_device *dev);
98998 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
98999@@ -1294,7 +1294,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
99000 }
99001
99002
99003-static struct inet6_protocol ip6gre_protocol __read_mostly = {
99004+static struct inet6_protocol ip6gre_protocol = {
99005 .handler = ip6gre_rcv,
99006 .err_handler = ip6gre_err,
99007 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
99008@@ -1637,7 +1637,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
99009 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
99010 };
99011
99012-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
99013+static struct rtnl_link_ops ip6gre_link_ops = {
99014 .kind = "ip6gre",
99015 .maxtype = IFLA_GRE_MAX,
99016 .policy = ip6gre_policy,
99017@@ -1650,7 +1650,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
99018 .fill_info = ip6gre_fill_info,
99019 };
99020
99021-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
99022+static struct rtnl_link_ops ip6gre_tap_ops = {
99023 .kind = "ip6gretap",
99024 .maxtype = IFLA_GRE_MAX,
99025 .policy = ip6gre_policy,
99026diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
99027index 7881965..9cf62c4 100644
99028--- a/net/ipv6/ip6_tunnel.c
99029+++ b/net/ipv6/ip6_tunnel.c
99030@@ -89,7 +89,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
99031
99032 static int ip6_tnl_dev_init(struct net_device *dev);
99033 static void ip6_tnl_dev_setup(struct net_device *dev);
99034-static struct rtnl_link_ops ip6_link_ops __read_mostly;
99035+static struct rtnl_link_ops ip6_link_ops;
99036
99037 static int ip6_tnl_net_id __read_mostly;
99038 struct ip6_tnl_net {
99039@@ -1717,7 +1717,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
99040 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
99041 };
99042
99043-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
99044+static struct rtnl_link_ops ip6_link_ops = {
99045 .kind = "ip6tnl",
99046 .maxtype = IFLA_IPTUN_MAX,
99047 .policy = ip6_tnl_policy,
99048diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
99049index 7b42d5e..1eff693 100644
99050--- a/net/ipv6/ip6_vti.c
99051+++ b/net/ipv6/ip6_vti.c
99052@@ -63,7 +63,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
99053
99054 static int vti6_dev_init(struct net_device *dev);
99055 static void vti6_dev_setup(struct net_device *dev);
99056-static struct rtnl_link_ops vti6_link_ops __read_mostly;
99057+static struct rtnl_link_ops vti6_link_ops;
99058
99059 static int vti6_net_id __read_mostly;
99060 struct vti6_net {
99061@@ -902,7 +902,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
99062 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
99063 };
99064
99065-static struct rtnl_link_ops vti6_link_ops __read_mostly = {
99066+static struct rtnl_link_ops vti6_link_ops = {
99067 .kind = "vti6",
99068 .maxtype = IFLA_VTI_MAX,
99069 .policy = vti6_policy,
99070diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
99071index 1c6ce31..299e566 100644
99072--- a/net/ipv6/ipv6_sockglue.c
99073+++ b/net/ipv6/ipv6_sockglue.c
99074@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
99075 if (sk->sk_type != SOCK_STREAM)
99076 return -ENOPROTOOPT;
99077
99078- msg.msg_control = optval;
99079+ msg.msg_control = (void __force_kernel *)optval;
99080 msg.msg_controllen = len;
99081 msg.msg_flags = flags;
99082
99083diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
99084index 710238f..0fd1816 100644
99085--- a/net/ipv6/netfilter/ip6_tables.c
99086+++ b/net/ipv6/netfilter/ip6_tables.c
99087@@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
99088 #endif
99089
99090 static int get_info(struct net *net, void __user *user,
99091- const int *len, int compat)
99092+ int len, int compat)
99093 {
99094 char name[XT_TABLE_MAXNAMELEN];
99095 struct xt_table *t;
99096 int ret;
99097
99098- if (*len != sizeof(struct ip6t_getinfo)) {
99099- duprintf("length %u != %zu\n", *len,
99100+ if (len != sizeof(struct ip6t_getinfo)) {
99101+ duprintf("length %u != %zu\n", len,
99102 sizeof(struct ip6t_getinfo));
99103 return -EINVAL;
99104 }
99105@@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
99106 info.size = private->size;
99107 strcpy(info.name, name);
99108
99109- if (copy_to_user(user, &info, *len) != 0)
99110+ if (copy_to_user(user, &info, len) != 0)
99111 ret = -EFAULT;
99112 else
99113 ret = 0;
99114@@ -1981,7 +1981,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99115
99116 switch (cmd) {
99117 case IP6T_SO_GET_INFO:
99118- ret = get_info(sock_net(sk), user, len, 1);
99119+ ret = get_info(sock_net(sk), user, *len, 1);
99120 break;
99121 case IP6T_SO_GET_ENTRIES:
99122 ret = compat_get_entries(sock_net(sk), user, len);
99123@@ -2028,7 +2028,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99124
99125 switch (cmd) {
99126 case IP6T_SO_GET_INFO:
99127- ret = get_info(sock_net(sk), user, len, 0);
99128+ ret = get_info(sock_net(sk), user, *len, 0);
99129 break;
99130
99131 case IP6T_SO_GET_ENTRIES:
99132diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
99133index 767ab8d..c5ec70a 100644
99134--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
99135+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
99136@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
99137
99138 static int nf_ct_frag6_sysctl_register(struct net *net)
99139 {
99140- struct ctl_table *table;
99141+ ctl_table_no_const *table = NULL;
99142 struct ctl_table_header *hdr;
99143
99144- table = nf_ct_frag6_sysctl_table;
99145 if (!net_eq(net, &init_net)) {
99146- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
99147+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
99148 GFP_KERNEL);
99149 if (table == NULL)
99150 goto err_alloc;
99151@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
99152 table[0].data = &net->nf_frag.frags.timeout;
99153 table[1].data = &net->nf_frag.frags.low_thresh;
99154 table[2].data = &net->nf_frag.frags.high_thresh;
99155- }
99156-
99157- hdr = register_net_sysctl(net, "net/netfilter", table);
99158+ hdr = register_net_sysctl(net, "net/netfilter", table);
99159+ } else
99160+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
99161 if (hdr == NULL)
99162 goto err_reg;
99163
99164@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
99165 return 0;
99166
99167 err_reg:
99168- if (!net_eq(net, &init_net))
99169- kfree(table);
99170+ kfree(table);
99171 err_alloc:
99172 return -ENOMEM;
99173 }
99174diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
99175index 827f795..7e28e82 100644
99176--- a/net/ipv6/output_core.c
99177+++ b/net/ipv6/output_core.c
99178@@ -9,8 +9,8 @@
99179
99180 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
99181 {
99182- static atomic_t ipv6_fragmentation_id;
99183- int old, new;
99184+ static atomic_unchecked_t ipv6_fragmentation_id;
99185+ int id;
99186
99187 #if IS_ENABLED(CONFIG_IPV6)
99188 if (rt && !(rt->dst.flags & DST_NOPEER)) {
99189@@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
99190 }
99191 }
99192 #endif
99193- do {
99194- old = atomic_read(&ipv6_fragmentation_id);
99195- new = old + 1;
99196- if (!new)
99197- new = 1;
99198- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
99199- fhdr->identification = htonl(new);
99200+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
99201+ if (!id)
99202+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
99203+ fhdr->identification = htonl(id);
99204 }
99205 EXPORT_SYMBOL(ipv6_select_ident);
99206
99207diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
99208index a83243c..a1ca589 100644
99209--- a/net/ipv6/ping.c
99210+++ b/net/ipv6/ping.c
99211@@ -246,6 +246,22 @@ static struct pernet_operations ping_v6_net_ops = {
99212 };
99213 #endif
99214
99215+static struct pingv6_ops real_pingv6_ops = {
99216+ .ipv6_recv_error = ipv6_recv_error,
99217+ .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
99218+ .icmpv6_err_convert = icmpv6_err_convert,
99219+ .ipv6_icmp_error = ipv6_icmp_error,
99220+ .ipv6_chk_addr = ipv6_chk_addr,
99221+};
99222+
99223+static struct pingv6_ops dummy_pingv6_ops = {
99224+ .ipv6_recv_error = dummy_ipv6_recv_error,
99225+ .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
99226+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
99227+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
99228+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
99229+};
99230+
99231 int __init pingv6_init(void)
99232 {
99233 #ifdef CONFIG_PROC_FS
99234@@ -253,11 +269,7 @@ int __init pingv6_init(void)
99235 if (ret)
99236 return ret;
99237 #endif
99238- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
99239- pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
99240- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
99241- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
99242- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
99243+ pingv6_ops = &real_pingv6_ops;
99244 return inet6_register_protosw(&pingv6_protosw);
99245 }
99246
99247@@ -266,11 +278,7 @@ int __init pingv6_init(void)
99248 */
99249 void pingv6_exit(void)
99250 {
99251- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
99252- pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
99253- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
99254- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
99255- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
99256+ pingv6_ops = &dummy_pingv6_ops;
99257 #ifdef CONFIG_PROC_FS
99258 unregister_pernet_subsys(&ping_v6_net_ops);
99259 #endif
99260diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
99261index b6bb87e..06cc9ed 100644
99262--- a/net/ipv6/raw.c
99263+++ b/net/ipv6/raw.c
99264@@ -384,7 +384,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
99265 {
99266 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
99267 skb_checksum_complete(skb)) {
99268- atomic_inc(&sk->sk_drops);
99269+ atomic_inc_unchecked(&sk->sk_drops);
99270 kfree_skb(skb);
99271 return NET_RX_DROP;
99272 }
99273@@ -412,7 +412,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
99274 struct raw6_sock *rp = raw6_sk(sk);
99275
99276 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
99277- atomic_inc(&sk->sk_drops);
99278+ atomic_inc_unchecked(&sk->sk_drops);
99279 kfree_skb(skb);
99280 return NET_RX_DROP;
99281 }
99282@@ -436,7 +436,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
99283
99284 if (inet->hdrincl) {
99285 if (skb_checksum_complete(skb)) {
99286- atomic_inc(&sk->sk_drops);
99287+ atomic_inc_unchecked(&sk->sk_drops);
99288 kfree_skb(skb);
99289 return NET_RX_DROP;
99290 }
99291@@ -465,6 +465,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99292 if (flags & MSG_OOB)
99293 return -EOPNOTSUPP;
99294
99295+ if (addr_len)
99296+ *addr_len=sizeof(*sin6);
99297+
99298 if (flags & MSG_ERRQUEUE)
99299 return ipv6_recv_error(sk, msg, len, addr_len);
99300
99301@@ -503,7 +506,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99302 sin6->sin6_flowinfo = 0;
99303 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
99304 IP6CB(skb)->iif);
99305- *addr_len = sizeof(*sin6);
99306 }
99307
99308 sock_recv_ts_and_drops(msg, sk, skb);
99309@@ -606,7 +608,7 @@ out:
99310 return err;
99311 }
99312
99313-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
99314+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
99315 struct flowi6 *fl6, struct dst_entry **dstp,
99316 unsigned int flags)
99317 {
99318@@ -918,12 +920,15 @@ do_confirm:
99319 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
99320 char __user *optval, int optlen)
99321 {
99322+ struct icmp6_filter filter;
99323+
99324 switch (optname) {
99325 case ICMPV6_FILTER:
99326 if (optlen > sizeof(struct icmp6_filter))
99327 optlen = sizeof(struct icmp6_filter);
99328- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
99329+ if (copy_from_user(&filter, optval, optlen))
99330 return -EFAULT;
99331+ raw6_sk(sk)->filter = filter;
99332 return 0;
99333 default:
99334 return -ENOPROTOOPT;
99335@@ -936,6 +941,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
99336 char __user *optval, int __user *optlen)
99337 {
99338 int len;
99339+ struct icmp6_filter filter;
99340
99341 switch (optname) {
99342 case ICMPV6_FILTER:
99343@@ -947,7 +953,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
99344 len = sizeof(struct icmp6_filter);
99345 if (put_user(len, optlen))
99346 return -EFAULT;
99347- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
99348+ filter = raw6_sk(sk)->filter;
99349+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
99350 return -EFAULT;
99351 return 0;
99352 default:
99353diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
99354index cc85a9b..526a133 100644
99355--- a/net/ipv6/reassembly.c
99356+++ b/net/ipv6/reassembly.c
99357@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
99358
99359 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99360 {
99361- struct ctl_table *table;
99362+ ctl_table_no_const *table = NULL;
99363 struct ctl_table_header *hdr;
99364
99365- table = ip6_frags_ns_ctl_table;
99366 if (!net_eq(net, &init_net)) {
99367- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
99368+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
99369 if (table == NULL)
99370 goto err_alloc;
99371
99372@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99373 /* Don't export sysctls to unprivileged users */
99374 if (net->user_ns != &init_user_ns)
99375 table[0].procname = NULL;
99376- }
99377+ hdr = register_net_sysctl(net, "net/ipv6", table);
99378+ } else
99379+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
99380
99381- hdr = register_net_sysctl(net, "net/ipv6", table);
99382 if (hdr == NULL)
99383 goto err_reg;
99384
99385@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99386 return 0;
99387
99388 err_reg:
99389- if (!net_eq(net, &init_net))
99390- kfree(table);
99391+ kfree(table);
99392 err_alloc:
99393 return -ENOMEM;
99394 }
99395diff --git a/net/ipv6/route.c b/net/ipv6/route.c
99396index 4b4944c..d346b14 100644
99397--- a/net/ipv6/route.c
99398+++ b/net/ipv6/route.c
99399@@ -1495,7 +1495,7 @@ int ip6_route_add(struct fib6_config *cfg)
99400 if (!table)
99401 goto out;
99402
99403- rt = ip6_dst_alloc(net, NULL, DST_NOCOUNT, table);
99404+ rt = ip6_dst_alloc(net, NULL, (cfg->fc_flags & RTF_ADDRCONF) ? 0 : DST_NOCOUNT, table);
99405
99406 if (!rt) {
99407 err = -ENOMEM;
99408@@ -2954,7 +2954,7 @@ struct ctl_table ipv6_route_table_template[] = {
99409
99410 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
99411 {
99412- struct ctl_table *table;
99413+ ctl_table_no_const *table;
99414
99415 table = kmemdup(ipv6_route_table_template,
99416 sizeof(ipv6_route_table_template),
99417diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
99418index d3005b3..b36df4a 100644
99419--- a/net/ipv6/sit.c
99420+++ b/net/ipv6/sit.c
99421@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
99422 static void ipip6_dev_free(struct net_device *dev);
99423 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
99424 __be32 *v4dst);
99425-static struct rtnl_link_ops sit_link_ops __read_mostly;
99426+static struct rtnl_link_ops sit_link_ops;
99427
99428 static int sit_net_id __read_mostly;
99429 struct sit_net {
99430@@ -1664,7 +1664,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
99431 unregister_netdevice_queue(dev, head);
99432 }
99433
99434-static struct rtnl_link_ops sit_link_ops __read_mostly = {
99435+static struct rtnl_link_ops sit_link_ops = {
99436 .kind = "sit",
99437 .maxtype = IFLA_IPTUN_MAX,
99438 .policy = ipip6_policy,
99439diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
99440index 107b2f1..72741a9 100644
99441--- a/net/ipv6/sysctl_net_ipv6.c
99442+++ b/net/ipv6/sysctl_net_ipv6.c
99443@@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
99444
99445 static int __net_init ipv6_sysctl_net_init(struct net *net)
99446 {
99447- struct ctl_table *ipv6_table;
99448+ ctl_table_no_const *ipv6_table;
99449 struct ctl_table *ipv6_route_table;
99450 struct ctl_table *ipv6_icmp_table;
99451 int err;
99452diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
99453index f67033b..6f974fc 100644
99454--- a/net/ipv6/tcp_ipv6.c
99455+++ b/net/ipv6/tcp_ipv6.c
99456@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
99457 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
99458 }
99459
99460+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99461+extern int grsec_enable_blackhole;
99462+#endif
99463+
99464 static void tcp_v6_hash(struct sock *sk)
99465 {
99466 if (sk->sk_state != TCP_CLOSE) {
99467@@ -1397,6 +1401,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
99468 return 0;
99469
99470 reset:
99471+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99472+ if (!grsec_enable_blackhole)
99473+#endif
99474 tcp_v6_send_reset(sk, skb);
99475 discard:
99476 if (opt_skb)
99477@@ -1479,12 +1486,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
99478 TCP_SKB_CB(skb)->sacked = 0;
99479
99480 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
99481- if (!sk)
99482+ if (!sk) {
99483+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99484+ ret = 1;
99485+#endif
99486 goto no_tcp_socket;
99487+ }
99488
99489 process:
99490- if (sk->sk_state == TCP_TIME_WAIT)
99491+ if (sk->sk_state == TCP_TIME_WAIT) {
99492+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99493+ ret = 2;
99494+#endif
99495 goto do_time_wait;
99496+ }
99497
99498 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
99499 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
99500@@ -1536,6 +1551,10 @@ csum_error:
99501 bad_packet:
99502 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
99503 } else {
99504+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99505+ if (!grsec_enable_blackhole || (ret == 1 &&
99506+ (skb->dev->flags & IFF_LOOPBACK)))
99507+#endif
99508 tcp_v6_send_reset(NULL, skb);
99509 }
99510
99511diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
99512index 089c741..cfee117 100644
99513--- a/net/ipv6/udp.c
99514+++ b/net/ipv6/udp.c
99515@@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
99516 udp_ipv6_hash_secret + net_hash_mix(net));
99517 }
99518
99519+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99520+extern int grsec_enable_blackhole;
99521+#endif
99522+
99523 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
99524 {
99525 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
99526@@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99527 int is_udp4;
99528 bool slow;
99529
99530+ if (addr_len)
99531+ *addr_len = sizeof(struct sockaddr_in6);
99532+
99533 if (flags & MSG_ERRQUEUE)
99534 return ipv6_recv_error(sk, msg, len, addr_len);
99535
99536@@ -435,7 +442,7 @@ try_again:
99537 if (unlikely(err)) {
99538 trace_kfree_skb(skb, udpv6_recvmsg);
99539 if (!peeked) {
99540- atomic_inc(&sk->sk_drops);
99541+ atomic_inc_unchecked(&sk->sk_drops);
99542 if (is_udp4)
99543 UDP_INC_STATS_USER(sock_net(sk),
99544 UDP_MIB_INERRORS,
99545@@ -477,7 +484,7 @@ try_again:
99546 ipv6_iface_scope_id(&sin6->sin6_addr,
99547 IP6CB(skb)->iif);
99548 }
99549- *addr_len = sizeof(*sin6);
99550+
99551 }
99552 if (is_udp4) {
99553 if (inet->cmsg_flags)
99554@@ -685,7 +692,7 @@ csum_error:
99555 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
99556 drop:
99557 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
99558- atomic_inc(&sk->sk_drops);
99559+ atomic_inc_unchecked(&sk->sk_drops);
99560 kfree_skb(skb);
99561 return -1;
99562 }
99563@@ -742,7 +749,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
99564 if (likely(skb1 == NULL))
99565 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
99566 if (!skb1) {
99567- atomic_inc(&sk->sk_drops);
99568+ atomic_inc_unchecked(&sk->sk_drops);
99569 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
99570 IS_UDPLITE(sk));
99571 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
99572@@ -881,6 +888,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
99573 goto csum_error;
99574
99575 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
99576+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99577+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
99578+#endif
99579 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
99580
99581 kfree_skb(skb);
99582diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
99583index 5f8e128..865d38e 100644
99584--- a/net/ipv6/xfrm6_policy.c
99585+++ b/net/ipv6/xfrm6_policy.c
99586@@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
99587 }
99588 }
99589
99590-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
99591+static int xfrm6_garbage_collect(struct dst_ops *ops)
99592 {
99593 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
99594
99595- xfrm6_policy_afinfo.garbage_collect(net);
99596+ xfrm_garbage_collect_deferred(net);
99597 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
99598 }
99599
99600@@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
99601
99602 static int __net_init xfrm6_net_init(struct net *net)
99603 {
99604- struct ctl_table *table;
99605+ ctl_table_no_const *table = NULL;
99606 struct ctl_table_header *hdr;
99607
99608- table = xfrm6_policy_table;
99609 if (!net_eq(net, &init_net)) {
99610- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
99611+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
99612 if (!table)
99613 goto err_alloc;
99614
99615 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
99616- }
99617+ hdr = register_net_sysctl(net, "net/ipv6", table);
99618+ } else
99619+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
99620
99621- hdr = register_net_sysctl(net, "net/ipv6", table);
99622 if (!hdr)
99623 goto err_reg;
99624
99625@@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
99626 return 0;
99627
99628 err_reg:
99629- if (!net_eq(net, &init_net))
99630- kfree(table);
99631+ kfree(table);
99632 err_alloc:
99633 return -ENOMEM;
99634 }
99635diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
99636index 41ac7938..75e3bb1 100644
99637--- a/net/irda/ircomm/ircomm_tty.c
99638+++ b/net/irda/ircomm/ircomm_tty.c
99639@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99640 add_wait_queue(&port->open_wait, &wait);
99641
99642 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
99643- __FILE__, __LINE__, tty->driver->name, port->count);
99644+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99645
99646 spin_lock_irqsave(&port->lock, flags);
99647 if (!tty_hung_up_p(filp))
99648- port->count--;
99649+ atomic_dec(&port->count);
99650 port->blocked_open++;
99651 spin_unlock_irqrestore(&port->lock, flags);
99652
99653@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99654 }
99655
99656 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
99657- __FILE__, __LINE__, tty->driver->name, port->count);
99658+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99659
99660 schedule();
99661 }
99662@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99663
99664 spin_lock_irqsave(&port->lock, flags);
99665 if (!tty_hung_up_p(filp))
99666- port->count++;
99667+ atomic_inc(&port->count);
99668 port->blocked_open--;
99669 spin_unlock_irqrestore(&port->lock, flags);
99670
99671 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
99672- __FILE__, __LINE__, tty->driver->name, port->count);
99673+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99674
99675 if (!retval)
99676 port->flags |= ASYNC_NORMAL_ACTIVE;
99677@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
99678
99679 /* ++ is not atomic, so this should be protected - Jean II */
99680 spin_lock_irqsave(&self->port.lock, flags);
99681- self->port.count++;
99682+ atomic_inc(&self->port.count);
99683 spin_unlock_irqrestore(&self->port.lock, flags);
99684 tty_port_tty_set(&self->port, tty);
99685
99686 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
99687- self->line, self->port.count);
99688+ self->line, atomic_read(&self->port.count));
99689
99690 /* Not really used by us, but lets do it anyway */
99691 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
99692@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
99693 tty_kref_put(port->tty);
99694 }
99695 port->tty = NULL;
99696- port->count = 0;
99697+ atomic_set(&port->count, 0);
99698 spin_unlock_irqrestore(&port->lock, flags);
99699
99700 wake_up_interruptible(&port->open_wait);
99701@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
99702 seq_putc(m, '\n');
99703
99704 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
99705- seq_printf(m, "Open count: %d\n", self->port.count);
99706+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
99707 seq_printf(m, "Max data size: %d\n", self->max_data_size);
99708 seq_printf(m, "Max header size: %d\n", self->max_header_size);
99709
99710diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
99711index c4b7218..3e83259 100644
99712--- a/net/iucv/af_iucv.c
99713+++ b/net/iucv/af_iucv.c
99714@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
99715
99716 write_lock_bh(&iucv_sk_list.lock);
99717
99718- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
99719+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
99720 while (__iucv_get_sock_by_name(name)) {
99721 sprintf(name, "%08x",
99722- atomic_inc_return(&iucv_sk_list.autobind_name));
99723+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
99724 }
99725
99726 write_unlock_bh(&iucv_sk_list.lock);
99727diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
99728index cd5b8ec..f205e6b 100644
99729--- a/net/iucv/iucv.c
99730+++ b/net/iucv/iucv.c
99731@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
99732 return NOTIFY_OK;
99733 }
99734
99735-static struct notifier_block __refdata iucv_cpu_notifier = {
99736+static struct notifier_block iucv_cpu_notifier = {
99737 .notifier_call = iucv_cpu_notify,
99738 };
99739
99740diff --git a/net/key/af_key.c b/net/key/af_key.c
99741index 545f047..9757a9d 100644
99742--- a/net/key/af_key.c
99743+++ b/net/key/af_key.c
99744@@ -3041,10 +3041,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
99745 static u32 get_acqseq(void)
99746 {
99747 u32 res;
99748- static atomic_t acqseq;
99749+ static atomic_unchecked_t acqseq;
99750
99751 do {
99752- res = atomic_inc_return(&acqseq);
99753+ res = atomic_inc_return_unchecked(&acqseq);
99754 } while (!res);
99755 return res;
99756 }
99757diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
99758index da1a1ce..571db8d 100644
99759--- a/net/l2tp/l2tp_ip.c
99760+++ b/net/l2tp/l2tp_ip.c
99761@@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
99762 if (flags & MSG_OOB)
99763 goto out;
99764
99765+ if (addr_len)
99766+ *addr_len = sizeof(*sin);
99767+
99768 skb = skb_recv_datagram(sk, flags, noblock, &err);
99769 if (!skb)
99770 goto out;
99771@@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
99772 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99773 sin->sin_port = 0;
99774 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
99775- *addr_len = sizeof(*sin);
99776 }
99777 if (inet->cmsg_flags)
99778 ip_cmsg_recv(msg, skb);
99779diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
99780index b4b61b2..ac84a257 100644
99781--- a/net/mac80211/cfg.c
99782+++ b/net/mac80211/cfg.c
99783@@ -826,7 +826,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
99784 ret = ieee80211_vif_use_channel(sdata, chandef,
99785 IEEE80211_CHANCTX_EXCLUSIVE);
99786 }
99787- } else if (local->open_count == local->monitors) {
99788+ } else if (local_read(&local->open_count) == local->monitors) {
99789 local->_oper_chandef = *chandef;
99790 ieee80211_hw_config(local, 0);
99791 }
99792@@ -3311,7 +3311,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
99793 else
99794 local->probe_req_reg--;
99795
99796- if (!local->open_count)
99797+ if (!local_read(&local->open_count))
99798 break;
99799
99800 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
99801@@ -3774,8 +3774,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
99802 if (chanctx_conf) {
99803 *chandef = chanctx_conf->def;
99804 ret = 0;
99805- } else if (local->open_count > 0 &&
99806- local->open_count == local->monitors &&
99807+ } else if (local_read(&local->open_count) > 0 &&
99808+ local_read(&local->open_count) == local->monitors &&
99809 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
99810 if (local->use_chanctx)
99811 *chandef = local->monitor_chandef;
99812diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
99813index 4aea4e7..9e698d1 100644
99814--- a/net/mac80211/ieee80211_i.h
99815+++ b/net/mac80211/ieee80211_i.h
99816@@ -28,6 +28,7 @@
99817 #include <net/ieee80211_radiotap.h>
99818 #include <net/cfg80211.h>
99819 #include <net/mac80211.h>
99820+#include <asm/local.h>
99821 #include "key.h"
99822 #include "sta_info.h"
99823 #include "debug.h"
99824@@ -961,7 +962,7 @@ struct ieee80211_local {
99825 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
99826 spinlock_t queue_stop_reason_lock;
99827
99828- int open_count;
99829+ local_t open_count;
99830 int monitors, cooked_mntrs;
99831 /* number of interfaces with corresponding FIF_ flags */
99832 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
99833diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
99834index a075791..1d0027f 100644
99835--- a/net/mac80211/iface.c
99836+++ b/net/mac80211/iface.c
99837@@ -519,7 +519,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99838 break;
99839 }
99840
99841- if (local->open_count == 0) {
99842+ if (local_read(&local->open_count) == 0) {
99843 res = drv_start(local);
99844 if (res)
99845 goto err_del_bss;
99846@@ -566,7 +566,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99847 res = drv_add_interface(local, sdata);
99848 if (res)
99849 goto err_stop;
99850- } else if (local->monitors == 0 && local->open_count == 0) {
99851+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
99852 res = ieee80211_add_virtual_monitor(local);
99853 if (res)
99854 goto err_stop;
99855@@ -675,7 +675,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99856 atomic_inc(&local->iff_promiscs);
99857
99858 if (coming_up)
99859- local->open_count++;
99860+ local_inc(&local->open_count);
99861
99862 if (hw_reconf_flags)
99863 ieee80211_hw_config(local, hw_reconf_flags);
99864@@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99865 err_del_interface:
99866 drv_remove_interface(local, sdata);
99867 err_stop:
99868- if (!local->open_count)
99869+ if (!local_read(&local->open_count))
99870 drv_stop(local);
99871 err_del_bss:
99872 sdata->bss = NULL;
99873@@ -856,7 +856,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99874 }
99875
99876 if (going_down)
99877- local->open_count--;
99878+ local_dec(&local->open_count);
99879
99880 switch (sdata->vif.type) {
99881 case NL80211_IFTYPE_AP_VLAN:
99882@@ -923,7 +923,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99883 }
99884 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
99885
99886- if (local->open_count == 0)
99887+ if (local_read(&local->open_count) == 0)
99888 ieee80211_clear_tx_pending(local);
99889
99890 /*
99891@@ -963,7 +963,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99892
99893 ieee80211_recalc_ps(local, -1);
99894
99895- if (local->open_count == 0) {
99896+ if (local_read(&local->open_count) == 0) {
99897 ieee80211_stop_device(local);
99898
99899 /* no reconfiguring after stop! */
99900@@ -974,7 +974,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99901 ieee80211_configure_filter(local);
99902 ieee80211_hw_config(local, hw_reconf_flags);
99903
99904- if (local->monitors == local->open_count)
99905+ if (local->monitors == local_read(&local->open_count))
99906 ieee80211_add_virtual_monitor(local);
99907 }
99908
99909diff --git a/net/mac80211/main.c b/net/mac80211/main.c
99910index 7d1c3ac..b62dd29 100644
99911--- a/net/mac80211/main.c
99912+++ b/net/mac80211/main.c
99913@@ -172,7 +172,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
99914 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
99915 IEEE80211_CONF_CHANGE_POWER);
99916
99917- if (changed && local->open_count) {
99918+ if (changed && local_read(&local->open_count)) {
99919 ret = drv_config(local, changed);
99920 /*
99921 * Goal:
99922diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
99923index 3401262..d5cd68d 100644
99924--- a/net/mac80211/pm.c
99925+++ b/net/mac80211/pm.c
99926@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
99927 struct ieee80211_sub_if_data *sdata;
99928 struct sta_info *sta;
99929
99930- if (!local->open_count)
99931+ if (!local_read(&local->open_count))
99932 goto suspend;
99933
99934 ieee80211_scan_cancel(local);
99935@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
99936 cancel_work_sync(&local->dynamic_ps_enable_work);
99937 del_timer_sync(&local->dynamic_ps_timer);
99938
99939- local->wowlan = wowlan && local->open_count;
99940+ local->wowlan = wowlan && local_read(&local->open_count);
99941 if (local->wowlan) {
99942 int err = drv_suspend(local, wowlan);
99943 if (err < 0) {
99944@@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
99945 WARN_ON(!list_empty(&local->chanctx_list));
99946
99947 /* stop hardware - this must stop RX */
99948- if (local->open_count)
99949+ if (local_read(&local->open_count))
99950 ieee80211_stop_device(local);
99951
99952 suspend:
99953diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
99954index 22b223f..ab70070 100644
99955--- a/net/mac80211/rate.c
99956+++ b/net/mac80211/rate.c
99957@@ -734,7 +734,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
99958
99959 ASSERT_RTNL();
99960
99961- if (local->open_count)
99962+ if (local_read(&local->open_count))
99963 return -EBUSY;
99964
99965 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
99966diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
99967index 6ff1346..936ca9a 100644
99968--- a/net/mac80211/rc80211_pid_debugfs.c
99969+++ b/net/mac80211/rc80211_pid_debugfs.c
99970@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
99971
99972 spin_unlock_irqrestore(&events->lock, status);
99973
99974- if (copy_to_user(buf, pb, p))
99975+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
99976 return -EFAULT;
99977
99978 return p;
99979diff --git a/net/mac80211/util.c b/net/mac80211/util.c
99980index 9f9b9bd..d6fcf59 100644
99981--- a/net/mac80211/util.c
99982+++ b/net/mac80211/util.c
99983@@ -1474,7 +1474,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
99984 }
99985 #endif
99986 /* everything else happens only if HW was up & running */
99987- if (!local->open_count)
99988+ if (!local_read(&local->open_count))
99989 goto wake_up;
99990
99991 /*
99992@@ -1699,7 +1699,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
99993 local->in_reconfig = false;
99994 barrier();
99995
99996- if (local->monitors == local->open_count && local->monitors > 0)
99997+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
99998 ieee80211_add_virtual_monitor(local);
99999
100000 /*
100001diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
100002index c3398cd..98ad3b4 100644
100003--- a/net/netfilter/Kconfig
100004+++ b/net/netfilter/Kconfig
100005@@ -1002,6 +1002,16 @@ config NETFILTER_XT_MATCH_ESP
100006
100007 To compile it as a module, choose M here. If unsure, say N.
100008
100009+config NETFILTER_XT_MATCH_GRADM
100010+ tristate '"gradm" match support'
100011+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
100012+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
100013+ ---help---
100014+ The gradm match allows to match on grsecurity RBAC being enabled.
100015+ It is useful when iptables rules are applied early on bootup to
100016+ prevent connections to the machine (except from a trusted host)
100017+ while the RBAC system is disabled.
100018+
100019 config NETFILTER_XT_MATCH_HASHLIMIT
100020 tristate '"hashlimit" match support'
100021 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
100022diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
100023index 394483b..ed51f2d 100644
100024--- a/net/netfilter/Makefile
100025+++ b/net/netfilter/Makefile
100026@@ -130,6 +130,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
100027 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
100028 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
100029 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
100030+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
100031 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
100032 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
100033 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
100034diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
100035index bac7e01..1d7a31a 100644
100036--- a/net/netfilter/ipset/ip_set_core.c
100037+++ b/net/netfilter/ipset/ip_set_core.c
100038@@ -1950,7 +1950,7 @@ done:
100039 return ret;
100040 }
100041
100042-static struct nf_sockopt_ops so_set __read_mostly = {
100043+static struct nf_sockopt_ops so_set = {
100044 .pf = PF_INET,
100045 .get_optmin = SO_IP_SET,
100046 .get_optmax = SO_IP_SET + 1,
100047diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
100048index 4c8e5c0..5a79b4d 100644
100049--- a/net/netfilter/ipvs/ip_vs_conn.c
100050+++ b/net/netfilter/ipvs/ip_vs_conn.c
100051@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
100052 /* Increase the refcnt counter of the dest */
100053 ip_vs_dest_hold(dest);
100054
100055- conn_flags = atomic_read(&dest->conn_flags);
100056+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
100057 if (cp->protocol != IPPROTO_UDP)
100058 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
100059 flags = cp->flags;
100060@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
100061
100062 cp->control = NULL;
100063 atomic_set(&cp->n_control, 0);
100064- atomic_set(&cp->in_pkts, 0);
100065+ atomic_set_unchecked(&cp->in_pkts, 0);
100066
100067 cp->packet_xmit = NULL;
100068 cp->app = NULL;
100069@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
100070
100071 /* Don't drop the entry if its number of incoming packets is not
100072 located in [0, 8] */
100073- i = atomic_read(&cp->in_pkts);
100074+ i = atomic_read_unchecked(&cp->in_pkts);
100075 if (i > 8 || i < 0) return 0;
100076
100077 if (!todrop_rate[i]) return 0;
100078diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
100079index 4f26ee4..6a9d7c3 100644
100080--- a/net/netfilter/ipvs/ip_vs_core.c
100081+++ b/net/netfilter/ipvs/ip_vs_core.c
100082@@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
100083 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
100084 /* do not touch skb anymore */
100085
100086- atomic_inc(&cp->in_pkts);
100087+ atomic_inc_unchecked(&cp->in_pkts);
100088 ip_vs_conn_put(cp);
100089 return ret;
100090 }
100091@@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
100092 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
100093 pkts = sysctl_sync_threshold(ipvs);
100094 else
100095- pkts = atomic_add_return(1, &cp->in_pkts);
100096+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100097
100098 if (ipvs->sync_state & IP_VS_STATE_MASTER)
100099 ip_vs_sync_conn(net, cp, pkts);
100100diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
100101index 35be035..50f8834 100644
100102--- a/net/netfilter/ipvs/ip_vs_ctl.c
100103+++ b/net/netfilter/ipvs/ip_vs_ctl.c
100104@@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
100105 */
100106 ip_vs_rs_hash(ipvs, dest);
100107 }
100108- atomic_set(&dest->conn_flags, conn_flags);
100109+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
100110
100111 /* bind the service */
100112 old_svc = rcu_dereference_protected(dest->svc, 1);
100113@@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
100114 * align with netns init in ip_vs_control_net_init()
100115 */
100116
100117-static struct ctl_table vs_vars[] = {
100118+static ctl_table_no_const vs_vars[] __read_only = {
100119 {
100120 .procname = "amemthresh",
100121 .maxlen = sizeof(int),
100122@@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
100123 " %-7s %-6d %-10d %-10d\n",
100124 &dest->addr.in6,
100125 ntohs(dest->port),
100126- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
100127+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
100128 atomic_read(&dest->weight),
100129 atomic_read(&dest->activeconns),
100130 atomic_read(&dest->inactconns));
100131@@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
100132 "%-7s %-6d %-10d %-10d\n",
100133 ntohl(dest->addr.ip),
100134 ntohs(dest->port),
100135- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
100136+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
100137 atomic_read(&dest->weight),
100138 atomic_read(&dest->activeconns),
100139 atomic_read(&dest->inactconns));
100140@@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
100141
100142 entry.addr = dest->addr.ip;
100143 entry.port = dest->port;
100144- entry.conn_flags = atomic_read(&dest->conn_flags);
100145+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
100146 entry.weight = atomic_read(&dest->weight);
100147 entry.u_threshold = dest->u_threshold;
100148 entry.l_threshold = dest->l_threshold;
100149@@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
100150 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
100151 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
100152 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
100153- (atomic_read(&dest->conn_flags) &
100154+ (atomic_read_unchecked(&dest->conn_flags) &
100155 IP_VS_CONN_F_FWD_MASK)) ||
100156 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
100157 atomic_read(&dest->weight)) ||
100158@@ -3580,7 +3580,7 @@ out:
100159 }
100160
100161
100162-static const struct genl_ops ip_vs_genl_ops[] __read_mostly = {
100163+static const struct genl_ops ip_vs_genl_ops[] = {
100164 {
100165 .cmd = IPVS_CMD_NEW_SERVICE,
100166 .flags = GENL_ADMIN_PERM,
100167@@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
100168 {
100169 int idx;
100170 struct netns_ipvs *ipvs = net_ipvs(net);
100171- struct ctl_table *tbl;
100172+ ctl_table_no_const *tbl;
100173
100174 atomic_set(&ipvs->dropentry, 0);
100175 spin_lock_init(&ipvs->dropentry_lock);
100176diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
100177index ca056a3..9cf01ef 100644
100178--- a/net/netfilter/ipvs/ip_vs_lblc.c
100179+++ b/net/netfilter/ipvs/ip_vs_lblc.c
100180@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
100181 * IPVS LBLC sysctl table
100182 */
100183 #ifdef CONFIG_SYSCTL
100184-static struct ctl_table vs_vars_table[] = {
100185+static ctl_table_no_const vs_vars_table[] __read_only = {
100186 {
100187 .procname = "lblc_expiration",
100188 .data = NULL,
100189diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
100190index 3f21a2f..a112e85 100644
100191--- a/net/netfilter/ipvs/ip_vs_lblcr.c
100192+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
100193@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
100194 * IPVS LBLCR sysctl table
100195 */
100196
100197-static struct ctl_table vs_vars_table[] = {
100198+static ctl_table_no_const vs_vars_table[] __read_only = {
100199 {
100200 .procname = "lblcr_expiration",
100201 .data = NULL,
100202diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
100203index f63c238..1b87f8a 100644
100204--- a/net/netfilter/ipvs/ip_vs_sync.c
100205+++ b/net/netfilter/ipvs/ip_vs_sync.c
100206@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
100207 cp = cp->control;
100208 if (cp) {
100209 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
100210- pkts = atomic_add_return(1, &cp->in_pkts);
100211+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100212 else
100213 pkts = sysctl_sync_threshold(ipvs);
100214 ip_vs_sync_conn(net, cp->control, pkts);
100215@@ -771,7 +771,7 @@ control:
100216 if (!cp)
100217 return;
100218 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
100219- pkts = atomic_add_return(1, &cp->in_pkts);
100220+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100221 else
100222 pkts = sysctl_sync_threshold(ipvs);
100223 goto sloop;
100224@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
100225
100226 if (opt)
100227 memcpy(&cp->in_seq, opt, sizeof(*opt));
100228- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
100229+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
100230 cp->state = state;
100231 cp->old_state = cp->state;
100232 /*
100233diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
100234index c47444e..b0961c6 100644
100235--- a/net/netfilter/ipvs/ip_vs_xmit.c
100236+++ b/net/netfilter/ipvs/ip_vs_xmit.c
100237@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
100238 else
100239 rc = NF_ACCEPT;
100240 /* do not touch skb anymore */
100241- atomic_inc(&cp->in_pkts);
100242+ atomic_inc_unchecked(&cp->in_pkts);
100243 goto out;
100244 }
100245
100246@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
100247 else
100248 rc = NF_ACCEPT;
100249 /* do not touch skb anymore */
100250- atomic_inc(&cp->in_pkts);
100251+ atomic_inc_unchecked(&cp->in_pkts);
100252 goto out;
100253 }
100254
100255diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
100256index a4b5e2a..13b1de3 100644
100257--- a/net/netfilter/nf_conntrack_acct.c
100258+++ b/net/netfilter/nf_conntrack_acct.c
100259@@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
100260 #ifdef CONFIG_SYSCTL
100261 static int nf_conntrack_acct_init_sysctl(struct net *net)
100262 {
100263- struct ctl_table *table;
100264+ ctl_table_no_const *table;
100265
100266 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
100267 GFP_KERNEL);
100268diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
100269index 43549eb..0bbeace 100644
100270--- a/net/netfilter/nf_conntrack_core.c
100271+++ b/net/netfilter/nf_conntrack_core.c
100272@@ -1605,6 +1605,10 @@ void nf_conntrack_init_end(void)
100273 #define DYING_NULLS_VAL ((1<<30)+1)
100274 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
100275
100276+#ifdef CONFIG_GRKERNSEC_HIDESYM
100277+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
100278+#endif
100279+
100280 int nf_conntrack_init_net(struct net *net)
100281 {
100282 int ret;
100283@@ -1619,7 +1623,11 @@ int nf_conntrack_init_net(struct net *net)
100284 goto err_stat;
100285 }
100286
100287+#ifdef CONFIG_GRKERNSEC_HIDESYM
100288+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
100289+#else
100290 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
100291+#endif
100292 if (!net->ct.slabname) {
100293 ret = -ENOMEM;
100294 goto err_slabname;
100295diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
100296index 1df1761..ce8b88a 100644
100297--- a/net/netfilter/nf_conntrack_ecache.c
100298+++ b/net/netfilter/nf_conntrack_ecache.c
100299@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
100300 #ifdef CONFIG_SYSCTL
100301 static int nf_conntrack_event_init_sysctl(struct net *net)
100302 {
100303- struct ctl_table *table;
100304+ ctl_table_no_const *table;
100305
100306 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
100307 GFP_KERNEL);
100308diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
100309index 974a2a4..52cc6ff 100644
100310--- a/net/netfilter/nf_conntrack_helper.c
100311+++ b/net/netfilter/nf_conntrack_helper.c
100312@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
100313
100314 static int nf_conntrack_helper_init_sysctl(struct net *net)
100315 {
100316- struct ctl_table *table;
100317+ ctl_table_no_const *table;
100318
100319 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
100320 GFP_KERNEL);
100321diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
100322index ce30041..3861b5d 100644
100323--- a/net/netfilter/nf_conntrack_proto.c
100324+++ b/net/netfilter/nf_conntrack_proto.c
100325@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
100326
100327 static void
100328 nf_ct_unregister_sysctl(struct ctl_table_header **header,
100329- struct ctl_table **table,
100330+ ctl_table_no_const **table,
100331 unsigned int users)
100332 {
100333 if (users > 0)
100334diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
100335index 59359be..cb372f9 100644
100336--- a/net/netfilter/nf_conntrack_proto_dccp.c
100337+++ b/net/netfilter/nf_conntrack_proto_dccp.c
100338@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
100339 out_invalid:
100340 if (LOG_INVALID(net, IPPROTO_DCCP))
100341 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
100342- NULL, msg);
100343+ NULL, "%s", msg);
100344 return false;
100345 }
100346
100347@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
100348
100349 out_invalid:
100350 if (LOG_INVALID(net, IPPROTO_DCCP))
100351- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
100352+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
100353 return -NF_ACCEPT;
100354 }
100355
100356diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
100357index f641751..d3c5b51 100644
100358--- a/net/netfilter/nf_conntrack_standalone.c
100359+++ b/net/netfilter/nf_conntrack_standalone.c
100360@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
100361
100362 static int nf_conntrack_standalone_init_sysctl(struct net *net)
100363 {
100364- struct ctl_table *table;
100365+ ctl_table_no_const *table;
100366
100367 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
100368 GFP_KERNEL);
100369diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
100370index 7a394df..bd91a8a 100644
100371--- a/net/netfilter/nf_conntrack_timestamp.c
100372+++ b/net/netfilter/nf_conntrack_timestamp.c
100373@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
100374 #ifdef CONFIG_SYSCTL
100375 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
100376 {
100377- struct ctl_table *table;
100378+ ctl_table_no_const *table;
100379
100380 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
100381 GFP_KERNEL);
100382diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
100383index 85296d4..8becdec 100644
100384--- a/net/netfilter/nf_log.c
100385+++ b/net/netfilter/nf_log.c
100386@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
100387
100388 #ifdef CONFIG_SYSCTL
100389 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
100390-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
100391+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
100392
100393 static int nf_log_proc_dostring(struct ctl_table *table, int write,
100394 void __user *buffer, size_t *lenp, loff_t *ppos)
100395@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
100396 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
100397 mutex_unlock(&nf_log_mutex);
100398 } else {
100399+ ctl_table_no_const nf_log_table = *table;
100400+
100401 mutex_lock(&nf_log_mutex);
100402 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
100403 lockdep_is_held(&nf_log_mutex));
100404 if (!logger)
100405- table->data = "NONE";
100406+ nf_log_table.data = "NONE";
100407 else
100408- table->data = logger->name;
100409- r = proc_dostring(table, write, buffer, lenp, ppos);
100410+ nf_log_table.data = logger->name;
100411+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
100412 mutex_unlock(&nf_log_mutex);
100413 }
100414
100415diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
100416index f042ae5..30ea486 100644
100417--- a/net/netfilter/nf_sockopt.c
100418+++ b/net/netfilter/nf_sockopt.c
100419@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
100420 }
100421 }
100422
100423- list_add(&reg->list, &nf_sockopts);
100424+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
100425 out:
100426 mutex_unlock(&nf_sockopt_mutex);
100427 return ret;
100428@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
100429 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
100430 {
100431 mutex_lock(&nf_sockopt_mutex);
100432- list_del(&reg->list);
100433+ pax_list_del((struct list_head *)&reg->list);
100434 mutex_unlock(&nf_sockopt_mutex);
100435 }
100436 EXPORT_SYMBOL(nf_unregister_sockopt);
100437diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
100438index a155d19..726b0f2 100644
100439--- a/net/netfilter/nfnetlink_log.c
100440+++ b/net/netfilter/nfnetlink_log.c
100441@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
100442 struct nfnl_log_net {
100443 spinlock_t instances_lock;
100444 struct hlist_head instance_table[INSTANCE_BUCKETS];
100445- atomic_t global_seq;
100446+ atomic_unchecked_t global_seq;
100447 };
100448
100449 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
100450@@ -564,7 +564,7 @@ __build_packet_message(struct nfnl_log_net *log,
100451 /* global sequence number */
100452 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
100453 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
100454- htonl(atomic_inc_return(&log->global_seq))))
100455+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
100456 goto nla_put_failure;
100457
100458 if (data_len) {
100459diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
100460index da0c1f4..f79737a 100644
100461--- a/net/netfilter/nft_compat.c
100462+++ b/net/netfilter/nft_compat.c
100463@@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
100464 /* We want to reuse existing compat_to_user */
100465 old_fs = get_fs();
100466 set_fs(KERNEL_DS);
100467- t->compat_to_user(out, in);
100468+ t->compat_to_user((void __force_user *)out, in);
100469 set_fs(old_fs);
100470 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
100471 kfree(out);
100472@@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
100473 /* We want to reuse existing compat_to_user */
100474 old_fs = get_fs();
100475 set_fs(KERNEL_DS);
100476- m->compat_to_user(out, in);
100477+ m->compat_to_user((void __force_user *)out, in);
100478 set_fs(old_fs);
100479 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
100480 kfree(out);
100481diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
100482new file mode 100644
100483index 0000000..c566332
100484--- /dev/null
100485+++ b/net/netfilter/xt_gradm.c
100486@@ -0,0 +1,51 @@
100487+/*
100488+ * gradm match for netfilter
100489